diff --git a/README.md b/README.md index 5db7beb..e6f667b 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/testrail-rspec/update-testrails.rb b/lib/testrail-rspec/update-testrails.rb index ff0a256..2fb8a8e 100644 --- a/lib/testrail-rspec/update-testrails.rb +++ b/lib/testrail-rspec/update-testrails.rb @@ -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