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?
  true
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 41
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 45
def comparing_hash_values?(actual, expected)
  actual.is_a?(Hash) && expected.is_a?(Hash)
end
perform_match(predicate, hash_predicate, actuals, expecteds) click to toggle source
# File lib/rspec/matchers/built_in/include.rb, line 29
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[k] == v}
    elsif comparing_hash_keys?(actuals, expected)
      actuals.has_key?(expected)
    else
      actuals.include?(expected)
    end
  end
end