test_bench-fixture 1.4.0.1 → 2.1.0.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/test_bench/fixture/actuate/class.rb +95 -0
- data/lib/test_bench/fixture/actuate/object.rb +91 -0
- data/lib/test_bench/fixture/controls/exception.rb +7 -0
- data/lib/test_bench/fixture/controls/fixture/class.rb +86 -0
- data/lib/test_bench/fixture/controls/fixture/object/modules.rb +39 -0
- data/lib/test_bench/fixture/controls/fixture/object.rb +31 -0
- data/lib/test_bench/fixture/controls/fixture.rb +8 -66
- data/lib/test_bench/fixture/controls/output.rb +1 -58
- data/lib/test_bench/fixture/controls/random.rb +7 -0
- data/lib/test_bench/fixture/controls/result.rb +1 -17
- data/lib/test_bench/fixture/controls/title.rb +7 -0
- data/lib/test_bench/fixture/controls.rb +9 -9
- data/lib/test_bench/fixture/evaluate.rb +29 -0
- data/lib/test_bench/fixture/fixture.rb +117 -128
- data/lib/test_bench/fixture.rb +5 -18
- metadata +29 -22
- data/lib/test_bench/fixture/assertion_failure.rb +0 -19
- data/lib/test_bench/fixture/controls/caller_location.rb +0 -66
- data/lib/test_bench/fixture/controls/error/backtrace.rb +0 -31
- data/lib/test_bench/fixture/controls/error.rb +0 -52
- data/lib/test_bench/fixture/controls/output/log.rb +0 -45
- data/lib/test_bench/fixture/controls/test_file.rb +0 -77
- data/lib/test_bench/fixture/error_policy.rb +0 -75
- data/lib/test_bench/fixture/output/capture.rb +0 -131
- data/lib/test_bench/fixture/output/log.rb +0 -142
- data/lib/test_bench/fixture/output/multiple.rb +0 -42
- data/lib/test_bench/fixture/output/null.rb +0 -9
- data/lib/test_bench/fixture/output/substitute/scope.rb +0 -26
- data/lib/test_bench/fixture/output/substitute.rb +0 -114
- data/lib/test_bench/fixture/output.rb +0 -57
- data/lib/test_bench/fixture/session/substitute.rb +0 -127
- data/lib/test_bench/fixture/session.rb +0 -249
@@ -1,127 +0,0 @@
|
|
1
|
-
module TestBench
|
2
|
-
module Fixture
|
3
|
-
class Session
|
4
|
-
module Substitute
|
5
|
-
def self.build
|
6
|
-
Session.new
|
7
|
-
end
|
8
|
-
|
9
|
-
class Session < Session
|
10
|
-
def scope(*contexts)
|
11
|
-
scoped_output = output.scope(*contexts)
|
12
|
-
|
13
|
-
return nil if scoped_output.records.empty?
|
14
|
-
|
15
|
-
scoped_session = self.class.new
|
16
|
-
scoped_session.output = scoped_output
|
17
|
-
scoped_session
|
18
|
-
end
|
19
|
-
alias_method :[], :scope
|
20
|
-
|
21
|
-
def context?(*outer_contexts, title)
|
22
|
-
output.exit_context_recorded_once?(*outer_contexts) do |t|
|
23
|
-
t == title
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def one_test_passed?(*contexts, title)
|
28
|
-
one_test?(*contexts, title) do |_, result|
|
29
|
-
result == true
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def one_test_failed?(*contexts, title)
|
34
|
-
one_test?(*contexts, title) do |_, result|
|
35
|
-
result == false
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def one_test?(*contexts, title, &block)
|
40
|
-
test_scope = test_scope(*contexts, title)
|
41
|
-
|
42
|
-
test_scope.finish_test_recorded_once?(&block)
|
43
|
-
end
|
44
|
-
|
45
|
-
def any_test_passed?(*contexts, title)
|
46
|
-
any_test?(*contexts, title) do |_, result|
|
47
|
-
result == true
|
48
|
-
end
|
49
|
-
end
|
50
|
-
alias_method :test_passed?, :any_test_passed?
|
51
|
-
|
52
|
-
def any_test_failed?(*contexts, title)
|
53
|
-
any_test?(*contexts, title) do |_, result|
|
54
|
-
result == false
|
55
|
-
end
|
56
|
-
end
|
57
|
-
alias_method :test_failed?, :any_test_failed?
|
58
|
-
|
59
|
-
def any_test?(*contexts, title, &block)
|
60
|
-
test_scope = test_scope(*contexts, title)
|
61
|
-
|
62
|
-
test_scope.finish_test_recorded?(&block)
|
63
|
-
end
|
64
|
-
alias_method :test?, :any_test?
|
65
|
-
|
66
|
-
def commented?(*contexts, text)
|
67
|
-
output.comment_recorded?(*contexts) do |t|
|
68
|
-
t == text
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def detail?(*contexts, text)
|
73
|
-
output.detail_recorded?(*contexts) do |t|
|
74
|
-
t == text
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def asserted?(*contexts, result: nil, caller_location: nil)
|
79
|
-
output.assert_recorded?(*contexts) do |r, cl|
|
80
|
-
result_match = result.nil? || r == result
|
81
|
-
caller_location_match = caller_location.nil? || cl == caller_location
|
82
|
-
|
83
|
-
result_match && caller_location_match
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def load(path)
|
88
|
-
output.enter_file(path)
|
89
|
-
|
90
|
-
inert_action = proc { }
|
91
|
-
result = evaluate(inert_action)
|
92
|
-
|
93
|
-
output.exit_file(path, result)
|
94
|
-
|
95
|
-
result
|
96
|
-
end
|
97
|
-
|
98
|
-
def loaded?(path=nil)
|
99
|
-
output.enter_file_recorded? do |p|
|
100
|
-
path.nil? || p == path
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def fixture?(fixture)
|
105
|
-
output.finish_fixture_recorded? do |f|
|
106
|
-
f == fixture
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_scope(*contexts, title)
|
111
|
-
context_scope = output.scope(*contexts)
|
112
|
-
|
113
|
-
titled_test_scope = context_scope.scope do |signal, t|
|
114
|
-
signal == :finish_test && t == title
|
115
|
-
end
|
116
|
-
|
117
|
-
untitled_test_scope = context_scope.scope(title) do |signal, t|
|
118
|
-
signal == :finish_test && t.nil?
|
119
|
-
end
|
120
|
-
|
121
|
-
titled_test_scope + untitled_test_scope
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -1,249 +0,0 @@
|
|
1
|
-
module TestBench
|
2
|
-
module Fixture
|
3
|
-
class Session
|
4
|
-
Error = Class.new(RuntimeError)
|
5
|
-
Abort = Class.new(RuntimeError)
|
6
|
-
|
7
|
-
def assertion_counter
|
8
|
-
@assertion_counter ||= 0
|
9
|
-
end
|
10
|
-
attr_writer :assertion_counter
|
11
|
-
|
12
|
-
def failure_counter
|
13
|
-
@failure_counter ||= 0
|
14
|
-
end
|
15
|
-
attr_writer :failure_counter
|
16
|
-
|
17
|
-
def skip_counter
|
18
|
-
@skip_counter ||= 0
|
19
|
-
end
|
20
|
-
attr_writer :skip_counter
|
21
|
-
|
22
|
-
def started
|
23
|
-
instance_variable_defined?(:@started) ?
|
24
|
-
@started :
|
25
|
-
@started = false
|
26
|
-
end
|
27
|
-
attr_writer :started
|
28
|
-
alias_method :started?, :started
|
29
|
-
|
30
|
-
def finished
|
31
|
-
instance_variable_defined?(:@finished) ?
|
32
|
-
@finished :
|
33
|
-
@finished = false
|
34
|
-
end
|
35
|
-
attr_writer :finished
|
36
|
-
alias_method :finished?, :finished
|
37
|
-
|
38
|
-
def error_policy
|
39
|
-
@error_policy ||= ErrorPolicy::RescueAssert.new
|
40
|
-
end
|
41
|
-
attr_writer :error_policy
|
42
|
-
|
43
|
-
def output
|
44
|
-
@output ||= Output::Substitute.build
|
45
|
-
end
|
46
|
-
attr_writer :output
|
47
|
-
|
48
|
-
def self.build(output: nil, error_policy: nil)
|
49
|
-
instance = new
|
50
|
-
|
51
|
-
if output.nil?
|
52
|
-
Output::Log.configure(instance)
|
53
|
-
else
|
54
|
-
instance.output = output
|
55
|
-
end
|
56
|
-
|
57
|
-
ErrorPolicy.configure(instance, policy: error_policy)
|
58
|
-
|
59
|
-
instance
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.configure(receiver, session: nil, output: nil, error_policy: nil, attr_name: nil)
|
63
|
-
attr_name ||= :session
|
64
|
-
|
65
|
-
if session.nil?
|
66
|
-
instance = build(output: output, error_policy: error_policy)
|
67
|
-
else
|
68
|
-
instance = session
|
69
|
-
end
|
70
|
-
|
71
|
-
receiver.public_send(:"#{attr_name}=", instance)
|
72
|
-
|
73
|
-
instance
|
74
|
-
end
|
75
|
-
|
76
|
-
def start
|
77
|
-
if started
|
78
|
-
raise Error, "Session has already been started"
|
79
|
-
end
|
80
|
-
|
81
|
-
self.started = true
|
82
|
-
|
83
|
-
output.start
|
84
|
-
end
|
85
|
-
|
86
|
-
def finish
|
87
|
-
if finished
|
88
|
-
raise Error, "Session has already finished"
|
89
|
-
end
|
90
|
-
|
91
|
-
self.finished = true
|
92
|
-
|
93
|
-
result = !failed?
|
94
|
-
|
95
|
-
output.finish(result)
|
96
|
-
|
97
|
-
result
|
98
|
-
end
|
99
|
-
|
100
|
-
def comment(text)
|
101
|
-
output.comment(text)
|
102
|
-
end
|
103
|
-
|
104
|
-
def detail(text)
|
105
|
-
output.detail(text)
|
106
|
-
end
|
107
|
-
|
108
|
-
def assert(value, caller_location: nil)
|
109
|
-
caller_location ||= caller[0]
|
110
|
-
|
111
|
-
result = value ? true : false
|
112
|
-
|
113
|
-
self.assertion_counter += 1
|
114
|
-
|
115
|
-
output.assert(result, caller_location)
|
116
|
-
|
117
|
-
unless result
|
118
|
-
assertion_failure = AssertionFailure.build(caller_location)
|
119
|
-
raise assertion_failure
|
120
|
-
end
|
121
|
-
|
122
|
-
result
|
123
|
-
end
|
124
|
-
|
125
|
-
def load(path)
|
126
|
-
output.enter_file(path)
|
127
|
-
|
128
|
-
result = false
|
129
|
-
|
130
|
-
Kernel.load(path)
|
131
|
-
|
132
|
-
result = true
|
133
|
-
|
134
|
-
ensure
|
135
|
-
|
136
|
-
output.exit_file(path, result)
|
137
|
-
end
|
138
|
-
|
139
|
-
def test(title=nil, &block)
|
140
|
-
if block.nil?
|
141
|
-
record_skip
|
142
|
-
output.skip_test(title)
|
143
|
-
return
|
144
|
-
end
|
145
|
-
|
146
|
-
output.start_test(title)
|
147
|
-
|
148
|
-
previous_failure_counter = self.failure_counter
|
149
|
-
previous_assertion_counter = self.assertion_counter
|
150
|
-
|
151
|
-
action = ->{
|
152
|
-
block.()
|
153
|
-
|
154
|
-
if failure_counter == previous_failure_counter
|
155
|
-
if assertion_counter == previous_assertion_counter
|
156
|
-
raise Error, "Test did not perform an assertion"
|
157
|
-
end
|
158
|
-
end
|
159
|
-
}
|
160
|
-
|
161
|
-
evaluate(action) do |result|
|
162
|
-
output.finish_test(title, result)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def context(title=nil, &block)
|
167
|
-
if block.nil?
|
168
|
-
record_skip
|
169
|
-
output.skip_context(title)
|
170
|
-
return
|
171
|
-
end
|
172
|
-
|
173
|
-
output.enter_context(title)
|
174
|
-
|
175
|
-
evaluate(block) do |result|
|
176
|
-
output.exit_context(title, result)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
def fixture(fixture, &block)
|
181
|
-
if block.nil? && !fixture.respond_to?(:call)
|
182
|
-
raise Error, "Block must be given when a fixture does not respond to #call"
|
183
|
-
end
|
184
|
-
|
185
|
-
actions = []
|
186
|
-
|
187
|
-
if fixture.respond_to?(:call)
|
188
|
-
actions << fixture
|
189
|
-
end
|
190
|
-
|
191
|
-
unless block.nil?
|
192
|
-
actions << proc { block.(fixture) }
|
193
|
-
end
|
194
|
-
|
195
|
-
output.start_fixture(fixture)
|
196
|
-
|
197
|
-
action = proc { actions.each(&:call) }
|
198
|
-
|
199
|
-
result = evaluate(action) do |result|
|
200
|
-
output.finish_fixture(fixture, result)
|
201
|
-
end
|
202
|
-
|
203
|
-
result
|
204
|
-
end
|
205
|
-
|
206
|
-
def evaluate(action, &block)
|
207
|
-
previous_failure_counter = self.failure_counter
|
208
|
-
|
209
|
-
begin
|
210
|
-
action.()
|
211
|
-
|
212
|
-
rescue Abort
|
213
|
-
|
214
|
-
rescue => error
|
215
|
-
record_failure
|
216
|
-
|
217
|
-
output.error(error)
|
218
|
-
|
219
|
-
error_policy.(error)
|
220
|
-
error = nil
|
221
|
-
|
222
|
-
ensure
|
223
|
-
result = failure_counter == previous_failure_counter
|
224
|
-
|
225
|
-
block.(result, error) unless block.nil?
|
226
|
-
end
|
227
|
-
|
228
|
-
result
|
229
|
-
end
|
230
|
-
|
231
|
-
def record_failure
|
232
|
-
self.failure_counter += 1
|
233
|
-
end
|
234
|
-
alias_method :fail!, :record_failure
|
235
|
-
|
236
|
-
def failed?
|
237
|
-
failure_counter.nonzero? ? true : false
|
238
|
-
end
|
239
|
-
|
240
|
-
def record_skip
|
241
|
-
self.skip_counter += 1
|
242
|
-
end
|
243
|
-
|
244
|
-
def skipped?
|
245
|
-
skip_counter.nonzero? ? true : false
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|