| Class | BareTest::Status |
| In: |
lib/baretest/status.rb
|
| Parent: | Object |
The status of an Assertion or Suite, including failure- and skipreasons, or in case of exceptions, the exception itself and in what phase it occurred An assertion or suite has 9 possible states:
| :success: | The assertion passed. This means the block returned a trueish value. |
| :failure: | The assertion failed. This means the block returned a falsish value. Alternatively it raised an Assertion::Failure. The latter has the advantage that it can provide nicer diagnostics. |
| :pending: | No block given to the assertion to be run |
| :skipped: | If one of the parent suites is missing a dependency, its assertions will be skipped Alternatively it raised an Assertion::Skip. |
| :error: | The assertion errored out. This means the block raised an exception |
| context | [R] | The assertions execute context. |
| entity | [R] | The assertion or suite this status belongs to. Assertion or Suite. |
| exception | [R] | If an exception occured in Assertion#execute, this will contain the Exception object raised. |
| failure_reason | [R] | Detailed reason for failing. Array or nil. |
| skip_reason | [R] | Detailed reason for skipping. Array or nil. |
| status | [R] | The status identifier, see BareTest::Status. Symbol. |
| entity: | The suite or Assertion this Status belongs to |
| status: | The status identifier |
| skip_reason: | Why the Assertion or Suite failed. Array, String or nil. |
| failure_reason: | Why the Assertion or Suite was skipped. Array, String or nil. |
# File lib/baretest/status.rb, line 50
50: def initialize(entity, status, context=nil, skip_reason=nil, failure_reason=nil, exception=nil)
51: @entity = entity
52: @status = status
53: @context = context
54: @skip_reason = skip_reason
55: @failure_reason = failure_reason
56: @exception = exception
57: end
The failure/error/skipping/pending reason. Returns nil if there‘s no reason, a string otherwise Options:
| :default: | Reason to return if no reason is present |
| :separator: | String used to separate multiple reasons |
| :indent: | A String, the indentation to use. Prefixes every line. |
| :first_indent: | A String, used to indent the first line only (replaces indent). |
# File lib/baretest/status.rb, line 66
66: def reason(opt=nil)
67: if opt then
68: default, separator, indent, first_indent =
69: *opt.values_at(:default, :separator, :indent, :first_indent)
70: reason = @skip_reason || @failure_reason || default
71: return nil unless reason
72: reason = reason.kind_of?(Array) ? reason : [reason]
73: reason = reason.join(separator || "\n")
74: reason = reason.gsub(/^/, indent) if indent
75: reason = reason.gsub(/\A#{Regexp.escape(indent)}/, first_indent) if first_indent
76: reason
77: else
78: @reason.empty? ? nil : @reason.join("\n")
79: end
80: end