Created
December 16, 2010 09:43
-
-
Save jmaicher/743238 to your computer and use it in GitHub Desktop.
DRY your specs - Example: Sign in user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/support/controller_spec_helper.rb | |
module ControllerSpecHelper | |
def sign_in_user(user) | |
controller.stub!(:current_user).and_return user | |
end | |
end | |
# spec/spec_helper.rb | |
RSpec.configure do |config| | |
# [..] | |
config.include(ControllerSpecHelper, :type => :controller) | |
end | |
# some controller spec where authentification is required | |
before :each do | |
@user = Factory.create(:user) | |
sign_in_user @user | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment