6 def initialize(*expecteds)
12 @expecteds.each do |expected|
13 return false unless actual.include?(expected)
22 def negative_failure_message
27 "include #{_pretty_print(@expecteds)}"
31 def _message(maybe_not="")
32 "expected #{@actual.inspect} #{maybe_not}to include #{_pretty_print(@expecteds)}"
35 def _pretty_print(array)
37 array.each_with_index do |item, index|
38 if index < (array.length - 2)
39 result << "#{item.inspect}, "
40 elsif index < (array.length - 1)
41 result << "#{item.inspect} and "
43 result << "#{item.inspect}"
51 # should include(expected)
52 # should_not include(expected)
54 # Passes if actual includes expected. This works for
55 # collections and Strings. You can also pass in multiple args
56 # and it will only pass if all args are found in collection.
60 # [1,2,3].should include(3)
61 # [1,2,3].should include(2,3) #would pass
62 # [1,2,3].should include(2,3,4) #would fail
63 # [1,2,3].should_not include(4)
64 # "spread".should include("read")
65 # "spread".should_not include("red")
66 def include(*expected)
67 Matchers::Include.new(*expected)