Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Testing behavior of before vs. before :each vs before :all

View before_spec.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
require 'spec_helper'
 
$count = 0
$count_each = 0
$count_all = 0
 
shared_examples_for "before :each" do
it { should == 1 }
it { should == 2 }
end
 
describe "before" do
before do
$count += 1
end
 
subject { $count }
it_should_behave_like "before :each"
end
 
describe "before :each" do
before :each do
$count_each += 1
end
 
subject { $count_each }
it_should_behave_like "before :each"
end
 
describe "before :all" do
before :all do
$count_all += 1
end
 
subject { $count_all }
it { should == 1 }
it { should == 1 }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.