Module: VerifiedDouble::RSpecMocksSyntaxOverrides

Defined in:
lib/verified_double/rspec_mocks_syntax_overrides.rb

Instance Method Summary collapse

Instance Method Details

#allow(*args) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/verified_double/rspec_mocks_syntax_overrides.rb', line 3

def allow(*args)
  if args[0].respond_to?(:can_record_interactions?)
    VerifiedDouble.registry.current_double = args[0]
  else
    VerifiedDouble.registry.current_double = nil
  end
  super(*args)
end

#expect(*args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/verified_double/rspec_mocks_syntax_overrides.rb', line 12

def expect(*args)
  if args[0].respond_to?(:can_record_interactions?)
    if args[0].respond_to?(:verified_any_instance_double?)
      raise "VerifiedDouble.any_instance_of doesn't support yet Rspec's " \
        "expect/allow syntax. Please use should_receive."
    else
      VerifiedDouble.registry.current_double = args[0]
    end


  else
    VerifiedDouble.registry.current_double = nil
  end
  super(*args)
end

#receive(*args) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/verified_double/rspec_mocks_syntax_overrides.rb', line 28

def receive(*args)
  if VerifiedDouble.registry.current_double
    VerifiedDouble.registry.add_method_signature_with_current_double(args[0])
    super(*args).tap {|result| result.extend(VerifiedDouble::CanRecordInteractions) }
  else
    super(*args)
  end
end