Class: Moarspec::Matchers::SendMessage

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers::Composable, RSpec::Mocks::ExampleMethods
Defined in:
lib/moarspec/matchers/send_message.rb

Instance Method Summary collapse

Constructor Details

#initialize(target, method) ⇒ SendMessage



10
11
12
13
# File 'lib/moarspec/matchers/send_message.rb', line 10

def initialize(target, method)
  @target = target
  @method = method
end

Instance Method Details

#at_least(n) ⇒ Object



36
37
38
39
# File 'lib/moarspec/matchers/send_message.rb', line 36

def at_least(n)
  @at_least = n
  self
end

#at_most(n) ⇒ Object



41
42
43
44
# File 'lib/moarspec/matchers/send_message.rb', line 41

def at_most(n)
  @at_most = n
  self
end

#calling_originalObject



26
27
28
29
# File 'lib/moarspec/matchers/send_message.rb', line 26

def calling_original
  @call_original = true
  self
end

#descriptionObject



93
94
95
# File 'lib/moarspec/matchers/send_message.rb', line 93

def description
  format('send %p.%s', @target, @method)
end

#does_not_match?(subject) ⇒ Boolean



82
83
84
85
86
# File 'lib/moarspec/matchers/send_message.rb', line 82

def does_not_match?(subject)
  run(subject)
  expect(@target).not_to expectation
  true
end

#exactly(n) ⇒ Object



31
32
33
34
# File 'lib/moarspec/matchers/send_message.rb', line 31

def exactly(n)
  @times = n
  self
end

#failure_messageObject



97
98
99
# File 'lib/moarspec/matchers/send_message.rb', line 97

def failure_message
  "expected #{description}, but sent nothing"
end

#failure_message_when_negatedObject



101
102
103
# File 'lib/moarspec/matchers/send_message.rb', line 101

def failure_message_when_negated
  "expected not #{description}, but sent it"
end

#matches?(subject) ⇒ Boolean

Matching



76
77
78
79
80
# File 'lib/moarspec/matchers/send_message.rb', line 76

def matches?(subject)
  run(subject)
  expect(@target).to expectation
  true
end

#onceObject



52
53
54
# File 'lib/moarspec/matchers/send_message.rb', line 52

def once
  exactly(1)
end

#orderedObject



64
65
66
67
# File 'lib/moarspec/matchers/send_message.rb', line 64

def ordered
  @ordered = true
  self
end

#returning(*res) ⇒ Object



21
22
23
24
# File 'lib/moarspec/matchers/send_message.rb', line 21

def returning(*res)
  @res = [*res]
  self
end

#supports_block_expectations?Boolean

Static properties



89
90
91
# File 'lib/moarspec/matchers/send_message.rb', line 89

def supports_block_expectations?
  true
end

#thriceObject



60
61
62
# File 'lib/moarspec/matchers/send_message.rb', line 60

def thrice
  exactly(3)
end

#timesObject



46
47
48
49
50
# File 'lib/moarspec/matchers/send_message.rb', line 46

def times
  fail NoMethodError unless @times || @at_least

  self
end

#twiceObject



56
57
58
# File 'lib/moarspec/matchers/send_message.rb', line 56

def twice
  exactly(2)
end

#with(*arguments) ⇒ Object

DSL



16
17
18
19
# File 'lib/moarspec/matchers/send_message.rb', line 16

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

#yielding(*args, &block) ⇒ Object



69
70
71
72
73
# File 'lib/moarspec/matchers/send_message.rb', line 69

def yielding(*args, &block)
  @yield_args = args
  @yield_block = block
  self
end