1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00
kaminari--kaminari/spec/support/matchers.rb

41 lines
956 B
Ruby
Raw Normal View History

2011-02-05 09:20:06 -05:00
RSpec::Matchers.define :contain_tag do |klass|
match do |collection|
if @num.blank?
collection.any? {|tag| tag.is_a? klass}
else
(@count = collection.count {|tag| tag.is_a? klass}) == @num
end
end
def count(num)
@num = num
self
end
description do
"contain #{@num || 'any'} instance(s) of #{klass.name}"
end
failure_message_for_should do |collection|
"expected #{@num || 'any'} instance(s) of #{klass.name} but was #{@count}"
end
end
RSpec::Matchers.define :contain_tag_old do |count|
match do |collection|
(@count = collection.count {|tag| tag.is_a? @klass}) == count
end
def instance_of(klass)
@klass = klass
self
end
alias :instances_of :instance_of
description do
"contain #{count || 'any'} instance(s) of #{@klass.name}"
end
failure_message_for_should do |collection|
"expected #{count || 'any'} instance(s) of #{@klass.name} but was #{@count}"
end
end