Class: Crabfarm::RSpec::ReducerSpyManager

Inherits:
Object
  • Object
show all
Defined in:
lib/crabfarm/rspec/reducer_spy_manager.rb

Instance Method Summary collapse

Constructor Details

#initializeReducerSpyManager

Returns a new instance of ReducerSpyManager.



8
9
10
# File 'lib/crabfarm/rspec/reducer_spy_manager.rb', line 8

def initialize
  @spies = {}
end

Instance Method Details

#new_spy_for(_reducer_class) ⇒ Object



12
13
14
# File 'lib/crabfarm/rspec/reducer_spy_manager.rb', line 12

def new_spy_for(_reducer_class)
  @spies[_reducer_class.to_s] = ReducerSpy.new(_reducer_class)
end

#prepare(_class, _target, _params) ⇒ Object

reducer decorator implementation



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/crabfarm/rspec/reducer_spy_manager.rb', line 18

def prepare(_class, _target, _params)
  spy = @spies[_class.to_s]
  unless spy.nil?
    spy.register_call _target, _params
    if spy.mock
      mock = _class.new _target, _params
      mock.mock spy.mock

      def mock.run
        # do nothing
      end

      return mock
    end
  end
  nil
end