Class: RLab::Assert::AssertionFailed

Inherits:
Error
  • Object
show all
Defined in:
lib/rlab/assert/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(assertion) ⇒ AssertionFailed

Returns a new instance of AssertionFailed.



8
9
10
# File 'lib/rlab/assert/errors.rb', line 8

def initialize assertion
  @assertion = assertion
end

Instance Attribute Details

#assertionObject (readonly)

Returns the value of attribute assertion.



6
7
8
# File 'lib/rlab/assert/errors.rb', line 6

def assertion
  @assertion
end

Instance Method Details

#backtraceObject



12
13
14
# File 'lib/rlab/assert/errors.rb', line 12

def backtrace
  assertion.trace.map &:to_s
end

#to_sObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/rlab/assert/errors.rb', line 16

def to_s
  failures = assertion.fails.map do |failed_check|
    failed_check.fail_message
  end
  if failures.size > 1
    "Assertion failure:\n\n    * #{failures * "\n    * "}\n"
  else
    "Assertion failure: #{failures * ", "}"
  end
end