Method: Shoulda::ClassMethods#before_should

Defined in:
lib/shoulda/context.rb

#before_should(name, &blk) ⇒ Object

Before statements

Before statements are should statements that run before the current context’s setup. These are especially useful when setting expectations.

Example:

class UserControllerTest < Test::Unit::TestCase
  context "the index action" do
    setup do
      @users = [Factory(:user)]
      User.stubs(:find).returns(@users)
    end

    context "on GET" do
      setup { get :index }

      should_respond_with :success

      # runs before "get :index"
      before_should "find all users" do
        User.expects(:find).with(:all).returns(@users)
      end
    end
  end
end


98
99
100
# File 'lib/shoulda/context.rb', line 98

def before_should(name, &blk)
  should(name, :before => blk) { assert true }
end