class Bogus::Interaction::ArgumentComparator

Attributes

recorded[R]
stubbed[R]

Public Class Methods

new(opts = {}) click to toggle source
# File lib/bogus/stubbing/interaction.rb, line 56
def initialize(opts = {})
  @recorded = opts.fetch(:recorded)
  @stubbed = opts.fetch(:stubbed)
end

Public Instance Methods

same?() click to toggle source
# File lib/bogus/stubbing/interaction.rb, line 61
def same?
  return true if with_matcher_args?

  stubbed == recorded_without_defaults
end

Private Instance Methods

recorded_has_keyword?() click to toggle source
# File lib/bogus/stubbing/interaction.rb, line 87
def recorded_has_keyword?
  last_recorded = recorded.last
  return false unless last_recorded.is_a?(Hash)
  last_recorded.values.any? { |v| DefaultValue == v }
end
recorded_without_defaults() click to toggle source
# File lib/bogus/stubbing/interaction.rb, line 69
def recorded_without_defaults
  without_defaults = recorded.reject{|v| DefaultValue == v}
  remove_default_keywords(without_defaults)
end
remove_default_keywords(recorded) click to toggle source
# File lib/bogus/stubbing/interaction.rb, line 74
def remove_default_keywords(recorded)
  return recorded unless recorded_has_keyword?
  positional = recorded[0...-1]
  keyword = recorded.last
  without_defaults = keyword.reject{|_, v| DefaultValue == v}
  return positional if without_defaults.empty?
  positional + [without_defaults]
end
with_matcher_args?() click to toggle source
# File lib/bogus/stubbing/interaction.rb, line 83
def with_matcher_args?
  WithArguments.matches?(stubbed: stubbed, recorded: recorded_without_defaults)
end