Created
October 26, 2012 16:43
-
-
Save fables-tales/3959827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/rspec/matchers/built_in/match_array.rb b/lib/rspec/matchers/built_in/match_array.rb | |
index f1ea560..671399c 100644 | |
--- a/lib/rspec/matchers/built_in/match_array.rb | |
+++ b/lib/rspec/matchers/built_in/match_array.rb | |
@@ -2,8 +2,13 @@ module RSpec | |
module Matchers | |
module BuiltIn | |
class MatchArray < BaseMatcher | |
+ | |
+ def quacks_like_array?(object) | |
+ [:dup, :each, :index, :delete_at].map {|x| object.respond_to? x}.all? | |
+ end | |
+ | |
def match(expected, actual) | |
- return false unless actual.is_a? Array | |
+ return false unless quacks_like_array? actual | |
@extra_items = difference_between_arrays(actual, expected) | |
@missing_items = difference_between_arrays(expected, actual) | |
@@ -11,7 +16,7 @@ module RSpec | |
end | |
def failure_message_for_should | |
- if actual.is_a? Array | |
+ if quacks_like_array? actual | |
message = "expected collection contained: #{safe_sort(expected).inspect}\n" | |
message += "actual collection contained: #{safe_sort(actual).inspect}\n" | |
message += "the missing elements were: #{safe_sort(@missing_items).inspect}\n" unless @missing_items.empty? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment