Ruby QA Helpers/Tools
===

## Install

Add to qa_helpers to your Gemfile

 - Use Ruby ~> 2.3.0

```bash
    gem "qa_helpers", git: "git@github.com:theorchard/ruby-qa-helpers.git"
```

or

```bash
    gem install specific_install
    gem specific_install -l git@github.com:theorchard/ruby-qa-helpers.git
```

## Usage

Make sure you have the following ENV vars in your ENV:
```bash
    export MYSQL_HOST=<the db host>
    export MYSQL_USER=<the db user>
    export MYSQL_PASSWORD=<the db pass>
    export MYSQL_DATABASE=<the db name>
```

If you'd like to use e2e_status command, export the following vars:

```bash
    export JENKINS_USER=<jenkins_username>
    export JENKINS_PASSWORD=<jenkins_password>
    export QA_HELPER_RUN_HEADLESS=false # in case if you'd like to see browser/debug
```

```ruby
    require 'qa_helpers'
    # Get grass by vendor_id
    QAHelpers::GrassTokenHelper.new.user_grass(vendor_id: 10303)
    # Get grass by vend_contact_id
    QAHelpers::GrassTokenHelper.new.user_grass(vend_contact_id: 7412)
```

Also DB client can be initialised by passing a hash with params, like this:

```ruby
    helper = QAHelpers::GrassTokenHelper.new
    db_params = { 
      username: 'name', 
      password: 'password', 
      host: 'dbhost', 
      database: 'dbname' 
    }
    helper.send(:db_client, db_params)
    # Then you can use helper (GrassTokenHelper) without providing those ENV vars
    helper.user_grass(vendor_id: 10303)
```

## CLI Usage

Make sure that you've installed the gem (see Install ^)

 - help

```bash

$ qa_helpers help
  Commands:
    qa_helpers e2e_status     # Collects E2E Cucumber test results form Jenkins legacy builds
    qa_helpers get_test_matrix  # Generates User Feature matrix based on cucumber_tests project
    qa_helpers grasshelper      # To get the grass token for specific vendor_id (-v) or vend_contact_id (-c), e.g. qa_helpers grasshelper -...
    qa_helpers help [COMMAND]   # Describe available commands or one specific command    
```

  - grasshelper
```bash
    $ qa_helpers help grasshelper
    Usage:
      qa_helpers grasshelper
    
    Options:
      -v, [--vendor-id=VENDOR_ID]              # The Vendor ID
      -c, [--vend-contact-id=VEND_CONTACT_ID]  # The Vendor Contact ID
    
    To get the grass token for specific vendor_id (-v) or vend_contact_id (-c),
        e.g. qa_helpers grasshelper -v 10303
    
    $ qa_helpers grasshelper -v 10303
    3d718eb3a047c3da3d0c380f3990ac03
    
    $ qa_helpers grasshelper -c 26122
    46d3e61cefac8dd8c0cce325581a9037
```

  - get_test_matrix
```bash
    $ qa_helpers help get_test_matrix
    Usage:
      qa_helpers get_test_matrix
    
    Options:
      -p, [--cucumber-path=CUCUMBER-PATH]  # The path to cucumber_tests project
      -f, [--format=FORMAT]                # The output format "stdout" or "xls"
    
    Generates User Feature matrix based on cucumber_tests project.
    
    $ qa_helpers get_test_matrix -p /path/to/cucumber_tests
      test_matrix.xlsx file was successfully created.
```

  - e2e_status
```bash
    $ qa_helpers help e2e_status
    Usage:
      qa_helpers e2e_status
    
    Options:
      -c, [--job-count=JOB-COUNT]  # The amount of latest jobs to parse.
    
    Collects E2E Cucumber test results form Jenkins legacy builds
    
    qa_helpers e2e_status --job-count 50

    Getting e2e status for last 50 builds
    [###############################################################################################] [50/50] [100.00%] [09:54] [00:00] [ 0.08/s]
    +------------------------------------+------+--------+--------+---------+
    | Feature                            | Runs | Passed | Failed | Passing |
    +------------------------------------+------+--------+--------+---------+
    | Copy Product                       | 77   | 30     | 47     | 38.96   |
    | Subtitle                           | 150  | 71     | 79     | 47.33   |
    ...
```


## Development

Make sure that you have all those ENV vars exported to your ENV (see Usage^).

```bash
    cd qa_helpers
    bundle
    rspec # to make sure all works fine
```
