Class: RLab::Assert::Check
- Inherits:
-
Object
- Object
- RLab::Assert::Check
- Defined in:
- lib/rlab/assert/check.rb
Instance Attribute Summary collapse
-
#argument ⇒ Object
readonly
Returns the value of attribute argument.
Instance Method Summary collapse
- #evaluate ⇒ Object
- #expect_error ⇒ Object
- #fail(message) ⇒ Object
- #fail_message ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(subject_thunk, argument) ⇒ Check
constructor
A new instance of Check.
- #negate ⇒ Object
- #negated? ⇒ Boolean
- #passed? ⇒ Boolean
- #subject ⇒ Object
Constructor Details
#initialize(subject_thunk, argument) ⇒ Check
Returns a new instance of Check.
8 9 10 11 |
# File 'lib/rlab/assert/check.rb', line 8 def initialize subject_thunk, argument @argument = argument @subject_thunk = subject_thunk end |
Instance Attribute Details
#argument ⇒ Object (readonly)
Returns the value of attribute argument.
6 7 8 |
# File 'lib/rlab/assert/check.rb', line 6 def argument @argument end |
Instance Method Details
#evaluate ⇒ Object
13 14 15 16 |
# File 'lib/rlab/assert/check.rb', line 13 def evaluate self.class.block.call self, @argument freeze end |
#expect_error ⇒ Object
18 19 20 |
# File 'lib/rlab/assert/check.rb', line 18 def expect_error @subject_thunk.expect_error end |
#fail(message) ⇒ Object
22 23 24 25 |
# File 'lib/rlab/assert/check.rb', line 22 def fail passed = negated? ^ yield @fail_message = unless passed end |
#fail_message ⇒ Object
27 28 29 |
# File 'lib/rlab/assert/check.rb', line 27 def "expected #{Assert.inspect subject} to#{" not" if negated?} #{@fail_message}" end |
#failed? ⇒ Boolean
31 32 33 |
# File 'lib/rlab/assert/check.rb', line 31 def failed? @fail_message ? true : false end |
#negate ⇒ Object
39 40 41 |
# File 'lib/rlab/assert/check.rb', line 39 def negate @negated = !@negated end |
#negated? ⇒ Boolean
35 36 37 |
# File 'lib/rlab/assert/check.rb', line 35 def negated? @negated ? true : false end |
#passed? ⇒ Boolean
43 44 45 |
# File 'lib/rlab/assert/check.rb', line 43 def passed? not failed? end |
#subject ⇒ Object
47 48 49 |
# File 'lib/rlab/assert/check.rb', line 47 def subject @expected_error or @subject_thunk.call end |