Module: Spectre::Assertion
- Defined in:
- lib/spectre/assertion.rb
Defined Under Namespace
Classes: AndEvaluation, AssertionFailure, Evaluation, OrEvaluation
Constant Summary
collapse
- @@success =
nil
Class Method Summary
collapse
Class Method Details
.expect(desc) ⇒ Object
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
# File 'lib/spectre/assertion.rb', line 248
def expect desc
status = 'unknown'
begin
Spectre::Logging.log_process("expect #{desc}")
yield
Spectre::Logging.log_status(desc, Logging::Status::OK)
status = :ok
rescue Interrupt => e
status = :skipped
raise e
rescue AssertionFailure => e
Spectre::Logging.log_status(desc, Logging::Status::FAILED)
status = :failed
raise AssertionFailure.new(e.message, e.expected, e.actual, desc), cause: nil
rescue Exception => e
Spectre::Logging.log_status(desc, Logging::Status::ERROR)
status = :error
raise AssertionFailure.new("An unexpected error occurred during expectation: #{e.message}", nil, nil, desc), cause: e
ensure
Spectre::Runner.current.expectations.append([desc, status])
end
end
|
.fail_with(message) ⇒ Object
296
297
298
|
# File 'lib/spectre/assertion.rb', line 296
def fail_with message
raise AssertionFailure.new(message)
end
|
.observe(desc = nil) ⇒ Object
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
# File 'lib/spectre/assertion.rb', line 272
def observe desc = nil
prefix = 'observing'
prefix += " '#{desc}'" if desc
begin
Spectre::Logging.log_info(prefix) if desc
yield
@@success = true
@@logger.info("#{prefix} finished with success")
rescue Interrupt => e
raise e
rescue Exception => e
error_message = "#{prefix} finished with failure: #{e.message}"
error_message += "\n" + e.backtrace.join("\n") if @@debug
@@logger.info(error_message)
@@success = false
end
end
|
.success? ⇒ Boolean
292
293
294
|
# File 'lib/spectre/assertion.rb', line 292
def success?
@@success
end
|