Module: TestBench::Fixture
- Included in:
- Controls::Fixture::BuildMethod, Controls::Fixture::Example, Controls::Fixture::NoBuildMethod, Evaluate
- Defined in:
- lib/test_bench/fixture/build.rb,
lib/test_bench/fixture/fixture.rb,
lib/test_bench/fixture/evaluate.rb,
lib/test_bench/fixture/controls/path.rb,
lib/test_bench/fixture/controls/text.rb,
lib/test_bench/fixture/controls/title.rb,
lib/test_bench/fixture/controls/output.rb,
lib/test_bench/fixture/controls/status.rb,
lib/test_bench/fixture/controls/fixture.rb,
lib/test_bench/fixture/controls/message.rb,
lib/test_bench/fixture/controls/session.rb,
lib/test_bench/fixture/controls/exception.rb,
lib/test_bench/fixture/controls/comment_style.rb
Defined Under Namespace
Modules: Build, Controls
Classes: Evaluate
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#assert(value) ⇒ Object
-
#assert_raises(exception_class = nil, message = nil, strict: nil, &block) ⇒ Object
-
#comment(heading_text = nil, text_or_fixture, style: nil, disposition: nil) ⇒ Object
-
#context(title = nil, &block) ⇒ Object
-
#context! ⇒ Object
-
#detail(heading_text = nil, text_or_fixture, style: nil, disposition: nil) ⇒ Object
-
#fixture(fixture_class, test_session: nil) ⇒ Object
-
#refute(value) ⇒ Object
-
#refute_raises(exception_class = nil, strict: nil, &block) ⇒ Object
-
#test(title = nil, &block) ⇒ Object
-
#test! ⇒ Object
Instance Attribute Details
#test_session ⇒ Object
3
4
5
|
# File 'lib/test_bench/fixture/fixture.rb', line 3
def test_session
@test_session ||= Session::Substitute.build
end
|
Class Method Details
.assure_boolean(value, message_subject) ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/test_bench/fixture/fixture.rb', line 8
def self.assure_boolean(value, message_subject)
if not value == true || value == false
raise Session::Failure, "#{message_subject} given non-boolean value: #{value.inspect}"
end
return "#{message_subject} failed"
end
|
.comment_text_and_disposition(text_or_fixture, style: nil, disposition: nil) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/test_bench/fixture/fixture.rb', line 94
def self.comment_text_and_disposition(text_or_fixture, style: nil, disposition: nil)
case text_or_fixture
in String => text
style ||= Output::CommentStyle.detect
in Fixture => fixture
style ||= Output::CommentStyle.block
test_session = fixture.test_session
text = Output::Get.(test_session)
in Object => object
style ||= Output::CommentStyle.detect
text = String.try_convert(object)
if text.nil?
raise TypeError, "no implicit conversion of #{object.class} into String"
end
end
disposition ||= Output::CommentStyle.get_disposition(style)
return text, disposition
end
|
.output(fixture) ⇒ Object
Remove when no longer in use - Nathan, Tue Jul 15 2025
121
122
123
124
125
|
# File 'lib/test_bench/fixture/fixture.rb', line 121
def self.output(fixture)
test_session = fixture.test_session
Output::Get.(test_session)
end
|
.title(title) ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/test_bench/fixture/fixture.rb', line 151
def self.title(title)
if title.nil? || title.instance_of?(String)
return title
end
title_string = String.try_convert(title)
if title_string.nil?
raise TypeError, "can't convert #{title.class} into #{String}"
end
title_string
end
|
Instance Method Details
#assert(value) ⇒ Object
16
17
18
19
20
|
# File 'lib/test_bench/fixture/fixture.rb', line 16
def assert(value)
failure_message = Fixture.assure_boolean(value, "Assertion")
test_session.assert(value, failure_message)
end
|
#assert_raises(exception_class = nil, message = nil, strict: nil, &block) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/test_bench/fixture/fixture.rb', line 30
def assert_raises(exception_class=nil, message=nil, strict: nil, &block)
if exception_class.nil?
strict = false
exception_class = StandardError
end
if strict.nil?
strict = true
end
test_session.detail "Expected exception: #{exception_class}#{' (strict)' if strict}"
if not message.nil?
test_session.detail "Expected message: #{message.inspect}"
end
block.()
rescue exception_class => exception
test_session.detail "Raised exception: #{exception.inspect}#{" (subclass of #{exception_class})" if exception.class < exception_class}"
if strict && !exception.instance_of?(exception_class)
raise
end
if not message.nil?
assert(exception.message == message)
else
assert(true)
end
else
test_session.detail "(No exception was raised)"
assert(false)
end
|
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/test_bench/fixture/fixture.rb', line 127
def (heading_text=nil, text_or_fixture, style: nil, disposition: nil)
if not heading_text.nil?
heading_style = Output::CommentStyle.heading
(heading_text, style: heading_style)
end
text, disposition = Fixture.comment_text_and_disposition(text_or_fixture, style:, disposition:)
test_session.(text, disposition)
end
|
#context(title = nil, &block) ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/test_bench/fixture/fixture.rb', line 184
def context(title=nil, &block)
title = Fixture.title(title)
if block.nil?
skip_message = title
test_session.skip(skip_message)
return nil
end
result = test_session.context(title, &block)
Session::Result.resolve(result, strict: true)
end
|
#context! ⇒ Object
198
199
200
201
202
|
# File 'lib/test_bench/fixture/fixture.rb', line 198
def context!(...)
if not context(...)
throw(Session::ExecutionBreak)
end
end
|
#detail(heading_text = nil, text_or_fixture, style: nil, disposition: nil) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/test_bench/fixture/fixture.rb', line 139
def detail(heading_text=nil, text_or_fixture, style: nil, disposition: nil)
if not heading_text.nil?
heading_style = Output::CommentStyle.heading
detail(heading_text, style: heading_style)
end
text, disposition = Fixture.comment_text_and_disposition(text_or_fixture, style:, disposition:)
test_session.detail(text, disposition)
end
|
#fixture(fixture_class, test_session: nil) ⇒ Object
204
205
206
207
208
209
210
211
212
|
# File 'lib/test_bench/fixture/fixture.rb', line 204
def fixture(fixture_class, *, test_session: nil, **, &)
test_session ||= self.test_session
fixture = Build.(fixture_class, *, test_session:, **, &)
fixture.()
fixture
end
|
#refute(value) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/test_bench/fixture/fixture.rb', line 22
def refute(value)
failure_message = Fixture.assure_boolean(value, "Refutation")
negated_value = !value
test_session.assert(negated_value, failure_message)
end
|
#refute_raises(exception_class = nil, strict: nil, &block) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/test_bench/fixture/fixture.rb', line 65
def refute_raises(exception_class=nil, strict: nil, &block)
if exception_class.nil?
strict = false
exception_class = StandardError
end
if strict.nil?
strict = true
end
test_session.detail "Prohibited exception: #{exception_class}#{' (strict)' if strict}"
block.()
rescue exception_class => exception
test_session.detail "Raised exception: #{exception.inspect}#{" (subclass of #{exception_class})" if exception.class < exception_class}"
if strict && !exception.instance_of?(exception_class)
raise
end
assert(false)
else
test_session.detail "(No exception was raised)"
assert(true)
end
|
#test(title = nil, &block) ⇒ Object
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/test_bench/fixture/fixture.rb', line 164
def test(title=nil, &block)
title = Fixture.title(title)
if block.nil?
skip_message = title
test_session.skip(skip_message)
return nil
end
result = test_session.test(title, &block)
Session::Result.resolve(result, strict: true)
end
|
#test! ⇒ Object
178
179
180
181
182
|
# File 'lib/test_bench/fixture/fixture.rb', line 178
def test!(...)
if not test(...)
throw(Session::ExecutionBreak)
end
end
|