Skip to content

Instantly share code, notes, and snippets.

@sj26
Created May 21, 2012 03:17
Show Gist options
  • Save sj26/2760421 to your computer and use it in GitHub Desktop.
Save sj26/2760421 to your computer and use it in GitHub Desktop.
Devise be_signed_in rspec matcher
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