test_bench-fixture 1.4.0.2 → 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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/lib/test_bench/fixture/actuate/class.rb +95 -0
  3. data/lib/test_bench/fixture/actuate/object.rb +91 -0
  4. data/lib/test_bench/fixture/controls/exception.rb +7 -0
  5. data/lib/test_bench/fixture/controls/fixture/class.rb +86 -0
  6. data/lib/test_bench/fixture/controls/fixture/object/modules.rb +39 -0
  7. data/lib/test_bench/fixture/controls/fixture/object.rb +31 -0
  8. data/lib/test_bench/fixture/controls/fixture.rb +8 -66
  9. data/lib/test_bench/fixture/controls/output.rb +1 -58
  10. data/lib/test_bench/fixture/controls/random.rb +7 -0
  11. data/lib/test_bench/fixture/controls/result.rb +1 -17
  12. data/lib/test_bench/fixture/controls/title.rb +7 -0
  13. data/lib/test_bench/fixture/controls.rb +9 -9
  14. data/lib/test_bench/fixture/evaluate.rb +29 -0
  15. data/lib/test_bench/fixture/fixture.rb +117 -128
  16. data/lib/test_bench/fixture.rb +5 -18
  17. metadata +29 -22
  18. data/lib/test_bench/fixture/assertion_failure.rb +0 -19
  19. data/lib/test_bench/fixture/controls/caller_location.rb +0 -66
  20. data/lib/test_bench/fixture/controls/error/backtrace.rb +0 -31
  21. data/lib/test_bench/fixture/controls/error.rb +0 -52
  22. data/lib/test_bench/fixture/controls/output/log.rb +0 -45
  23. data/lib/test_bench/fixture/controls/test_file.rb +0 -77
  24. data/lib/test_bench/fixture/error_policy.rb +0 -75
  25. data/lib/test_bench/fixture/output/capture.rb +0 -131
  26. data/lib/test_bench/fixture/output/log.rb +0 -142
  27. data/lib/test_bench/fixture/output/multiple.rb +0 -42
  28. data/lib/test_bench/fixture/output/null.rb +0 -9
  29. data/lib/test_bench/fixture/output/substitute/scope.rb +0 -26
  30. data/lib/test_bench/fixture/output/substitute.rb +0 -114
  31. data/lib/test_bench/fixture/output.rb +0 -57
  32. data/lib/test_bench/fixture/session/substitute.rb +0 -127
  33. data/lib/test_bench/fixture/session.rb +0 -250
@@ -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,250 +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
- source = File.read(path)
131
- TOPLEVEL_BINDING.eval(source, path)
132
-
133
- result = true
134
-
135
- ensure
136
-
137
- output.exit_file(path, result)
138
- end
139
-
140
- def test(title=nil, &block)
141
- if block.nil?
142
- record_skip
143
- output.skip_test(title)
144
- return
145
- end
146
-
147
- output.start_test(title)
148
-
149
- previous_failure_counter = self.failure_counter
150
- previous_assertion_counter = self.assertion_counter
151
-
152
- action = ->{
153
- block.()
154
-
155
- if failure_counter == previous_failure_counter
156
- if assertion_counter == previous_assertion_counter
157
- raise Error, "Test did not perform an assertion"
158
- end
159
- end
160
- }
161
-
162
- evaluate(action) do |result|
163
- output.finish_test(title, result)
164
- end
165
- end
166
-
167
- def context(title=nil, &block)
168
- if block.nil?
169
- record_skip
170
- output.skip_context(title)
171
- return
172
- end
173
-
174
- output.enter_context(title)
175
-
176
- evaluate(block) do |result|
177
- output.exit_context(title, result)
178
- end
179
- end
180
-
181
- def fixture(fixture, &block)
182
- if block.nil? && !fixture.respond_to?(:call)
183
- raise Error, "Block must be given when a fixture does not respond to #call"
184
- end
185
-
186
- actions = []
187
-
188
- if fixture.respond_to?(:call)
189
- actions << fixture
190
- end
191
-
192
- unless block.nil?
193
- actions << proc { block.(fixture) }
194
- end
195
-
196
- output.start_fixture(fixture)
197
-
198
- action = proc { actions.each(&:call) }
199
-
200
- result = evaluate(action) do |result|
201
- output.finish_fixture(fixture, result)
202
- end
203
-
204
- result
205
- end
206
-
207
- def evaluate(action, &block)
208
- previous_failure_counter = self.failure_counter
209
-
210
- begin
211
- action.()
212
-
213
- rescue Abort
214
-
215
- rescue => error
216
- record_failure
217
-
218
- output.error(error)
219
-
220
- error_policy.(error)
221
- error = nil
222
-
223
- ensure
224
- result = failure_counter == previous_failure_counter
225
-
226
- block.(result, error) unless block.nil?
227
- end
228
-
229
- result
230
- end
231
-
232
- def record_failure
233
- self.failure_counter += 1
234
- end
235
- alias_method :fail!, :record_failure
236
-
237
- def failed?
238
- failure_counter.nonzero? ? true : false
239
- end
240
-
241
- def record_skip
242
- self.skip_counter += 1
243
- end
244
-
245
- def skipped?
246
- skip_counter.nonzero? ? true : false
247
- end
248
- end
249
- end
250
- end