add be_able_to matcher
This commit is contained in:
parent
35c4864de4
commit
cf49c5b9de
13
lib/cancan/matchers.rb
Normal file
13
lib/cancan/matchers.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
Spec::Matchers.define :be_able_to do |action, subject|
|
||||||
|
match do |model|
|
||||||
|
model.can?(action, subject)
|
||||||
|
end
|
||||||
|
|
||||||
|
failure_message_for_should do |model|
|
||||||
|
"expected to be able to #{action.inspect} #{subject.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
|
failure_message_for_should_not do |model|
|
||||||
|
"expected not to be able to #{action.inspect} #{subject.inspect}"
|
||||||
|
end
|
||||||
|
end
|
25
spec/cancan/matchers_spec.rb
Normal file
25
spec/cancan/matchers_spec.rb
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
require "spec_helper"
|
||||||
|
|
||||||
|
describe "be_able_to" do
|
||||||
|
it "delegates to can?" do
|
||||||
|
object = Object.new
|
||||||
|
mock(object).can?(:read, 123) { true }
|
||||||
|
object.should be_able_to(:read, 123)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports a nice failure message for should" do
|
||||||
|
object = Object.new
|
||||||
|
mock(object).can?(:read, 123) { false }
|
||||||
|
expect do
|
||||||
|
object.should be_able_to(:read, 123)
|
||||||
|
end.should raise_error('expected to be able to :read 123')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports a nice failure message for should not" do
|
||||||
|
object = Object.new
|
||||||
|
mock(object).can?(:read, 123) { true }
|
||||||
|
expect do
|
||||||
|
object.should_not be_able_to(:read, 123)
|
||||||
|
end.should raise_error('expected not to be able to :read 123')
|
||||||
|
end
|
||||||
|
end
|
|
@ -5,6 +5,7 @@ require 'active_record'
|
||||||
require 'action_controller'
|
require 'action_controller'
|
||||||
require 'action_view'
|
require 'action_view'
|
||||||
require 'cancan'
|
require 'cancan'
|
||||||
|
require 'cancan/matchers'
|
||||||
|
|
||||||
Spec::Runner.configure do |config|
|
Spec::Runner.configure do |config|
|
||||||
config.mock_with :rr
|
config.mock_with :rr
|
||||||
|
|
Loading…
Reference in New Issue
Block a user