Created
May 21, 2012 03:17
-
-
Save sj26/2760421 to your computer and use it in GitHub Desktop.
Devise be_signed_in rspec matcher
This file contains hidden or 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
module DeviseMatchers | |
class BeSignedIn | |
attr_reader :warden, :scope_or_resource | |
def initialize warden, scope_or_resource=nil | |
@warden = warden | |
@scope_or_resource = scope_or_resource | |
end | |
def matches? actual | |
if scope_or_resource.nil? | |
Devise.mappings.any? { |scope| warden.authenticated? scope } | |
else | |
scope = Devise::Mapping.find_scope!(scope_or_resource) | |
warden.authenticated? scope | |
end | |
end | |
end | |
def be_signed_in scope_or_resource=nil | |
BeSignedIn.new warden, scope_or_resource | |
end | |
end | |
RSpec.configure do |config| | |
config.include DeviseMatchers, type: :controller | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment