test_bench-fixture 1.3.1.1 → 1.4.0.0

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: dd27a4edf7acf4edf1164412314db924454693e2f72f0e574bec02a58af093ae
4
+ data.tar.gz: bc3a36d8ad06b43cc579ef4f0f5b0c5f88218bc1a3d59619bf5de16a6b28f2d6
5
5
  SHA512:
6
- metadata.gz: a9d28986ecc5bd4c76efd955b7dcc6923289dbe8430fa849ba20e5340805dead1f0a1f3ed7813dd403041fbf3decb2bd2dcd27d72e195a3690cdf84d4abf4eed
7
- data.tar.gz: 8d52b899330892b3e021ce3c275dc51573ea6c02995c704bab40d5698da21a5e934ab42e1ea81afdeb14b213dd19e295e9061901a2d2201173050d1c6b1679be
6
+ metadata.gz: 582d6f3112ba646f6e0c44bd23e8a7a1edc2cd56cc0f7fe50fac7165e512be215dba275d44535042fd19fa03dfbc96d693a066802f3aab3c2e0e23a13a270a1d
7
+ data.tar.gz: 7a496e3c08dbb33f894d09609d735868c22904355fabb162a500b9cd8aa3ad566a652758e15187de9fb5fca9a0ca1ce4fda9981cecd2e25a41da8e5ebdb22cd8
@@ -107,8 +107,6 @@ module TestBench
107
107
 
108
108
  detail "(No error was raised)"
109
109
 
110
- assert(false, caller_location: caller_location)
111
-
112
110
  rescue error_class => error
113
111
 
114
112
  detail "Raised error: #{error.inspect}#{" (subclass of #{error_class})" if error.class < error_class}"
@@ -124,6 +122,9 @@ module TestBench
124
122
  end
125
123
 
126
124
  assert(result, caller_location: caller_location)
125
+
126
+ else
127
+ assert(false, caller_location: caller_location)
127
128
  end
128
129
 
129
130
  def refute_raises(error_class=nil, strict: nil, caller_location: nil, &block)
@@ -168,6 +169,16 @@ module TestBench
168
169
  test_session.test(text, &block)
169
170
  end
170
171
 
172
+ def test!(text=nil, &block)
173
+ result = test(text, &block)
174
+
175
+ unless result
176
+ raise Session::Abort.new, "Context aborted"
177
+ end
178
+
179
+ result
180
+ end
181
+
171
182
  def fixture(cls, *args, **kwargs, &block)
172
183
  Fixture.(cls, *args, session: test_session, **kwargs, &block)
173
184
  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
@@ -148,19 +138,23 @@ module TestBench
148
138
 
149
139
  def test(title=nil, &block)
150
140
  if block.nil?
141
+ record_skip
151
142
  output.skip_test(title)
152
143
  return
153
144
  end
154
145
 
155
146
  output.start_test(title)
156
147
 
148
+ previous_failure_counter = self.failure_counter
157
149
  previous_assertion_counter = self.assertion_counter
158
150
 
159
- action = proc {
151
+ action = ->{
160
152
  block.()
161
153
 
162
- unless assertion_counter > previous_assertion_counter
163
- raise Error, "Test did not perform an assertion"
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
164
158
  end
165
159
  }
166
160
 
@@ -171,6 +165,7 @@ module TestBench
171
165
 
172
166
  def context(title=nil, &block)
173
167
  if block.nil?
168
+ record_skip
174
169
  output.skip_context(title)
175
170
  return
176
171
  end
@@ -209,18 +204,23 @@ module TestBench
209
204
  end
210
205
 
211
206
  def evaluate(action, &block)
212
- previous_error_counter = self.error_counter
207
+ previous_failure_counter = self.failure_counter
213
208
 
214
209
  begin
215
210
  action.()
216
211
 
212
+ rescue Abort
213
+
217
214
  rescue => error
218
- error(error)
215
+ record_failure
216
+
217
+ output.error(error)
219
218
 
219
+ error_policy.(error)
220
220
  error = nil
221
221
 
222
222
  ensure
223
- result = error_counter == previous_error_counter
223
+ result = failure_counter == previous_failure_counter
224
224
 
225
225
  block.(result, error) unless block.nil?
226
226
  end
@@ -228,17 +228,21 @@ module TestBench
228
228
  result
229
229
  end
230
230
 
231
- def fail!
232
- self.assertion_counter += 1
233
- self.error_counter += 1
231
+ def record_failure
232
+ self.failure_counter += 1
234
233
  end
234
+ alias_method :fail!, :record_failure
235
235
 
236
236
  def failed?
237
- error_counter.nonzero? ? true : false
237
+ failure_counter.nonzero? ? true : false
238
+ end
239
+
240
+ def record_skip
241
+ self.skip_counter += 1
238
242
  end
239
243
 
240
- def skip!
241
- self.skip = true
244
+ def skipped?
245
+ skip_counter.nonzero? ? true : false
242
246
  end
243
247
  end
244
248
  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.0
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: 2021-05-18 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.1.6
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: Test object framework for Ruby and MRuby