Class: ATMResultFormatter

Inherits:
RSpec::Core::Formatters::BaseFormatter
  • Object
show all
Defined in:
lib/atm_result_formatter.rb

Constant Summary collapse

DEFAULT_RESULT_FORMATTER_OPTIONS =
{ run_only_found_tests: false, post_results: false }.freeze

Instance Method Summary collapse

Instance Method Details

#close(_notification) ⇒ Object



52
53
54
55
56
57
58
# 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) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/atm_result_formatter.rb', line 26

def dump_summary(notification)
  notification.examples.each do |example|
    file_name = example.[: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((example))
    @test_data << if ATMFormatter.config.test_run_id
                    test_data.merge!(test_run_id: ATMFormatter.config.test_run_id,
                                     test_case_id: example.[:test_id],
                                     file_path: file_path)
                  else
                    test_data.merge!(test_case_id: example.[: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) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/atm_result_formatter.rb', line 60

def example_started(notification)
  if notification.example.[:environment] || ATMFormatter.config.environment
    configure_env(notification.example)
  end

  if @options[:run_only_found_tests] && !@test_cases.include?(test_id(notification.example))
    notification.example.[:skip] = "#{notification.example.[:test_id]} was not found in the #{ATMFormatter.config.test_run_id} test run."
  end

  notification.example.[:step_index] = 0
end

#start(_notification) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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