Module: Containable::Test
- Defined in:
- lib/containable/test.rb
Overview
Allows stubbing of dependencies for testing purposes only.
Instance Method Summary collapse
Instance Method Details
#resolve(key) ⇒ Object Also known as: []
6 |
# File 'lib/containable/test.rb', line 6 def resolve(key) = stubs.fetch(key.to_s) { super } |
#restore ⇒ Object
24 25 26 27 28 |
# File 'lib/containable/test.rb', line 24 def restore stubs.clear dependencies.replace originals if originals true end |
#stub(**overrides) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/containable/test.rb', line 10 def stub(**overrides) @originals ||= dependencies.dup overrides.each do |key, value| normalized_key = key.to_s fail KeyError, "Unable to stub unknown key: #{key.inspect}." unless key? normalized_key stubs[normalized_key] = value end end |
#stub! ⇒ Object
22 |
# File 'lib/containable/test.rb', line 22 def stub!(**) = stub(**) |