test_bench-fixture 1.3.1.1 → 1.4.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d3be2a7cebd18fa06326859f2169a44e6a8974af8c32033669bbd95aacc827b
4
- data.tar.gz: 36784decf899b9f0432da060ce1133d4e426a45830ce6adaf92c7c82e405f4d2
3
+ metadata.gz: cc001b82ac9ea1f454084cb5eae8d7d1d6a210e394da970c90ca1867aa0720da
4
+ data.tar.gz: 6e6b9d88655aac2b360a89e08325b07ea2837ec3a55acc0aa145e6700cd1d615
5
5
  SHA512:
6
- metadata.gz: a9d28986ecc5bd4c76efd955b7dcc6923289dbe8430fa849ba20e5340805dead1f0a1f3ed7813dd403041fbf3decb2bd2dcd27d72e195a3690cdf84d4abf4eed
7
- data.tar.gz: 8d52b899330892b3e021ce3c275dc51573ea6c02995c704bab40d5698da21a5e934ab42e1ea81afdeb14b213dd19e295e9061901a2d2201173050d1c6b1679be
6
+ metadata.gz: 1e9b30ca2c58bc2a113ad378111addff10e348a76115ce467479942c37a46fecad65571e6fff52d1392fbc64bb6173cf57da6e073a52e337a04af0a4df91a2a7
7
+ data.tar.gz: 51e9b333a51d131d5419bad17105e6b3cd71e660ae35823f627748a06f21a52416db220e14954d6ed7c87ef0a9cd5fab0163eee403789c16de2de802cb6ba413
@@ -62,6 +62,18 @@ module TestBench
62
62
  alias_method :session, :test_session
63
63
  alias_method :session=, :test_session=
64
64
 
65
+ def inspect
66
+ original_test_session = test_session
67
+
68
+ self.test_session = "(not inspected; class is #{original_test_session.class})"
69
+
70
+ begin
71
+ super
72
+ ensure
73
+ self.test_session = original_test_session
74
+ end
75
+ end
76
+
65
77
  def comment(text, *additional_lines)
66
78
  test_session.comment(text)
67
79
 
@@ -107,8 +119,6 @@ module TestBench
107
119
 
108
120
  detail "(No error was raised)"
109
121
 
110
- assert(false, caller_location: caller_location)
111
-
112
122
  rescue error_class => error
113
123
 
