Class: Rspec::Something::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/something/proxy.rb

Instance Method Summary collapse

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
19
20
21
22
23
24
25
# File 'lib/rspec/something/proxy.rb', line 13

def method_missing(name, *args)
  receive = RSpec::Mocks::Matchers::Receive.new(name, nil)
  receive.with(*args) unless args.empty?

  target = RSpec::Mocks::ExpectationTarget.new(@double)
  if should_be_received?
    target.to(receive)
  else
    target.not_to(receive)
  end

  @double
end

Instance Method Details

#won_tObject



27
28
29
30
# File 'lib/rspec/something/proxy.rb', line 27

def won_t
  @_won_t = true
  self
end