Class: Bogus::Shadow

Inherits:
Object
  • Object
show all
Defined in:
lib/bogus/stubbing/shadow.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShadow

Returns a new instance of Shadow.



5
6
7
8
9
# File 'lib/bogus/stubbing/shadow.rb', line 5

def initialize
  @calls = []
  @stubs = []
  @required = Set.new
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



3
4
5
# File 'lib/bogus/stubbing/shadow.rb', line 3

def calls
  @calls
end

Class Method Details

.has_shadow?(object) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/bogus/stubbing/shadow.rb', line 41

def self.has_shadow?(object)
  object.respond_to?(:__shadow__)
end

Instance Method Details

#has_received(name, args) ⇒ Object



17
18
19
# 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) ⇒ Object



28
29
30
31
# 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) ⇒ Object



11
12
13
14
15
# 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) ⇒ Object



21
22
23
24
25
26
# 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_interactionsObject



33
34
35
36
37
38
39
# 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