Permalink
Browse files

Updated `assert_contains` and `assert_does_not_contain` to work with …

…more objects that quack like an Array

Closes https://github.com/thoughtbot/shoulda/issues/#issue/139
  • Loading branch information...
1 parent 9ce23d7 commit 2c66aa8913a23da3b8cbca4fef2b60f820893604 @rmm5t rmm5t committed Jan 30, 2011
Showing with 2 additions and 2 deletions.
  1. +2 −2 lib/shoulda/context/assertions.rb
@@ -22,7 +22,7 @@ def assert_same_elements(a1, a2, msg = nil)
# assert_contains(['a', '1'], 'a') => passes
# assert_contains(['a', '1'], /not there/) => fails
def assert_contains(collection, x, extra_msg = "")
- collection = [collection] unless collection.is_a?(Array)
+ collection = Array(collection)
msg = "#{x.inspect} not found in #{collection.to_a.inspect} #{extra_msg}"
case x
when Regexp
@@ -35,7 +35,7 @@ def assert_contains(collection, x, extra_msg = "")
# Asserts that the given collection does not contain item x. If x is a regular expression, ensure that
# none of the elements from the collection match x.
def assert_does_not_contain(collection, x, extra_msg = "")
- collection = [collection] unless collection.is_a?(Array)
+ collection = Array(collection)
msg = "#{x.inspect} found in #{collection.to_a.inspect} " + extra_msg
case x
when Regexp

0 comments on commit 2c66aa8

Please sign in to comment.