Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: passing configuration hash in the constructor #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ config.after(:each) do |scenario|
end
```

**To use credentials from environment variables**
- configuration could be provided in the constructor
- values from the passed `config` hash will take precedence over configuration in `testrail_config.yml`
```
testrail_config = {
url: ENV['TESTRAIL_URL']
user: ENV['TESTRAIL_USER']
password: ENV['TESTRAIL_PASSWORD']
run_id: ENV['TESTRAIL_RUN_ID']
}

config.after(:each) do |scenario|
TestrailRSpec::UpdateTestRails.new(scenario, config: testrail_config).upload_result
end
```

**Is there any demo available for this gem?**

Yes, you can use this `capybara` demo as an example, https://github.com/prashanth-sams/testrail-rspec
Expand Down
12 changes: 9 additions & 3 deletions lib/testrail-rspec/update-testrails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ module TestrailRSpec
class UpdateTestRails
attr_accessor :client

def initialize(scenario)
def initialize(scenario, config: {})
@scenario = scenario

if File.exist? './testrail_config.yml'
@config = YAML.load_file("./testrail_config.yml")['testrail']
raise 'TestRail configuration file not loaded successfully' if @config.nil?
else
raise 'TestRail configuration file is required'
end

if !config.nil? && !config.empty?
@config = (@config || {}).merge(config.map { |k, v| [k.to_s, v] }.to_h)
end

if @config.nil? || @config.empty?
raise 'TestRail configuration file or hash is required'
end

setup_testrail_client
Expand Down