Class: Moarspec::Matchers::SendMessage
- Inherits:
-
Object
- Object
- Moarspec::Matchers::SendMessage
- Includes:
- RSpec::Matchers::Composable, RSpec::Mocks::ExampleMethods
- Defined in:
- lib/moarspec/matchers/send_message.rb
Instance Method Summary collapse
- #at_least(n) ⇒ Object
- #at_most(n) ⇒ Object
- #calling_original ⇒ Object
- #description ⇒ Object
- #does_not_match?(subject) ⇒ Boolean
- #exactly(n) ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(target, method) ⇒ SendMessage
constructor
A new instance of SendMessage.
-
#matches?(subject) ⇒ Boolean
Matching.
- #once ⇒ Object
- #ordered ⇒ Object
- #returning(*res) ⇒ Object
-
#supports_block_expectations? ⇒ Boolean
Static properties.
- #thrice ⇒ Object
- #times ⇒ Object
- #twice ⇒ Object
-
#with(*arguments) ⇒ Object
DSL.
- #yielding(*args, &block) ⇒ Object
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_original ⇒ Object
26 27 28 29 |
# File 'lib/moarspec/matchers/send_message.rb', line 26 def calling_original @call_original = true self end |
#description ⇒ Object
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_message ⇒ Object
97 98 99 |
# File 'lib/moarspec/matchers/send_message.rb', line 97 def "expected #{description}, but sent nothing" end |
#failure_message_when_negated ⇒ Object
101 102 103 |
# File 'lib/moarspec/matchers/send_message.rb', line 101 def "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 |
#once ⇒ Object
52 53 54 |
# File 'lib/moarspec/matchers/send_message.rb', line 52 def once exactly(1) end |
#ordered ⇒ Object
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 |
#thrice ⇒ Object
60 61 62 |
# File 'lib/moarspec/matchers/send_message.rb', line 60 def thrice exactly(3) end |
#times ⇒ Object
46 47 48 49 50 |
# File 'lib/moarspec/matchers/send_message.rb', line 46 def times fail NoMethodError unless @times || @at_least self end |
#twice ⇒ Object
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 |