Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 58eaac6

Browse files
committed
Add test case for :each.
1 parent 32a6d29 commit 58eaac6

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

spec/rspec/core/hooks_filtering_spec.rb

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,36 @@ module RSpec::Core
8383
]
8484
end
8585

86-
it "applies only to examples with matching metadata" do
87-
sequence = []
88-
89-
group = RSpec.describe do
90-
example("") { sequence << :ex_1 }
91-
example("", :run_hooks) { sequence << :ex_2 }
92-
end
86+
{ ":example" => [:example], ":each" => [:each] }.each do |label, args|
87+
args << :run_hooks
88+
it "applies only to examples with matching metadata (for hooks declared with #{label})" do
89+
sequence = []
90+
91+
group = RSpec.describe do
92+
example("") { sequence << :ex_1 }
93+
example("", :run_hooks) { sequence << :ex_2 }
94+
end
9395

94-
RSpec.configure do |c|
95-
c.before(:example, :run_hooks) { sequence << :before_ex_2 }
96-
c.prepend_before(:example, :run_hooks) { sequence << :before_ex_1 }
96+
RSpec.configure do |c|
97+
c.before(*args) { sequence << :before_ex_2 }
98+
c.prepend_before(*args) { sequence << :before_ex_1 }
9799

98-
c.after(:example, :run_hooks) { sequence << :after_ex_1 }
99-
c.append_after(:example, :run_hooks) { sequence << :after_ex_2 }
100+
c.after(*args) { sequence << :after_ex_1 }
101+
c.append_after(*args) { sequence << :after_ex_2 }
100102

101-
c.around(:example, :run_hooks) do |ex|
102-
sequence << :around_before_ex
103-
ex.run
104-
sequence << :around_after_ex
103+
c.around(*args) do |ex|
104+
sequence << :around_before_ex
105+
ex.run
106+
sequence << :around_after_ex
107+
end
105108
end
106-
end
107109

108-
group.run
109-
expect(sequence).to eq [
110-
:ex_1,
111-
:around_before_ex, :before_ex_1, :before_ex_2, :ex_2, :after_ex_1, :after_ex_2, :around_after_ex,
112-
]
110+
group.run
111+
expect(sequence).to eq [
112+
:ex_1,
113+
:around_before_ex, :before_ex_1, :before_ex_2, :ex_2, :after_ex_1, :after_ex_2, :around_after_ex,
114+
]
115+
end
113116
end
114117

115118
it "does not apply `suite` hooks to groups (or print warnings about suite hooks applied to example groups)" do

0 commit comments

Comments
 (0)