module ThoughtBot::Shoulda::Assertions
def assert_contains(collection, x, extra_msg = "")
assert_contains(['a', '1'], 'a') => passes
assert_contains(['a', '1'], /\d/) => passes
at least one element from the collection matches x. +extra_msg+ is appended to the error message if the assertion fails.
Asserts that the given collection contains item x. If x is a regular expression, ensure that
def assert_contains(collection, x, extra_msg = "") collection = [collection] unless collection.is_a?(Array) msg = "#{x.inspect} not found in #{collection.to_a.inspect} #{extra_msg}" case x when Regexp assert(collection.detect { |e| e =~ x }, msg) else assert(collection.include?(x), msg) end end