Rspec matcher: include_kind_of
Simple way to check if array contains element with given class.
RSpec::Matchers.define :include_kind_of do |expected|
match do |actual|
actual.detect{ |item| item.kind_of?(expected) }
end
failure_message_for_should do |actual|
"expected that #{actual} includes kind of #{expected}"
end
failure_message_for_should_not do |actual|
"expected that #{actual} would not include kind of #{expected}"
end
description do
"includes kind of #{expected}"
end
end
Written by Gatis Tomsons
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#