From e79238d59f76ca1ef9eec872b2833f43b2d05333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20=C5=A0ar=C4=8Devi=C4=87?= Date: Thu, 27 Jul 2017 12:51:34 +0200 Subject: [PATCH] Shared examples for all rspec versions --- .../semaphore_rspec3_json_formatter.rb | 23 +++++++++++-------- spec/integration/rspec_spec.rb | 5 ++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/rspec_formatters/semaphore_rspec3_json_formatter.rb b/rspec_formatters/semaphore_rspec3_json_formatter.rb index 9f4d894..4a4f4f5 100644 --- a/rspec_formatters/semaphore_rspec3_json_formatter.rb +++ b/rspec_formatters/semaphore_rspec3_json_formatter.rb @@ -35,16 +35,21 @@ def format_example(example) end def file_path(example) - # In case of a shared_example - # example[:file_path] returns the path of the shared_example file + # For shared examples 'example.file_path' returns the path of the shared example file. + # This is not optinal for our use case because we can't estimate the duration of the + # original spec file. # - # We are interested in the duration of the file from which the shared_example was called instead. - # - # We can get this infor from `example.id`. - # - # It has the following format: `./spec/models/analysis_spec.rb[1:17:1:1:1]` - # We are droping the angle brackets at the end. + # To resolve this, we use `example.metadata[:example_group]` that contains the correct + # file path for both shared examples and regular tests + + find_example_group_root_path(example.metadata[:example_group]) + end - example.id.gsub(/\[.*\]$/, "") + def find_example_group_root_path(example_group) + if example_group.has_key?(:parent_example_group) + find_example_group_root_path(example_group[:parent_example_group]) + else + example_group[:file_path] + end end end diff --git a/spec/integration/rspec_spec.rb b/spec/integration/rspec_spec.rb index 2b3aedd..1182674 100644 --- a/spec/integration/rspec_spec.rb +++ b/spec/integration/rspec_spec.rb @@ -17,10 +17,11 @@ @test_repo.clone @test_repo.set_env_var("RSPEC_SPLIT_CONFIGURATION_PATH", @split_configuration_path) - # set RSpec version of the test project + # set RSpec version in the test project rspec_dependancy_pattern = 'spec.add_development_dependency "rspec".*$' rspec_dependancy_version = "spec.add_development_dependency \"rspec\", '#{@rspec_version}'" - system(%Q{sed -i 's/#{rspec_dependancy_pattern}/#{rspec_dependancy_version}/' #{@test_repo.project_path}/rspec_project.gemspec}) + gemspec_path = "#{@test_repo.project_path}/rspec_project.gemspec" + system(%{sed -i 's/#{rspec_dependancy_pattern}/#{rspec_dependancy_version}/' #{gemspec_path}}) File.write(@split_configuration_path, [ { :files => [] },