Exception: Assay::Assertion
- Inherits:
-
Exception
- Object
- Exception
- Assay::Assertion
show all
- Defined in:
- lib/assay/assertion.rb
Constant Summary
collapse
- SIZE_LIMIT =
When displaying errors, use this as a rule of thumb for determining when the inspected object will be too big for a single line message.
13
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(message = nil, *arguments, &block) ⇒ Assertion
Returns a new instance of Assertion.
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/assay/assertion.rb', line 79
def initialize(message=nil, *arguments, &block)
message ? super(message % arguments) : super()
@arguments = arguments
@block = block
end
|
Class Method Details
.assert(*args, &blk) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/assay/assertion.rb', line 25
def self.assert(*args, &blk)
opts = Hash === args.last ? args.pop : {}
backtrace = opts[:backtrace] || caller
message = opts[:message]
err = new(message, *args, &blk)
err.set_backtrace(backtrace)
err.assert
end
|
.assertable_method ⇒ Object
20
21
22
|
# File 'lib/assay/assertion.rb', line 20
def self.assertable_method
"assert_#{assertion_name}"
end
|
.fail?(*args, &blk) ⇒ Boolean
74
75
76
|
# File 'lib/assay/assertion.rb', line 74
def self.fail?(*args, &blk)
! pass?(*args, &blk)
end
|
.pass?(*args, &blk) ⇒ Boolean
69
70
71
|
# File 'lib/assay/assertion.rb', line 69
def self.pass?(*args, &blk)
raise NotImplementedError
end
|
.refute(*args, &blk) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/assay/assertion.rb', line 47
def self.refute(*args, &blk)
opts = Hash === args.last ? args.pop : {}
backtrace = opts[:backtrace] || caller
message = opts[:message]
err = new(message, *args, &blk)
err.set_backtrace(backtrace)
err.refute
end
|
.to_matcher(*args, &blk) ⇒ Object
Returns Matcher for the failure class.
15
16
17
|
# File 'lib/assay/assertion.rb', line 15
def self.to_matcher(*args, &blk)
Matcher.new(self, *args, &blk)
end
|
Instance Method Details
#assert ⇒ Object
109
110
111
112
|
# File 'lib/assay/assertion.rb', line 109
def assert
raise self unless pass?
end
|
#assertion? ⇒ Boolean
Failure is always a type of assertion.
This method allows Assay’s classes to work in any test framework that supports this interface.
94
95
96
|
# File 'lib/assay/assertion.rb', line 94
def assertion?
true end
|
#fail? ⇒ Boolean
104
105
106
|
# File 'lib/assay/assertion.rb', line 104
def fail?
not pass?
end
|
#negative? ⇒ Boolean
121
122
123
|
# File 'lib/assay/assertion.rb', line 121
def negative?
@negative
end
|
#pass? ⇒ Boolean
99
100
101
|
# File 'lib/assay/assertion.rb', line 99
def pass?
self.class.pass?(*@arguments, &@block) end
|
#refute ⇒ Object
115
116
117
118
|
# File 'lib/assay/assertion.rb', line 115
def refute
raise self unless fail?
end
|
#set_arguments(arguments) ⇒ Object
Set arguments used to make assertion.
132
133
134
135
|
# File 'lib/assay/assertion.rb', line 132
def set_arguments(arguments)
@arguments = arguments
end
|
#set_negative(negative) ⇒ Object
Set whether this failure was the inverse of it’s normal meaning. For example, ‘!=` rather than `==`.
127
128
129
|
# File 'lib/assay/assertion.rb', line 127
def set_negative(negative)
@negative = !!negative
end
|
#to_s ⇒ Object
138
139
140
141
142
143
144
|
# File 'lib/assay/assertion.rb', line 138
def to_s
if @negative
"NOT " + super()
else
super()
end
end
|