Class: BrainzLab::Testing::Matchers::HaveBeenCapturedMatcher
- Inherits:
-
Object
- Object
- BrainzLab::Testing::Matchers::HaveBeenCapturedMatcher
- Defined in:
- lib/brainzlab/testing/matchers.rb
Overview
Matcher for errors
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize ⇒ HaveBeenCapturedMatcher
constructor
A new instance of HaveBeenCapturedMatcher.
- #matches?(error_class) ⇒ Boolean
- #with_context(context) ⇒ Object
- #with_message(message) ⇒ Object
Constructor Details
#initialize ⇒ HaveBeenCapturedMatcher
Returns a new instance of HaveBeenCapturedMatcher.
140 141 142 143 |
# File 'lib/brainzlab/testing/matchers.rb', line 140 def initialize @expected_message = nil @expected_context = nil end |
Instance Method Details
#description ⇒ Object
181 182 183 184 185 186 |
# File 'lib/brainzlab/testing/matchers.rb', line 181 def description desc = "have captured error #{@error_class}" desc += " with message #{@expected_message.inspect}" if @expected_message desc += " with context #{@expected_context.inspect}" if @expected_context desc end |
#failure_message ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/brainzlab/testing/matchers.rb', line 164 def actual_errors = BrainzLab::Testing.event_store.errors if actual_errors.empty? "expected error #{@error_class} to have been captured, but no errors were captured" else msg = "expected error #{@error_class} to have been captured" msg += " with message matching #{@expected_message.inspect}" if @expected_message msg += " with context #{@expected_context.inspect}" if @expected_context msg + ", but captured errors were:\n #{actual_errors.map { |e| { class: e[:error_class], message: e[:message] } }.inspect}" end end |
#failure_message_when_negated ⇒ Object
177 178 179 |
# File 'lib/brainzlab/testing/matchers.rb', line 177 def "expected error #{@error_class} not to have been captured, but it was" end |
#matches?(error_class) ⇒ Boolean
155 156 157 158 159 160 161 162 |
# File 'lib/brainzlab/testing/matchers.rb', line 155 def matches?(error_class) @error_class = error_class BrainzLab::Testing.event_store.error_captured?( @error_class, message: @expected_message, context: @expected_context ) end |
#with_context(context) ⇒ Object
150 151 152 153 |
# File 'lib/brainzlab/testing/matchers.rb', line 150 def with_context(context) @expected_context = context self end |
#with_message(message) ⇒ Object
145 146 147 148 |
# File 'lib/brainzlab/testing/matchers.rb', line 145 def () @expected_message = self end |