class RSpec::Matchers::BuiltIn::Include

Public Class Methods

new(*expected) click to toggle source
# File lib/rspec/matchers/built_in/include.rb, line 5
def initialize(*expected)
  @expected = expected
end

Public Instance Methods

description() click to toggle source
# File lib/rspec/matchers/built_in/include.rb, line 19
def description
  "include#{expected_to_sentence}"
end
diffable?() click to toggle source
# File lib/rspec/matchers/built_in/include.rb, line 23
def diffable?
  # Matchers do not diff well, since diff uses their inspect
  # output, which includes their instance variables and such.
  @expected.none? { |e| RSpec::Matchers.is_a_matcher?(e) }
end
does_not_match?(actual) click to toggle source
# File lib/rspec/matchers/built_in/include.rb, line 14
def does_not_match?(actual)
  @actual = actual
  perform_match(:none?, :any?, @actual, @expected)
end
matches?(actual) click to toggle source
# File lib/rspec/matchers/built_in/include.rb, line 9
def matches?(actual)
  @actual = actual
  perform_match(:all?, :all?, @actual, @expected)
end

Private Instance Methods

comparing_hash_keys?(actual, expected) click to toggle source
# File lib/rspec/matchers/built_in/include.rb, line 47
def comparing_hash_keys?(actual, expected)
  actual.is_a?(Hash) && !expected.is_a?(Hash)
end
comparing_hash_values?(actual, expected) click to toggle source
# File lib/rspec/matchers/built_in/include.rb, line 51
def comparing_hash_values?(actual, expected)
  actual.is_a?(Hash) && expected.is_a?(Hash)
end
comparing_with_matcher?(actual, expected) click to toggle source
# File lib/rspec/matchers/built_in/include.rb, line 55
def comparing_with_matcher?(actual, expected)
  actual.is_a?(Array) && RSpec::Matchers.is_a_matcher?(expected)
end
perform_match(predicate, hash_predicate, actuals, expecteds) click to toggle source
# File lib/rspec/matchers/built_in/include.rb, line 31
def perform_match(predicate, hash_predicate, actuals, expecteds)
  expecteds.__send__(predicate) do |expected|
    if comparing_hash_values?(actuals, expected)
      expected.__send__(hash_predicate) { |k,v|
        actuals.has_key?(k) && actuals[k] == v
      }
    elsif comparing_hash_keys?(actuals, expected)
      actuals.has_key?(expected)
    elsif comparing_with_matcher?(actual, expected)
      actual.any? { |value| expected.matches?(value) }
    else
      actuals.include?(expected)
    end
  end
end