Class: BrainzLab::Testing::Matchers::HaveBeenLoggedMatcher
- Inherits:
-
Object
- Object
- BrainzLab::Testing::Matchers::HaveBeenLoggedMatcher
- Defined in:
- lib/brainzlab/testing/matchers.rb
Overview
Matcher for logs
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize ⇒ HaveBeenLoggedMatcher
constructor
A new instance of HaveBeenLoggedMatcher.
- #matches?(level) ⇒ Boolean
- #with_data(data) ⇒ Object
- #with_message(message) ⇒ Object
Constructor Details
#initialize ⇒ HaveBeenLoggedMatcher
Returns a new instance of HaveBeenLoggedMatcher.
191 192 193 194 |
# File 'lib/brainzlab/testing/matchers.rb', line 191 def initialize @expected_message = nil @expected_data = nil end |
Instance Method Details
#description ⇒ Object
229 230 231 232 233 234 |
# File 'lib/brainzlab/testing/matchers.rb', line 229 def description desc = "have logged at level :#{@level}" desc += " with message #{@expected_message.inspect}" if @expected_message desc += " with data #{@expected_data.inspect}" if @expected_data desc end |
#failure_message ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/brainzlab/testing/matchers.rb', line 211 def actual_logs = BrainzLab::Testing.event_store.logs_at_level(@level) if actual_logs.empty? "expected a log at level :#{@level} to have been recorded, but none were found.\n" \ "Available log levels: #{BrainzLab::Testing.event_store.logs.map { |l| l[:level] }.uniq.inspect}" else msg = "expected a log at level :#{@level}" msg += " with message matching #{@expected_message.inspect}" if @expected_message msg += " with data #{@expected_data.inspect}" if @expected_data msg + ", but logged messages were:\n #{actual_logs.map { |l| { message: l[:message], data: l[:data] } }.inspect}" end end |
#failure_message_when_negated ⇒ Object
225 226 227 |
# File 'lib/brainzlab/testing/matchers.rb', line 225 def "expected no log at level :#{@level} to have been recorded, but it was" end |
#matches?(level) ⇒ Boolean
206 207 208 209 |
# File 'lib/brainzlab/testing/matchers.rb', line 206 def matches?(level) @level = level.to_sym BrainzLab::Testing.event_store.logged?(@level, @expected_message, @expected_data) end |
#with_data(data) ⇒ Object
201 202 203 204 |
# File 'lib/brainzlab/testing/matchers.rb', line 201 def with_data(data) @expected_data = data self end |
#with_message(message) ⇒ Object
196 197 198 199 |
# File 'lib/brainzlab/testing/matchers.rb', line 196 def () @expected_message = self end |