Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedor Barannik committed May 17, 2017
2 parents f47b21f + 7f4bd21 commit 16a3dde
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/tmj_formatter/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TMJFormatter
VERSION = '0.1.0'
VERSION = '0.1.2'.freeze
end
54 changes: 32 additions & 22 deletions lib/tmj_result_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions spec/tmj_create_test_formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'spec_helper'

RSpec.describe 'TMJCreateTestFormatter', skip: true do
it 'TODO' do |e|
end
end
7 changes: 7 additions & 0 deletions spec/tmj_formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions spec/tmj_output_formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'spec_helper'

RSpec.describe 'TMJOutputFormatter', skip: true do
it 'TODO' do |e|
end
end

0 comments on commit 16a3dde

Please sign in to comment.