Class: Caricature::RSpecMatchers::HaveReceived

Inherits:
Object
  • Object
show all
Defined in:
lib/caricature/rspec/integration.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ HaveReceived

Returns a new instance of HaveReceived.



18
19
20
21
# File 'lib/caricature/rspec/integration.rb', line 18

def initialize(expected)
  @expected = expected
  @block_args, @error, @args = nil, "", [:any]
end

Instance Method Details

#allow_any_argumentsObject

allow any arguments ignore the argument constraint



58
59
60
61
# File 'lib/caricature/rspec/integration.rb', line 58

def allow_any_arguments
  @args = :any
  self
end

#failure_message_for_shouldObject



35
36
37
# File 'lib/caricature/rspec/integration.rb', line 35

def failure_message_for_should
  "expected #{@target.inspect} to have received #{@expected}" + @error
end

#failure_message_for_should_notObject



39
40
41
# File 'lib/caricature/rspec/integration.rb', line 39

def failure_message_for_should_not
  "expected #{@target.inspect} not to have received #{@expected}" + @error
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/caricature/rspec/integration.rb', line 23

def matches?(target)
  @target = target

  veri = @target.did_receive?(@expected).with(*@args)
  veri.with_block_args(*@block_args) if @block_args
  result = veri.successful?

  @error = "\n#{veri.error}" unless result

  result
end

#with(*args) ⇒ Object

constrain this verification to the provided arguments



44
45
46
47
48
49
50
# File 'lib/caricature/rspec/integration.rb', line 44

def with(*args)
  ags = *args
  @args = args
  @args = [:any] if (args.first.is_a?(Symbol) and args.first == :any) || ags.nil?
  # @callback = b if b
  self
end

#with_block_args(*args) ⇒ Object



52
53
54
55
# File 'lib/caricature/rspec/integration.rb', line 52

def with_block_args(*args)
  @block_args = args
  self
end