Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 2c66aa8913a23da3b8cbca4fef2b60f820893604 1 parent 9ce23d7
Ryan McGeary authored January 29, 2011

Showing 1 changed file with 2 additions and 2 deletions. Show diff stats Hide diff stats

  1. 4  lib/shoulda/context/assertions.rb
4  lib/shoulda/context/assertions.rb
@@ -22,7 +22,7 @@ def assert_same_elements(a1, a2, msg = nil)
22 22
       #   assert_contains(['a', '1'], 'a') => passes
23 23
       #   assert_contains(['a', '1'], /not there/) => fails
24 24
       def assert_contains(collection, x, extra_msg = "")
25  
-        collection = [collection] unless collection.is_a?(Array)
  25
+        collection = Array(collection)
26 26
         msg = "#{x.inspect} not found in #{collection.to_a.inspect} #{extra_msg}"
27 27
         case x
28 28
         when Regexp
@@ -35,7 +35,7 @@ def assert_contains(collection, x, extra_msg = "")
35 35
       # Asserts that the given collection does not contain item x.  If x is a regular expression, ensure that
36 36
       # none of the elements from the collection match x.
37 37
       def assert_does_not_contain(collection, x, extra_msg = "")
38  
-        collection = [collection] unless collection.is_a?(Array)
  38
+        collection = Array(collection)
39 39
         msg = "#{x.inspect} found in #{collection.to_a.inspect} " + extra_msg
40 40
         case x
41 41
         when Regexp

0 notes on commit 2c66aa8

Please sign in to comment.
Something went wrong with that request. Please try again.