Last Updated: February 25, 2016
·
417
· gacha

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