You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
597 B
23 lines
597 B
# Allow matching arrays in "ba_able_to" |
|
# |
|
# user.should be_able_to [:read, :write], post |
|
# |
|
RSpec::Matchers.define :be_able_to do |*args| |
|
match do |ability| |
|
arguments = args.dup |
|
first = arguments.delete_at(0) |
|
if first.is_a?(Array) |
|
first.all?{|operation| ability.can?(operation, *arguments)} |
|
else |
|
ability.can?(*args) |
|
end |
|
end |
|
|
|
failure_message_for_should do |ability| |
|
"expected to be able to #{args.map(&:inspect).join(" ")}" |
|
end |
|
|
|
failure_message_for_should_not do |ability| |
|
"expected not to be able to #{args.map(&:inspect).join(" ")}" |
|
end |
|
end
|
|
|