Class: Mocktail::HandlesDryNewCall

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mocktail/handles_dry_new_call.rb,
lib/mocktail/sorbet/mocktail/handles_dry_new_call.rb

Instance Method Summary collapse

Constructor Details

#initializeHandlesDryNewCall

Returns a new instance of HandlesDryNewCall.



5
6
7
8
9
10
# File 'lib/mocktail/handles_dry_new_call.rb', line 5

def initialize
  @validates_arguments = ValidatesArguments.new
  @logs_call = LogsCall.new
  @fulfills_stubbing = FulfillsStubbing.new
  @imitates_type = ImitatesType.new
end

Instance Method Details

#handle(type, args, kwargs, block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mocktail/handles_dry_new_call.rb', line 12

def handle(type, args, kwargs, block)
  @validates_arguments.validate(Call.new(
    original_method: type.instance_method(:initialize),
    args: args,
    kwargs: kwargs,
    block: block
  ))

  new_call = Call.new(
    singleton: true,
    double: type,
    original_type: type,
    dry_type: type,
    method: :new,
    args: args,
    kwargs: kwargs,
    block: block
  )
  @logs_call.log(new_call)
  if @fulfills_stubbing.satisfaction(new_call)
    @fulfills_stubbing.fulfill(new_call)
  else
    @imitates_type.imitate(type)
  end
end