Skip to content

Instantly share code, notes, and snippets.

@carlosantoniodasilva
Created April 14, 2011 17:55
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 carlosantoniodasilva/920061 to your computer and use it in GitHub Desktop.
Save carlosantoniodasilva/920061 to your computer and use it in GitHub Desktop.
Example showing how RSpec before/after blocks work.
# Acceptance spec
require "acceptance_helper"
feature "Rspec before blocks" do
before(:suite) do
puts "I'll run just once, before suite"
end
before(:all) do
puts "I'll run 3 times, before all"
end
before(:each) do
puts "I'll run 4 times, before all"
end
after(:each) do
puts "I'll run 3 times, after each"
end
after(:all) do
puts "I'll run 3 times, after all"
end
after(:suite) do
puts "I'll run just once, after suite"
end
scenario "1"
scenario "2"
context "foo" do
scenario "3"
end
context 'bar' do
scenario "4"
end
end
# Output
=begin
I'll run just once, before suite
Rspec before blocks
I'll run 3 times, before all
I'll run 4 times, before each
I'll run 3 times, after each
1 (PENDING: Not Yet Implemented)
I'll run 4 times, before each
I'll run 3 times, after each
2 (PENDING: Not Yet Implemented)
I'll run 3 times, after all
foo
I'll run 3 times, before all
I'll run 4 times, before each
I'll run 3 times, after each
3 (PENDING: Not Yet Implemented)
I'll run 3 times, after all
bar
I'll run 3 times, before all
I'll run 4 times, before each
I'll run 3 times, after each
4 (PENDING: Not Yet Implemented)
I'll run 3 times, after all
Pending:
Rspec before blocks 1 (Not Yet Implemented)
./spec/acceptance/_foo_bar_spec.rb:36
Rspec before blocks 2 (Not Yet Implemented)
./spec/acceptance/_foo_bar_spec.rb:37
Rspec before blocks foo 3 (Not Yet Implemented)
./spec/acceptance/_foo_bar_spec.rb:40
Rspec before blocks bar 4 (Not Yet Implemented)
./spec/acceptance/_foo_bar_spec.rb:44
Finished in 0.298433 seconds
4 examples, 0 failures, 4 pending
I'll run just once, after suite
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment