diff --git a/lib/tmj_formatter/version.rb b/lib/tmj_formatter/version.rb index c417c27..9cb099a 100755 --- a/lib/tmj_formatter/version.rb +++ b/lib/tmj_formatter/version.rb @@ -1,3 +1,3 @@ module TMJFormatter - VERSION = '0.1.0' + VERSION = '0.1.2'.freeze end diff --git a/lib/tmj_result_formatter.rb b/lib/tmj_result_formatter.rb index b45e249..6acc438 100644 --- a/lib/tmj_result_formatter.rb +++ b/lib/tmj_result_formatter.rb @@ -7,22 +7,24 @@ class TMJResultFormatter < RSpec::Core::Formatters::BaseFormatter RSpec::Core::Formatters.register self, :start, :example_started, :example_passed, :example_failed - def initialize(output) - @output = output - end - def start(_notification) @options = DEFAULT_RESULT_FORMATTER_OPTIONS.merge(RSpec.configuration.tmj_result_formatter_options) if @options[:run_only_found_tests] - @client = TMJ::Client.new - test_run_data = @client.TestRun.find(TMJ.config.test_run_id) + begin + @client = TMJ::Client.new + test_run_data = @client.TestRun.find(TMJ.config.test_run_id) + raise TMJ::TestRunError, test_run_data unless test_run_data.code == 200 + rescue => e + puts e, e.message + exit + end @test_cases = @client.TestCase.retrive_based_on_username(test_run_data, TMJ.config.username.downcase) end end def example_started(notification) if @options[:run_only_found_tests] && !@test_cases.include?(test_id(notification.example)) - notification.example.metadata[:skip] = true + notification.example.metadata[:skip] = "#{notification.example.metadata[:test_id]} was not found in the #{TMJ.config.test_run_id} test run." end notification.example.metadata[:step_index] = 0 end @@ -55,24 +57,32 @@ def post_result(example) def with_steps(example) # TODO: Make this better { - test_case: test_id(example), - status: status(example.metadata[:execution_result]), - environment: example.metadata.fetch(:environment) { nil }, - comment: comment(example.metadata), - execution_time: run_time(example.metadata[:execution_result]), - script_results: steps(example.metadata) - } + test_case: 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 def without_steps(example) # TODO: Make this better { - test_case: test_id(example), - status: status(example.metadata[:execution_result]), - comment: comment(example.metadata), - execution_time: run_time(example.metadata[:execution_result]) + test_case: test_id(example), + status: status(example.metadata[:execution_result]), + comment: comment(example.metadata), + execution_time: run_time(example.metadata[:execution_result]) } end + def fetch_environment(example) + if example.metadata[:environment] && !example.metadata[:environment].empty? + example.metadata[:environment] + elsif TMJ.config.environment && !TMJ.config.environment.empty? + TMJ.config.environment + end + end + def test_id(example) example.metadata[:test_id] end @@ -101,10 +111,10 @@ def steps(scenario) # TODO: Make this better def status_code(status) case status - when :failed, :passed then - status.to_s.gsub('ed', '').capitalize - when :pending then - 'Blocked' + when :failed, :passed then + status.to_s.gsub('ed', '').capitalize + when :pending then + 'Blocked' end end end diff --git a/spec/tmj_create_test_formatter_spec.rb b/spec/tmj_create_test_formatter_spec.rb new file mode 100644 index 0000000..046d326 --- /dev/null +++ b/spec/tmj_create_test_formatter_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' + +RSpec.describe 'TMJCreateTestFormatter', skip: true do + it 'TODO' do |e| + end +end \ No newline at end of file diff --git a/spec/tmj_formatter_spec.rb b/spec/tmj_formatter_spec.rb new file mode 100644 index 0000000..2a2ea40 --- /dev/null +++ b/spec/tmj_formatter_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +RSpec.describe 'TMJFormatter' do + it 'check version' do |e| + expect(TMJFormatter::VERSION).not_to be nil + end +end \ No newline at end of file diff --git a/spec/tmj_output_formatter_spec.rb b/spec/tmj_output_formatter_spec.rb new file mode 100644 index 0000000..160b3ce --- /dev/null +++ b/spec/tmj_output_formatter_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' + +RSpec.describe 'TMJOutputFormatter', skip: true do + it 'TODO' do |e| + end +end \ No newline at end of file