Skip to content

Instantly share code, notes, and snippets.

@pietern
Created January 20, 2010 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pietern/281750 to your computer and use it in GitHub Desktop.
Save pietern/281750 to your computer and use it in GitHub Desktop.
# Add config.include(Matchers) to your spec_helper.rb
# ability.should allow_to(:manage, Post)
#
module Matchers
class CanCanMatcher
def initialize(action, noun)
@action, @noun = action, noun
end
def matches?(ability)
ability.can?(@action, @noun)
end
def failure_message
"expected ability to allow #{@action} on #{@noun}"
end
def negative_failure_message
"expected ability to disallow #{@action} on #{@noun}"
end
end
def allow_to(*args)
CanCanMatcher.new(*args)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment