Class: FlexMock::RSpecMatchers::HaveReceived

Inherits:
Object
  • Object
show all
Includes:
SpyDescribers
Defined in:
lib/flexmock/rspec_spy_matcher.rb

Instance Method Summary collapse

Methods included from SpyDescribers

#describe_spy_expectation, #describe_spy_negative_expectation

Constructor Details

#initialize(method_name) ⇒ HaveReceived

Returns a new instance of HaveReceived.



9
10
11
12
13
14
15
16
# File 'lib/flexmock/rspec_spy_matcher.rb', line 9

def initialize(method_name)
  @method_name = method_name
  @args = nil
  @block = nil
  @times = nil
  @needs_block = nil
  @additional_validations = []
end

Instance Method Details

#and(&block) ⇒ Object



69
70
71
72
# File 'lib/flexmock/rspec_spy_matcher.rb', line 69

def and(&block)
  @additional_validations << block
  self
end

#construct_optionsObject



74
75
76
77
78
79
80
81
# File 'lib/flexmock/rspec_spy_matcher.rb', line 74

def construct_options
  {
    :times      => @times,
    :with_block => @needs_block,
    :on_count   => @on_count,
    :and        => @additional_validations,
  }
end

#failure_message_for_shouldObject



24
25
26
# File 'lib/flexmock/rspec_spy_matcher.rb', line 24

def failure_message_for_should
  describe_spy_expectation(@spy, @method_name, @args, @options)
end

#failure_message_for_should_notObject



28
29
30
# File 'lib/flexmock/rspec_spy_matcher.rb', line 28

def failure_message_for_should_not
  describe_spy_negative_expectation(@spy, @method_name, @args, @options)
end

#matches?(spy) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/flexmock/rspec_spy_matcher.rb', line 18

def matches?(spy)
  @spy = spy
  @options = construct_options
  @spy.flexmock_received?(@method_name, @args, @options)
end

#neverObject



52
53
54
# File 'lib/flexmock/rspec_spy_matcher.rb', line 52

def never
  times(0)
end

#on(on_count) ⇒ Object



64
65
66
67
# File 'lib/flexmock/rspec_spy_matcher.rb', line 64

def on(on_count)
  @on_count = on_count
  self
end

#onceObject



56
57
58
# File 'lib/flexmock/rspec_spy_matcher.rb', line 56

def once
  times(1)
end

#times(n) ⇒ Object



47
48
49
50
# File 'lib/flexmock/rspec_spy_matcher.rb', line 47

def times(n)
  @times = n
  self
end

#twiceObject



60
61
62
# File 'lib/flexmock/rspec_spy_matcher.rb', line 60

def twice
  times(2)
end

#with(*args) ⇒ Object



32
33
34
35
# File 'lib/flexmock/rspec_spy_matcher.rb', line 32

def with(*args)
  @args = args
  self
end

#with_a_blockObject



37
38
39
40
# File 'lib/flexmock/rspec_spy_matcher.rb', line 37

def with_a_block
  @needs_block = true
  self
end

#without_a_blockObject



42
43
44
45
# File 'lib/flexmock/rspec_spy_matcher.rb', line 42

def without_a_block
  @needs_block = false
  self
end