Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demonstrates the order in which lifecycle event handlers run in rspec
describe "Lifecycle function tests" do
test_array = []
before(:all) do
test_array.push "main block before :all handler"
end
before(:each) do # or just before with no param
test_array.push "main block before :each handler"
end
describe "first block" do
before(:all) do
test_array.push "first block before :all handler"
end
before(:each) do # or just before with no param
test_array.push "first block before :each handler"
end
it "is a test" do
test_array.push "first block a test"
expect(test_array).to eq [
"main block before :all handler",
"first block before :all handler",
"main block before :each handler",
"first block before :each handler",
"first block a test"
]
end
it "is another test" do
test_array.push "first block another test"
expect(test_array).to eq [
"main block before :all handler",
"first block before :all handler",
"main block before :each handler",
"first block before :each handler",
"first block a test",
"main block before :each handler",
"first block before :each handler",
"first block another test"
]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment