Nested Before/Around Run In Weird Order
Created by: benmmurphy
Subject of the issue
If you have a describe block with an before(:each) and then nest a describe block with an around(:each) the around(:each) runs before the before(:each). I would have thought the around(:each) is just a nice way of writing before(:each) after(:each) and sharing some state between them. but because of the way around(:each) always runs before before(:each) even if it is nested lower it makes around(:each) much less useful.
there doesn't seem to be a test case for this behaviour in the documentation so I'm not sure if this was deliberate or not. though, i guess it would be hard to change this behaviour because probably a lot of people rely on it.
Your environment
- Ruby version: 2.4.0
- rspec-core version: 3.7
Steps to reproduce
describe "filter" do
before(:each) do
puts "before each outer"
end
describe "inner" do
around(:each) do |example|
puts "around each inner"
example.run
end
it "should" do
puts "example"
end
end
end
actual:
around each inner
before each outer
example
expected:
before each outer
around each inner
example
here is how it works if they are both before(:each) rather than using an around(:each) for the inner.
describe "filter" do
before(:each) do
puts "before each outer"
end
describe "inner" do
before(:each) do
puts "before each inner"
end
it "should" do
puts "example"
end
end
end
before each outer
before each inner
example