114
124
  detail "Raised error: #{error.inspect}#{" (subclass of #{error_class})" if error.class < error_class}"
@@ -124,6 +134,9 @@ module TestBench
124
134
  end
125
135
 
126
136
  assert(result, caller_location: caller_location)
137
+
138
+ else
139
+ assert(false, caller_location: caller_location)
127
140
  end
128
141
 
129
142
  def refute_raises(error_class=nil, strict: nil, caller_location: nil, &block)
@@ -168,6 +181,16 @@ module TestBench
168
181
  test_session.test(text, &block)
169
182
  end
170
183
 
184
+ def test!(text=nil, &block)
185
+ result = test(text, &block)
186
+
187
+ unless result
188
+ raise Session::Abort.new, "Context aborted"
189
+ end
190
+
191
+ result
192
+ end
193
+
171
194
  def fixture(cls, *args, **kwargs, &block)
172
195
  Fixture.(cls, *args, session: test_session, **kwargs, &block)
173
196
  end
@@ -2,22 +2,22 @@ module TestBench
2
2
  module Fixture
3
3
  class Session
4
4
  Error = Class.new(RuntimeError)
5
+ Abort = Class.new(RuntimeError)
5
6
 
6
7
  def assertion_counter
7
8
  @assertion_counter ||= 0
8
9
  end
9
10
  attr_writer :assertion_counter
10
11
 
11
- def error_counter
12
- @error_counter ||= 0
12
+ def failure_counter
13
+ @failure_counter ||= 0
13
14
  end
14
- attr_writer :error_counter
15
+ attr_writer :failure_counter
15
16
 
16
- def skip
17
- @skip ||= false
17
+ def skip_counter
18
+ @skip_counter ||= 0
18
19
  end
19
- attr_writer :skip
20
- alias_method :skip?, :skip
20
+ attr_writer :skip_counter
21
21
 
22
22
  def started
23
23
  instance_variable_defined?(:@started) ?
@@ -36,7 +36,7 @@ module TestBench
36
36
  alias_method :finished?, :finished
37
37
 
38
38
  def error_policy
39
- @error_policy ||= ErrorPolicy::Build.(:rescue_assert)
39
+ @error_policy ||= ErrorPolicy::RescueAssert.new
40
40
  end
41
41
  attr_writer :error_policy
42
42
 
@@ -105,14 +105,6 @@ module TestBench
105
105
  output.detail(text)
106
106
  end
107
107
 
108
- def error(error)
109
- fail!
110
-
111
- output.error(error)
112
-
113
- error_policy.(error)
114
- end
115
-
116
108
  def assert(value, caller_location: nil)
117
109
  caller_location ||= caller[0]
118
110
 
@@ -123,8 +115,6 @@ module TestBench
123
115
  output.assert(result, caller_location)
124
116
 
125
117
  unless result
126
- self.error_counter += 1
127
-
128
118
  assertion_failure = AssertionFailure.build(caller_location)
129
119
  raise assertion_failure
130
120
  end
@@ -137,7 +127,8 @@ module TestBench
137
127
 
138
128
  result = false
139
129
 
140
- Kernel.load(path)
130
+ source = File.read(path)
131
+ TOPLEVEL_BINDING.eval(source, path)
141
132
 
142
133
  result = true
143
134
 
@@ -148,19 +139,23 @@ module TestBench
148
139
 
149
140
  def test(title=nil, &block)
150
141
  if block.nil?
142
+ record_skip
151
143
  output.skip_test(title)
152
144
  return
153
145
  end
154
146
 
155
147
  output.start_test(title)
156
148
 
149
+ previous_failure_counter = self.failure_counter
157
150
  previous_assertion_counter = self.assertion_counter
158
151
 
159
- action = proc {
152
+ action = ->{
160
153
  block.()
161
154
 
162
- unless assertion_counter > previous_assertion_counter
163
- raise Error, "Test did not perform an assertion"
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
164
159
  end
165
160
  }
166
161
 
@@ -171,6 +166,7 @@ module TestBench
171
166
 
172
167
  def context(title=nil, &block)
173
168
  if block.nil?
169
+ record_skip
174
170
  output.skip_context(title)
175
171
  return
176
172
  end
@@ -209,18 +205,23 @@ module TestBench
209
205
  end
210
206
 
211
207
  def evaluate(action, &block)
212
- previous_error_counter = self.error_counter
208
+ previous_failure_counter = self.failure_counter
213
209
 
214
210
  begin
215
211
  action.()
216
212
 
213
+ rescue Abort
214
+
217
215
  rescue => error
218
- error(error)
216
+ record_failure
217
+
218
+ output.error(error)
219
219
 
220
+ error_policy.(error)
220
221
  error = nil
221
222
 
222
223
  ensure
223
- result = error_counter == previous_error_counter
224
+ result = failure_counter == previous_failure_counter
224
225
 
225
226
  block.(result, error) unless block.nil?
226
227
  end
@@ -228,17 +229,21 @@ module TestBench
228
229
  result
229
230
  end
230
231
 
231
- def fail!
232
- self.assertion_counter += 1
233
- self.error_counter += 1
232
+ def record_failure
233
+ self.failure_counter += 1
234
234
  end
235
+ alias_method :fail!, :record_failure
235
236
 
236
237
  def failed?
237
- error_counter.nonzero? ? true : false
238
+ failure_counter.nonzero? ? true : false
239
+ end
240
+
241
+ def record_skip
242
+ self.skip_counter += 1
238
243
  end
239
244
 
240
- def skip!
241
- self.skip = true
245
+ def skipped?
246
+ skip_counter.nonzero? ? true : false
242
247
  end
243
248
  end
244
249
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_bench-fixture
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1.1
4
+ version: 1.4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Ladd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-14 00:00:00.000000000 Z
11
+ date: 2022-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test_bench-bootstrap
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 3.1.4
74
+ rubygems_version: 3.3.4
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: Test object framework for Ruby and MRuby