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 => [] },