Skip to content

Instantly share code, notes, and snippets.

@jmaicher
Created December 16, 2010 09:43
Show Gist options
  • Save jmaicher/743238 to your computer and use it in GitHub Desktop.
Save jmaicher/743238 to your computer and use it in GitHub Desktop.
DRY your specs - Example: Sign in user
# 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