Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Created March 5, 2022 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcameron/641efac5061bf59a95a5f91419f3fc2c to your computer and use it in GitHub Desktop.
Save adamcameron/641efac5061bf59a95a5f91419f3fc2c to your computer and use it in GitHub Desktop.
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