Class: Mocktail::Cabinet
- Inherits:
-
Object
- Object
- Mocktail::Cabinet
- Extended by:
- T::Sig
- Defined in:
- lib/mocktail/value/cabinet.rb,
lib/mocktail/sorbet/mocktail/value/cabinet.rb
Instance Attribute Summary collapse
-
#calls ⇒ Object
readonly
Returns the value of attribute calls.
-
#demonstration_in_progress ⇒ Object
writeonly
Sets the attribute demonstration_in_progress.
-
#stubbings ⇒ Object
readonly
Returns the value of attribute stubbings.
-
#unsatisfying_calls ⇒ Object
readonly
Returns the value of attribute unsatisfying_calls.
Instance Method Summary collapse
- #calls_for_double(double) ⇒ Object
- #demonstration_in_progress? ⇒ Boolean
- #double_for_instance(thing) ⇒ Object
-
#initialize ⇒ Cabinet
constructor
A new instance of Cabinet.
- #reset! ⇒ Object
- #store_call(call) ⇒ Object
- #store_double(double) ⇒ Object
- #store_stubbing(stubbing) ⇒ Object
- #store_unsatisfying_call(unsatisfying_call) ⇒ Object
- #stubbings_for_double(double) ⇒ Object
Constructor Details
#initialize ⇒ Cabinet
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
#calls ⇒ Object (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
9 10 11 |
# File 'lib/mocktail/value/cabinet.rb', line 9 def demonstration_in_progress=(value) @demonstration_in_progress = value end |
#stubbings ⇒ Object (readonly)
Returns the value of attribute stubbings.
13 14 15 |
# File 'lib/mocktail/value/cabinet.rb', line 13 def stubbings @stubbings end |
#unsatisfying_calls ⇒ Object (readonly)
Returns the value of attribute unsatisfying_calls.
15 16 17 |
# File 'lib/mocktail/value/cabinet.rb', line 15 def @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
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 () @unsatisfying_calls << end |