Skip to content

Commit

Permalink
Updated assert_contains and assert_does_not_contain to work with …
Browse files Browse the repository at this point in the history
…more objects that quack like an Array

Closes https://github.com/thoughtbot/shoulda/issues/#issue/139
  • Loading branch information
rmm5t committed Jan 30, 2011
1 parent 9ce23d7 commit 2c66aa8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/shoulda/context/assertions.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2c66aa8

Please sign in to comment.