Skip to content

Commit

Permalink
Shared examples for all rspec versions
Browse files Browse the repository at this point in the history
  • Loading branch information
shiroyasha committed Jul 27, 2017
1 parent 8c74b17 commit e79238d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
23 changes: 14 additions & 9 deletions rspec_formatters/semaphore_rspec3_json_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions spec/integration/rspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 => [] },
Expand Down

0 comments on commit e79238d

Please sign in to comment.