Class: Rspec::Something::Proxy
- Inherits:
-
Object
- Object
- Rspec::Something::Proxy
- Defined in:
- lib/rspec/something/proxy.rb
Instance Method Summary collapse
-
#initialize(_double) ⇒ Proxy
constructor
A new instance of Proxy.
-
#method_missing(name, *args) ⇒ Object
set expectation to double at first method invocation and return double itself.
- #won_t ⇒ Object
Constructor Details
#initialize(_double) ⇒ Proxy
Returns a new instance of Proxy.
5 6 7 8 |
# File 'lib/rspec/something/proxy.rb', line 5 def initialize(_double) @_won_t = false @double = _double end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
set expectation to double at first method invocation and return double itself.
13 14 15 16 17 18 |
# File 'lib/rspec/something/proxy.rb', line 13 def method_missing(name, *args) (should_be_received? ? @double.should_receive(name) : @double.should_not_receive(name)) .tap {|o| o.with(*args) unless args.empty? } @double end |
Instance Method Details
#won_t ⇒ Object
20 21 22 23 |
# File 'lib/rspec/something/proxy.rb', line 20 def won_t @_won_t = true self end |