Skip to content

@kevinrutherford /spec_helper.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Mocking warden in controller specs
module RandomHelpers
def random_number() SecureRandom.random_number(10000); end
def random_id() random_number; end
def random_name() SecureRandom.hex(20); end
end
module ControllerHelpers
def user_double(attrs = {})
user_attrs = {
:first_name => random_name,
:last_name => random_name,
:authenticatable_salt => 'x'
}.merge(attrs)
mock_model(User, user_attrs)
end
def stub_sign_in_with(user)
request.env['warden'] = double(Warden,
:authenticate => user,
:authenticate! => user,
:authenticate? => true)
sign_in(user)
return user
end
def stub_sign_in(attrs = {})
stub_sign_in_with user_double(attrs)
end
end
RSpec.configure do |config|
config.include RandomHelpers
config.include Devise::TestHelpers, :type => :controller
config.include ControllerHelpers, :type => :controller
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.