Class: Fare::FareMatcher::Expectation
- Inherits:
-
Object
- Object
- Fare::FareMatcher::Expectation
- Defined in:
- lib/fare/rspec.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #does_not_match?(expect_block) ⇒ Boolean
- #event ⇒ Object
- #event_name ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(subject, action, payload) ⇒ Expectation
constructor
A new instance of Expectation.
- #matches?(expect_block) ⇒ Boolean
- #payload_matcher ⇒ Object
- #payload_matches? ⇒ Boolean
- #supports_block_expectations? ⇒ Boolean
Constructor Details
#initialize(subject, action, payload) ⇒ Expectation
Returns a new instance of Expectation.
18 19 20 21 22 |
# File 'lib/fare/rspec.rb', line 18 def initialize(subject, action, payload) @subject = subject @action = action @payload = payload end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
16 17 18 |
# File 'lib/fare/rspec.rb', line 16 def action @action end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
16 17 18 |
# File 'lib/fare/rspec.rb', line 16 def payload @payload end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
16 17 18 |
# File 'lib/fare/rspec.rb', line 16 def subject @subject end |
Instance Method Details
#does_not_match?(expect_block) ⇒ Boolean
34 35 36 37 38 39 |
# File 'lib/fare/rspec.rb', line 34 def does_not_match?(expect_block) raise ArgumentError, "Checking payload with negative expectation is not possible" if payload Fare..clear expect_block.call event.nil? end |
#event ⇒ Object
69 70 71 |
# File 'lib/fare/rspec.rb', line 69 def event Fare..get(subject, action) end |
#event_name ⇒ Object
57 58 59 |
# File 'lib/fare/rspec.rb', line 57 def event_name "#{subject}##{action}" end |
#failure_message ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/fare/rspec.rb', line 41 def if event.nil? if Fare..size == 0 "There were no events published" else "Expected event #{event_name}, but got:\n#{Fare.stubbed_messages.list}" end else "Payload did not match: #{payload_matcher.last_error}\nActual payload was:\n#{event.payload}" end end |
#failure_message_when_negated ⇒ Object
53 54 55 |
# File 'lib/fare/rspec.rb', line 53 def "Expected not to publish #{event_name}, but published it with payload: #{event.payload}" end |
#matches?(expect_block) ⇒ Boolean
28 29 30 31 32 |
# File 'lib/fare/rspec.rb', line 28 def matches?(expect_block) Fare..clear expect_block.call !event.nil? && payload_matches? end |
#payload_matcher ⇒ Object
73 74 75 |
# File 'lib/fare/rspec.rb', line 73 def payload_matcher @payload_matcher ||= JsonExpressions::Matcher.new(payload) end |
#payload_matches? ⇒ Boolean
61 62 63 64 65 66 67 |
# File 'lib/fare/rspec.rb', line 61 def payload_matches? if payload payload_matcher =~ event.payload else true end end |
#supports_block_expectations? ⇒ Boolean
24 25 26 |
# File 'lib/fare/rspec.rb', line 24 def supports_block_expectations? true end |