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.



23
24
25
26
# File 'lib/caricature/rspec/integration.rb', line 23

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



63
64
65
66
# File 'lib/caricature/rspec/integration.rb', line 63

def allow_any_arguments
  @args = :any
  self
end

#failure_message_for_shouldObject



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

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

#failure_message_for_should_notObject



44
45
46
# File 'lib/caricature/rspec/integration.rb', line 44

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

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/caricature/rspec/integration.rb', line 28

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



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

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



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

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