Class: FTest::Assert::Assertion
- Inherits:
-
Object
- Object
- FTest::Assert::Assertion
show all
- Defined in:
- lib/ftest/assert/assertion.rb
Defined Under Namespace
Classes: Refutation, SubjectThunk
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(subject_proc, checks) ⇒ Assertion
Returns a new instance of Assertion.
8
9
10
11
12
13
14
|
# File 'lib/ftest/assert/assertion.rb', line 8
def initialize subject_proc, checks
@subject_proc = subject_proc
@checks = checks
@passes = []
@fails = []
@trace = caller_locations
end
|
Instance Attribute Details
#fails ⇒ Object
Returns the value of attribute fails.
4
5
6
|
# File 'lib/ftest/assert/assertion.rb', line 4
def fails
@fails
end
|
#passes ⇒ Object
Returns the value of attribute passes.
5
6
7
|
# File 'lib/ftest/assert/assertion.rb', line 5
def passes
@passes
end
|
#source ⇒ Object
Returns the value of attribute source.
6
7
8
|
# File 'lib/ftest/assert/assertion.rb', line 6
def source
@source
end
|
Instance Method Details
#build_checks ⇒ Object
23
24
25
26
27
28
|
# File 'lib/ftest/assert/assertion.rb', line 23
def build_checks
@checks.map do |check_name, argument|
FTest.logger.debug "Resolving check #{check_name.inspect}, arg=#{argument.inspect}"
resolve_check check_name, argument
end
end
|
#call ⇒ Object
16
17
18
19
20
21
|
# File 'lib/ftest/assert/assertion.rb', line 16
def call
perform_checks
freeze
raise to_error if failed?
subject
end
|
#failed? ⇒ Boolean
30
31
32
|
# File 'lib/ftest/assert/assertion.rb', line 30
def failed?
fails.any?
end
|
#file ⇒ Object
34
35
36
|
# File 'lib/ftest/assert/assertion.rb', line 34
def file
@trace[0].path
end
|
#freeze ⇒ Object
38
39
40
41
|
# File 'lib/ftest/assert/assertion.rb', line 38
def freeze
passes.freeze
fails.freeze
end
|
#line ⇒ Object
43
44
45
|
# File 'lib/ftest/assert/assertion.rb', line 43
def line
@trace[0].lineno
end
|
#passed? ⇒ Boolean
47
48
49
|
# File 'lib/ftest/assert/assertion.rb', line 47
def passed?
not failed?
end
|
51
52
53
54
55
56
57
|
# File 'lib/ftest/assert/assertion.rb', line 51
def perform_checks
build_checks.each do |check|
check.evaluate
ary = if check.passed? then passes else fails end
ary.push check
end
end
|
#resolve_check(check_name, argument) ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/ftest/assert/assertion.rb', line 59
def resolve_check check_name, argument
check = Checks.resolve check_name do
check_name = :include if check_name == :includes
argument = [check_name, *argument]
Checks[:predicate]
end
check.new subject_thunk, argument
end
|
#subject ⇒ Object
68
69
70
|
# File 'lib/ftest/assert/assertion.rb', line 68
def subject
subject_thunk.call
end
|
#subject_thunk ⇒ Object
72
73
74
|
# File 'lib/ftest/assert/assertion.rb', line 72
def subject_thunk
@subject_thunk ||= SubjectThunk.new @subject_proc
end
|
#to_error ⇒ Object
76
77
78
|
# File 'lib/ftest/assert/assertion.rb', line 76
def to_error
AssertionFailed.new self
end
|
#trace ⇒ Object
80
81
82
|
# File 'lib/ftest/assert/assertion.rb', line 80
def trace
Assert.filter_trace @trace
end
|