Class: Mocktail::Cabinet

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mocktail/value/cabinet.rb,
lib/mocktail/sorbet/mocktail/value/cabinet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCabinet

Returns a new instance of Cabinet.



17
18
19
20
21
22
23
# File 'lib/mocktail/value/cabinet.rb', line 17

def initialize
  @doubles = []
  @calls = []
  @stubbings = []
  @unsatisfying_calls = []
  @demonstration_in_progress = false
end

Instance Attribute Details

#callsObject (readonly)

Returns the value of attribute calls.



11
12
13
# File 'lib/mocktail/value/cabinet.rb', line 11

def calls
  @calls
end

#demonstration_in_progress=(value) ⇒ Object (writeonly)

Sets the attribute demonstration_in_progress

Parameters:

  • value

    the value to set the attribute demonstration_in_progress to.



9
10
11
# File 'lib/mocktail/value/cabinet.rb', line 9

def demonstration_in_progress=(value)
  @demonstration_in_progress = value
end

#stubbingsObject (readonly)

Returns the value of attribute stubbings.



13
14
15
# File 'lib/mocktail/value/cabinet.rb', line 13

def stubbings
  @stubbings
end

#unsatisfying_callsObject (readonly)

Returns the value of attribute unsatisfying_calls.



15
16
17
# File 'lib/mocktail/value/cabinet.rb', line 15

def unsatisfying_calls
  @unsatisfying_calls
end

Instance Method Details

#calls_for_double(double) ⇒ Object



69
70
71
72
73
# File 'lib/mocktail/value/cabinet.rb', line 69

def calls_for_double(double)
  @calls.select { |call|
    Bind.call(call.double, :==, double.dry_instance)
  }
end

#demonstration_in_progress?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/mocktail/value/cabinet.rb', line 52

def demonstration_in_progress?
  @demonstration_in_progress
end

#double_for_instance(thing) ⇒ Object



56
57
58
59
60
61
# File 'lib/mocktail/value/cabinet.rb', line 56

def double_for_instance(thing)
  @doubles.find { |double|
    # Intentionally calling directly to avoid an infinite recursion in Bind.call
    Object.instance_method(:==).bind_call(double.dry_instance, thing)
  }
end

#reset!Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/mocktail/value/cabinet.rb', line 25

def reset!
  @calls = []
  @stubbings = []
  @unsatisfying_calls = []
  # Could cause an exception or prevent pollution—you decide!
  @demonstration_in_progress = false
  # note we don't reset doubles as they don't carry any
  # user-meaningful state on them, and clearing them on reset could result
  # in valid mocks being broken and stop working
end

#store_call(call) ⇒ Object



40
41
42
# File 'lib/mocktail/value/cabinet.rb', line 40

def store_call(call)
  @calls << call
end

#store_double(double) ⇒ Object



36
37
38
# File 'lib/mocktail/value/cabinet.rb', line 36

def store_double(double)
  @doubles << double
end

#store_stubbing(stubbing) ⇒ Object



44
45
46
# File 'lib/mocktail/value/cabinet.rb', line 44

def store_stubbing(stubbing)
  @stubbings << stubbing
end

#store_unsatisfying_call(unsatisfying_call) ⇒ Object



48
49
50
# File 'lib/mocktail/value/cabinet.rb', line 48

def store_unsatisfying_call(unsatisfying_call)
  @unsatisfying_calls << unsatisfying_call
end

#stubbings_for_double(double) ⇒ Object



63
64
65
66
67
# File 'lib/mocktail/value/cabinet.rb', line 63

def stubbings_for_double(double)
  @stubbings.select { |stubbing|
    Bind.call(stubbing.recording.double, :==, double.dry_instance)
  }
end