Class: BareTest::Status
- Inherits:
-
Object
- Object
- BareTest::Status
- Defined in:
- lib/baretest/status.rb
Overview
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
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
The assertions execute context.
-
#entity ⇒ Object
readonly
The assertion or suite this status belongs to.
-
#exception ⇒ Object
readonly
If an exception occured in Assertion#execute, this will contain the Exception object raised.
-
#failure_reason ⇒ Object
readonly
Detailed reason for failing.
-
#skip_reason ⇒ Object
readonly
Detailed reason for skipping.
-
#status ⇒ Object
readonly
The status identifier, see BareTest::Status.
Instance Method Summary collapse
-
#initialize(entity, status, context = nil, skip_reason = nil, failure_reason = nil, exception = nil) ⇒ Status
constructor
- entity
- The suite or Assertion this Status belongs to status
- The status identifier skip_reason
-
Why the Assertion or Suite failed.
-
#inspect ⇒ Object
:nodoc:.
-
#reason(opt = nil) ⇒ Object
The failure/error/skipping/pending reason.
Constructor Details
#initialize(entity, status, context = nil, skip_reason = nil, failure_reason = nil, exception = nil) ⇒ Status
- 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.
50 51 52 53 54 55 56 57 |
# File 'lib/baretest/status.rb', line 50 def initialize(entity, status, context=nil, skip_reason=nil, failure_reason=nil, exception=nil) @entity = entity @status = status @context = context @skip_reason = skip_reason @failure_reason = failure_reason @exception = exception end |
Instance Attribute Details
#context ⇒ Object (readonly)
The assertions execute context.
29 30 31 |
# File 'lib/baretest/status.rb', line 29 def context @context end |
#entity ⇒ Object (readonly)
The assertion or suite this status belongs to. Assertion or Suite.
26 27 28 |
# File 'lib/baretest/status.rb', line 26 def entity @entity end |
#exception ⇒ Object (readonly)
If an exception occured in Assertion#execute, this will contain the Exception object raised.
42 43 44 |
# File 'lib/baretest/status.rb', line 42 def exception @exception end |
#failure_reason ⇒ Object (readonly)
Detailed reason for failing. Array or nil.
38 39 40 |
# File 'lib/baretest/status.rb', line 38 def failure_reason @failure_reason end |
#skip_reason ⇒ Object (readonly)
Detailed reason for skipping. Array or nil.
35 36 37 |
# File 'lib/baretest/status.rb', line 35 def skip_reason @skip_reason end |
#status ⇒ Object (readonly)
The status identifier, see BareTest::Status. Symbol.
32 33 34 |
# File 'lib/baretest/status.rb', line 32 def status @status end |
Instance Method Details
#inspect ⇒ Object
:nodoc:
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/baretest/status.rb', line 82 def inspect # :nodoc: sprintf "#<%s:0x%08x status=%p exception=%p skip_reason=%p failure_reason=%p entity=%p>", self.class, object_id>>1, @status, @exception, @skip_reason, @failure_reason, @entity end |
#reason(opt = nil) ⇒ Object
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).
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/baretest/status.rb', line 66 def reason(opt=nil) if opt then default, separator, indent, first_indent = *opt.values_at(:default, :separator, :indent, :first_indent) reason = @skip_reason || @failure_reason || default return nil unless reason reason = reason.kind_of?(Array) ? reason : [reason] reason = reason.join(separator || "\n") reason = reason.gsub(/^/, indent) if indent reason = reason.gsub(/\A#{Regexp.escape(indent)}/, first_indent) if first_indent reason else @reason.empty? ? nil : @reason.join("\n") end end |