class Bogus::Shadow

Attributes

calls[R]

Public Class Methods

has_shadow?(object) click to toggle source
# File lib/bogus/stubbing/shadow.rb, line 41
def self.has_shadow?(object)
  object.respond_to?(:__shadow__)
end
new() click to toggle source
# File lib/bogus/stubbing/shadow.rb, line 5
def initialize
  @calls = []
  @stubs = []
  @required = Set.new
end

Public Instance Methods

has_received(name, args) click to toggle source
# File lib/bogus/stubbing/shadow.rb, line 17
def has_received(name, args)
  @calls.any? { |i| Interaction.same?(recorded: i, stubbed: Interaction.new(name, args)) }
end
mocks(name, *args, &return_value) click to toggle source
# File lib/bogus/stubbing/shadow.rb, line 28
def mocks(name, *args, &return_value)
  interaction = stubs(name, *args, &return_value)
  @required.add(interaction)
end
run(method_name, *args) click to toggle source
# File lib/bogus/stubbing/shadow.rb, line 11
def run(method_name, *args)
  interaction = Interaction.new(method_name, args)
  @calls << interaction
  return_value(interaction)
end
stubs(name, *args, &return_value) click to toggle source
# File lib/bogus/stubbing/shadow.rb, line 21
def stubs(name, *args, &return_value)
  interaction = Interaction.new(name, args)
  add_stub(interaction, return_value)
  @required.reject! { |i| Interaction.same?(recorded: i, stubbed: interaction) }
  interaction
end
unsatisfied_interactions() click to toggle source
# File lib/bogus/stubbing/shadow.rb, line 33
def unsatisfied_interactions
  @required.reject do |stubbed|
    @calls.any? do |recorded|
      Interaction.same?(recorded: recorded, stubbed: stubbed)
    end
  end
end

Private Instance Methods

add_stub(interaction, return_value_block) click to toggle source
# File lib/bogus/stubbing/shadow.rb, line 47
def add_stub(interaction, return_value_block)
  @stubs << [interaction, return_value_block] if return_value_block
end
return_value(interaction) click to toggle source
# File lib/bogus/stubbing/shadow.rb, line 51
def return_value(interaction)
  _, return_value = @stubs.reverse.find{|i, v| Interaction.same?(recorded: interaction, stubbed: i)}
  return_value ||= proc{ UndefinedReturnValue.new(interaction) }
  return_value.call
end