Pages

Friday, October 14, 2011

Sequence of calls in rspec
                
 Example:
        describe "creates a new brand entry" do

            puts "I am defined BEFORE the before hook"

            before(:each) do
                puts "I am a statement defined in the before(:each) hook..."
            end

            puts "I am defined AFTER the before hook"

            login_admin_user
            it "assigns a new brand as @brand" do
                get :new
                assigns(:brand).should be_a_new(Brand)
            end

Result:

I am defined BEFORE the before hook
I am defined AFTER the before hook
....I am a statement defined in the before(:each) hook...
..........

Finished in 1.61 seconds
14 examples, 0 failures


Statements defined in before hooks will be run right before any specs are ruined. This means that if you defined statements before the statements in the before hook, those statements will run first.