class ATMResultFormatter
Constants
- DEFAULT_RESULT_FORMATTER_OPTIONS
Public Instance Methods
close(_notification)
click to toggle source
# File lib/atm_result_formatter.rb, line 52 def close(_notification) @test_results.each do |key, _value| File.open("test_results/#{key}.json", 'w') do |config| config.puts(JSON.pretty_generate(@test_results[key])) end end end
dump_summary(notification)
click to toggle source
# File lib/atm_result_formatter.rb, line 26 def dump_summary(notification) notification.examples.each do |example| file_name = example.metadata[:file_path].match(/[^\/]*_spec/)[0] # "#{}.json" file_path = "#{file_name}_#{@time_stamp}" @test_results[file_path.to_sym] = { test_cases: [] } test_data = @client.TestRun.process_result(process_metadata(example)) @test_data << if ATMFormatter.config.test_run_id test_data.merge!(test_run_id: ATMFormatter.config.test_run_id, test_case_id: example.metadata[:test_id], file_path: file_path) else test_data.merge!(test_case_id: example.metadata[:test_id], file_path: file_path) end end @test_results.each do |key, _value| @test_data.each do |test_case_data| if key.to_s == test_case_data[:file_path] test_case_data.delete(:file_path) @test_results[key][:test_cases] << test_case_data end end end end
example_started(notification)
click to toggle source
# File lib/atm_result_formatter.rb, line 60 def example_started(notification) if notification.example.metadata[:environment] || ATMFormatter.config.environment configure_env(notification.example) end if @options[:run_only_found_tests] && !@test_cases.include?(test_id(notification.example)) notification.example.metadata[:skip] = "#{notification.example.metadata[:test_id]} was not found in the #{ATMFormatter.config.test_run_id} test run." end notification.example.metadata[:step_index] = 0 end
start(_notification)
click to toggle source
# File lib/atm_result_formatter.rb, line 8 def start(_notification) @options = DEFAULT_RESULT_FORMATTER_OPTIONS.merge(ATMFormatter.config.result_formatter_options) @client = ATM::Client.new(ATMFormatter.config.to_hash) if @options[:run_only_found_tests] test_run_data = @client.TestRun.find(ATMFormatter.config.test_run_id) if test_run_data.code != 200 puts ATM::TestRunError.new(test_run_data).message exit end @test_cases = @client.TestCase.retrive_based_on_username(test_run_data, ATMFormatter.config.username.downcase) end @time_stamp = "#{Time.now.to_i.to_s}-#{rand(10**10)}" @test_results = {} @test_data = [] Dir.mkdir('test_results') unless Dir.exist?('test_results') end
Private Instance Methods
comment(scenario)
click to toggle source
# File lib/atm_result_formatter.rb, line 113 def comment(scenario) comment = [] return if scenario[:kanoah_evidence].nil? && scenario[:execution_result].exception.inspect == 'nil' comment << scenario[:execution_result].exception.inspect comment << "#{scenario[:kanoah_evidence][:title]}<br />#{scenario[:kanoah_evidence][:path]}" unless scenario[:kanoah_evidence].nil? comment.join('<br />') end
configure_env(example)
click to toggle source
# File lib/atm_result_formatter.rb, line 74 def configure_env(example) if (!example.metadata[:environment].nil? && !example.metadata[:environment].strip.empty?) && (!ATMFormatter.config.environment.nil? && !ATMFormatter.config.environment.strip.empty?) warn("WARNING: Environment is set twice! ATMFormatter.config.environment: #{ATMFormatter.config.environment} Spec: #{example.metadata[:environment]} Will use environment provided by the spec.") elsif example.metadata[:environment].nil? || example.metadata[:environment].strip.empty? example.metadata[:environment] = ATMFormatter.config.environment end end
fetch_environment(example)
click to toggle source
# File lib/atm_result_formatter.rb, line 97 def fetch_environment(example) if example.metadata[:environment] && !example.metadata[:environment].strip.empty? example.metadata[:environment] elsif ATMFormatter.config.environment && !ATMFormatter.config.environment.strip.empty? ATMFormatter.config.environment end end
process_metadata(example)
click to toggle source
# File lib/atm_result_formatter.rb, line 86 def process_metadata(example) { test_case_id: test_id(example), status: status(example.metadata[:execution_result]), environment: fetch_environment(example), comment: comment(example.metadata), execution_time: run_time(example.metadata[:execution_result]), script_results: steps(example.metadata) }.delete_if { |_k, v| v.nil? } end
run_time(scenario)
click to toggle source
# File lib/atm_result_formatter.rb, line 123 def run_time(scenario) scenario.run_time.to_i * 1000 end
status(scenario)
click to toggle source
# File lib/atm_result_formatter.rb, line 109 def status(scenario) status_code(scenario.status) end
status_code(status)
click to toggle source
# File lib/atm_result_formatter.rb, line 134 def status_code(status) case status when :failed, :passed then status.to_s.gsub('ed', '').capitalize when :pending then 'Not Supported' end end
steps(scenario)
click to toggle source
# File lib/atm_result_formatter.rb, line 127 def steps(scenario) # TODO: Make this better return unless scenario[:steps] arr = [] scenario[:steps].each { |s| arr << s.reject { |k, _v| k == :step_name } } arr end
test_id(example)
click to toggle source
# File lib/atm_result_formatter.rb, line 105 def test_id(example) example.metadata[:test_id] end