lib/spec/matchers/include.rb in dchelimsky-rspec-1.1.11 vs lib/spec/matchers/include.rb in dchelimsky-rspec-1.1.11.1
- old
+ new
@@ -5,20 +5,23 @@
def initialize(*expecteds)
@expecteds = expecteds
end
- def matches?(given)
- @given = given
+ def matches?(actual)
+ @actual = actual
@expecteds.each do |expected|
- case given
- when Hash
- expected.each_pair do |k,v|
- return false unless given[k] == v
+ if actual.is_a?(Hash)
+ if expected.is_a?(Hash)
+ expected.each_pair do |k,v|
+ return false unless actual[k] == v
+ end
+ else
+ return false unless actual.has_key?(expected)
end
else
- return false unless given.include?(expected)
+ return false unless actual.include?(expected)
end
end
true
end
@@ -34,11 +37,11 @@
"include #{_pretty_print(@expecteds)}"
end
private
def _message(maybe_not="")
- "expected #{@given.inspect} #{maybe_not}to include #{_pretty_print(@expecteds)}"
+ "expected #{@actual.inspect} #{maybe_not}to include #{_pretty_print(@expecteds)}"
end
def _pretty_print(array)
result = ""
array.each_with_index do |item, index|
@@ -56,10 +59,10 @@
# :call-seq:
# should include(expected)
# should_not include(expected)
#
- # Passes if given includes expected. This works for
+ # Passes if actual includes expected. This works for
# collections and Strings. You can also pass in multiple args
# and it will only pass if all args are found in collection.
#
# == Examples
#