Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/rspec/core/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,18 @@ def scope_and_options_from(scope=:each, options={})
options = scope
scope = :each
end
return scope, options
return normalized_scope_for(scope), options
end

def scope_aliases
@scope_aliases ||= {
:example => :each,
:group => :all,
}
end

def normalized_scope_for(scope)
scope_aliases[scope] || scope
end
end
end
Expand Down
44 changes: 44 additions & 0 deletions spec/rspec/core/example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,50 @@ module RSpec::Core
end

describe "#before, after, and around hooks" do
describe "scope aliasing" do
it "aliases the `:group` hook scope to `:all`" do
group = ExampleGroup.describe
order = []
group.before(:group) { order << 1 }
group.example("example") {}

group.hooks[:before][:all].run_all(group)
order.should == [1]
end

it "aliases the `:example` hook scope to `:each`" do
group = ExampleGroup.describe
order = []
group.before(:example) { order << 1 }
group.example("example") {}

group.hooks[:before][:each].run_all(group)
order.should == [1]
end

it "should work with `before`" do
group = ExampleGroup.describe
order = []
group.before(:group) { order << 1 }
group.before(:example) { order << 2 }
group.example("example") {}

group.run
order.should == [1, 2]
end

it "should work with `after`" do
group = ExampleGroup.describe
order = []
group.after(:example) { order << 1 }
group.after(:group) { order << 2 }

group.example("example") {}

group.run
order.should == [1, 2]
end
end

it "runs the before alls in order" do
group = ExampleGroup.describe
Expand Down