Class: RSpec::Instrumentation::Matcher::InstrumentMatcher
- Inherits:
-
Object
- Object
- RSpec::Instrumentation::Matcher::InstrumentMatcher
- Includes:
- Matchers::Composable
- Defined in:
- lib/rspec-instrumentation-matcher.rb
Instance Method Summary collapse
- #at_least(value) ⇒ Object
- #at_most(value) ⇒ Object
- #description ⇒ Object
- #failure_message(negative = false) ⇒ Object
-
#initialize(subject) ⇒ InstrumentMatcher
constructor
A new instance of InstrumentMatcher.
- #matches?(event_proc) ⇒ Boolean
- #negative_failure_message ⇒ Object (also: #failure_message_when_negated)
- #never ⇒ Object
- #once ⇒ Object
- #supports_block_expectations? ⇒ Boolean
- #times(value) ⇒ Object
- #twice ⇒ Object
- #with(expectation) ⇒ Object
Constructor Details
#initialize(subject) ⇒ InstrumentMatcher
Returns a new instance of InstrumentMatcher.
13 14 15 16 17 18 |
# File 'lib/rspec-instrumentation-matcher.rb', line 13 def initialize(subject) @subject = subject @payload = nil @received = 0 @at_least = 1 end |
Instance Method Details
#at_least(value) ⇒ Object
66 67 68 69 |
# File 'lib/rspec-instrumentation-matcher.rb', line 66 def at_least(value) @at_least = value self end |
#at_most(value) ⇒ Object
71 72 73 74 75 |
# File 'lib/rspec-instrumentation-matcher.rb', line 71 def at_most(value) @at_most = value @at_least = nil self end |
#description ⇒ Object
20 21 22 |
# File 'lib/rspec-instrumentation-matcher.rb', line 20 def description "instrument #{@subject} #{}" end |
#failure_message(negative = false) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rspec-instrumentation-matcher.rb', line 48 def (negative = false) = "Expected #{@subject} #{'not ' if negative}to be instrumented" << " at least #{count @at_least}" unless at_least? << " at most #{count @at_most}" unless at_most? << " exactly #{count @times}" unless times? if !at_least? || !at_most? || !times? << " but was instrumented #{count @received}" << ' and the payload should have been' unless with? else << ' with' unless with? end << " #{@payload_expectation.inspect} instead of #{@payload.inspect}" unless with? end |
#matches?(event_proc) ⇒ Boolean
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rspec-instrumentation-matcher.rb', line 28 def matches?(event_proc) raise_block_syntax_error if block_given? callback = lambda do |_name, _start, _finish, _id, payload| @payload = payload @received += 1 end ActiveSupport::Notifications.subscribed(callback, @subject) do event_proc.call end times? && at_least? && at_most? && with? end |
#negative_failure_message ⇒ Object Also known as: failure_message_when_negated
42 43 44 |
# File 'lib/rspec-instrumentation-matcher.rb', line 42 def (true) end |
#never ⇒ Object
85 86 87 |
# File 'lib/rspec-instrumentation-matcher.rb', line 85 def never times(0) end |
#once ⇒ Object
77 78 79 |
# File 'lib/rspec-instrumentation-matcher.rb', line 77 def once times(1) end |
#supports_block_expectations? ⇒ Boolean
24 25 26 |
# File 'lib/rspec-instrumentation-matcher.rb', line 24 def supports_block_expectations? true end |
#times(value) ⇒ Object
89 90 91 92 93 |
# File 'lib/rspec-instrumentation-matcher.rb', line 89 def times(value) @at_least = nil @times = value self end |
#twice ⇒ Object
81 82 83 |
# File 'lib/rspec-instrumentation-matcher.rb', line 81 def twice times(2) end |
#with(expectation) ⇒ Object
95 96 97 98 99 |
# File 'lib/rspec-instrumentation-matcher.rb', line 95 def with(expectation) @with = true @payload_expectation = expectation self end |