Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
allow additional arguments for be_able_to matcher, this requires Ruby…
Browse files Browse the repository at this point in the history
… 1.8.7 or higher to use matcher
  • Loading branch information
ryanb committed Apr 15, 2010
1 parent cf49c5b commit 6e1e96c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rdoc
@@ -1,5 +1,7 @@
1.1.0 (not released)

* Adding be_able_to RSpec matcher (thanks dchelimsky) - see issue #54

* Support additional arguments to can? which get passed to the block - see issue #48


Expand Down
8 changes: 4 additions & 4 deletions lib/cancan/matchers.rb
@@ -1,13 +1,13 @@
Spec::Matchers.define :be_able_to do |action, subject|
Spec::Matchers.define :be_able_to do |*args|
match do |model|
model.can?(action, subject)
model.can?(*args)
end

failure_message_for_should do |model|
"expected to be able to #{action.inspect} #{subject.inspect}"
"expected to be able to #{args.map(&:inspect).join(" ")}"
end

failure_message_for_should_not do |model|
"expected not to be able to #{action.inspect} #{subject.inspect}"
"expected not to be able to #{args.map(&:inspect).join(" ")}"
end
end
8 changes: 8 additions & 0 deletions spec/cancan/matchers_spec.rb
Expand Up @@ -22,4 +22,12 @@
object.should_not be_able_to(:read, 123)
end.should raise_error('expected not to be able to :read 123')
end

it "delegates additional arguments to can? and reports in failure message" do
object = Object.new
mock(object).can?(:read, 123, 456) { false }
expect do
object.should be_able_to(:read, 123, 456)
end.should raise_error('expected to be able to :read 123 456')
end
end

0 comments on commit 6e1e96c

Please sign in to comment.