diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 4d73c53..3621703 100644 --- a/CHANGELOG.rdoc +++ b/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 diff --git a/lib/cancan/matchers.rb b/lib/cancan/matchers.rb index ef764e6..d9628bc 100644 --- a/lib/cancan/matchers.rb +++ b/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 diff --git a/spec/cancan/matchers_spec.rb b/spec/cancan/matchers_spec.rb index 622ae69..de6a439 100644 --- a/spec/cancan/matchers_spec.rb +++ b/spec/cancan/matchers_spec.rb @@ -22,4 +22,12 @@ describe "be_able_to" do 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