Skip to content

Commit

Permalink
Fix before(:all) operating as before(:each)
Browse files Browse the repository at this point in the history
Now, when we detect a before(:all), we distribute the entire group,
instead of distributing each example within the group
  • Loading branch information
sandro committed Feb 28, 2014
1 parent 8d868c3 commit 6828ef2
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions lib/specjour/loader.rb
Expand Up @@ -99,20 +99,33 @@ def rspec_examples
end
end

# recursively gather groups containing a before(:all) hook, and examples
def gather_groups(groups)
groups.map do |g|
before_all_hooks = g.send(:find_hook, :before, :all, nil, nil)
if before_all_hooks.any?
g
else
(g.filtered_examples || []) + gather_groups(g.children)
end
end.flatten
end

def filtered_examples
examples = ::RSpec.world.example_groups.map do |g|
g.descendant_filtered_examples
end.flatten
locations = examples.map do |e|
meta = e.metadata
groups = e.example_group.parent_groups + [e.example_group]
shared_group = groups.detect do |group|
group.metadata[:shared_group_name]
end
if shared_group
meta = shared_group.metadata[:example_group]
executables = gather_groups(::RSpec.world.example_groups)
locations = executables.map do |e|
if e.respond_to?(:examples)
e.metadata[:example_group][:location]
else
if e.example_group.metadata[:shared_group_name]
e.metadata[:example_group][:location]
else
e.metadata[:location]
end
end
meta[:location]
end
ensure
::RSpec.reset
Expand Down

1 comment on commit 6828ef2

@pedrocarrico
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 Nice! Keep up the good work!

Please sign in to comment.