test_bench-fixture 1.2.3.0 → 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: 92a9ac5353665c67bc88fb3c636eb9379f8a7b8f8cfd648ad9caa8d63765e12d
4
- data.tar.gz: 782ae920e5d292b2f972deaa757537a77a4f63df1e35c38a8650af31205e0bcd
3
+ metadata.gz: dd27a4edf7acf4edf1164412314db924454693e2f72f0e574bec02a58af093ae
4
+ data.tar.gz: bc3a36d8ad06b43cc579ef4f0f5b0c5f88218bc1a3d59619bf5de16a6b28f2d6
5
5
  SHA512:
6
- metadata.gz: df910d453578e8c1b156386740d48141f326b72539decc9666094056d80db2f27deeae3a380433d8ef03968e8701e0e05545d796ff7376d38bdc1c314d368e45
7
- data.tar.gz: 321c9d1b5b92e6572ac356dd518cfe481b9ae2b3f8df0b5b4197130a2123963e98aa73ce00e2e9b8d048dd9e0eaf29c172b0c398f19bcd8b2d7a4e92224ec778
6
+ metadata.gz: 582d6f3112ba646f6e0c44bd23e8a7a1edc2cd56cc0f7fe50fac7165e512be215dba275d44535042fd19fa03dfbc96d693a066802f3aab3c2e0e23a13a270a1d
7
+ data.tar.gz: 7a496e3c08dbb33f894d09609d735868c22904355fabb162a500b9cd8aa3ad566a652758e15187de9fb5fca9a0ca1ce4fda9981cecd2e25a41da8e5ebdb22cd8
@@ -36,12 +36,6 @@ module TestBench
36
36
  def self.line_number
37
37
  111
38
38
  end
39
-
40
- module Pattern
41
- def self.example
42
- /other_dir/
43
- end
44
- end
45
39
  end
46
40
 
47
41
  Implementation = self
@@ -24,7 +24,7 @@ module TestBench
24
24
  policies.fetch(policy) do
25
25
  *policies, final_policy = self.policies.keys
26
26
 
27
- policy_list = "#{policies.map(&:inspect) * ', '} or #{final_policy.inspect}"
27
+ policy_list = "#{policies.map(&:inspect).join(', ')} or #{final_policy.inspect}"
28
28
 
29
29
  raise PolicyError, "Policy #{policy.inspect} is unknown. It must be one of: #{policy_list}"
30
30
  end
@@ -37,7 +37,11 @@ module TestBench
37
37
  def self.call(cls, *args, **kwargs, &block)
38
38
  factory_method = factory_method(cls)
39
39
 
40
- last_parameter_type, _ = factory_method.parameters.last
40
+ if factory_method.name == :new
41
+ last_parameter_type, _ = cls.instance_method(:initialize).parameters.last
42
+ else
43
+ last_parameter_type, _ = factory_method.parameters.last
44
+ end
41
45
 
42
46
  if last_parameter_type == :block
43
47
  instance = build(cls, *args, **kwargs, &block)
@@ -58,12 +62,20 @@ module TestBench
58
62
  alias_method :session, :test_session
59
63
  alias_method :session=, :test_session=
60
64
 
61
- def comment(text)
65
+ def comment(text, *additional_lines)
62
66
  test_session.comment(text)
67
+
68
+ additional_lines.each do |text|
69
+ test_session.comment(text)
70
+ end
63
71
  end
64
72
 
65
- def detail(text)
73
+ def detail(text, *additional_lines)
66
74
  test_session.detail(text)
75
+
76
+ additional_lines.each do |text|
77
+ test_session.detail(text)
78
+ end
67
79
  end
68
80
 
69
81
  def assert(value, caller_location: nil)
@@ -95,8 +107,6 @@ module TestBench
95
107
 
96
108
  detail "(No error was raised)"
97
109
 
98
- assert(false, caller_location: caller_location)
99
-
100
110
  rescue error_class => error
101
111
 
102
112
  detail "Raised error: #{error.inspect}#{" (subclass of #{error_class})" if error.class < error_class}"
@@ -112,6 +122,9 @@ module TestBench
112
122
  end
113
123
 
114
124
  assert(result, caller_location: caller_location)
125
+
126
+ else
127
+ assert(false, caller_location: caller_location)
115
128
  end
116
129
 
117
130
  def refute_raises(error_class=nil, strict: nil, caller_location: nil, &block)
@@ -156,6 +169,16 @@ module TestBench
156
169
  test_session.test(text, &block)
157
170
  end
158
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
+
159
182
  def fixture(cls, *args, **kwargs, &block)
160
183
  Fixture.(cls, *args, session: test_session, **kwargs, &block)
161
184
  end
@@ -59,7 +59,7 @@ module TestBench
59
59
 
60
60
  def self.assure_level(level)
61
61
  unless level_ordinals.key?(level)
62
- raise Error, "Unknown log level #{level.inspect} (Valid levels: #{levels.map(&:inspect) * ', '})"
62
+ raise Error, "Unknown log level #{level.inspect} (Valid levels: #{levels.map(&:inspect).join(', ')})"
63
63
  end
64
64
  end
65
65
 
@@ -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
@@ -135,30 +125,36 @@ module TestBench
135
125
  def load(path)
136
126
  output.enter_file(path)
137
127
 
138
- action = proc { Kernel.load(path) }
128
+ result = false
139
129
 
140
- result = evaluate(action)
130
+ Kernel.load(path)
141
131
 
142
- output.exit_file(path, result)
132
+ result = true
143
133
 
144
- result
134
+ ensure
135
+
136
+ output.exit_file(path, result)
145
137
  end
146
138
 
147
139
  def test(title=nil, &block)
148
140
  if block.nil?
141
+ record_skip
149
142
  output.skip_test(title)
150
143
  return
151
144
  end
152
145
 
153
146
  output.start_test(title)
154
147
 
148
+ previous_failure_counter = self.failure_counter
155
149
  previous_assertion_counter = self.assertion_counter
156
150
 
157
- action = proc {
151
+ action = ->{
158
152
  block.()
159
153
 
160
- unless assertion_counter > previous_assertion_counter
161
- 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
162
158
  end
163
159
  }
164
160
 
@@ -169,6 +165,7 @@ module TestBench
169
165
 
170
166
  def context(title=nil, &block)
171
167
  if block.nil?
168
+ record_skip
172
169
  output.skip_context(title)
173
170
  return
174
171
  end
@@ -198,26 +195,32 @@ module TestBench
198
195
  output.start_fixture(fixture)
199
196
 
200
197
  action = proc { actions.each(&:call) }
201
- result = evaluate(action)
202
198
 
203
- output.finish_fixture(fixture, result)
199
+ result = evaluate(action) do |result|
200
+ output.finish_fixture(fixture, result)
201
+ end
204
202
 
205
203
  result
206
204
  end
207
205
 
208
206
  def evaluate(action, &block)
209
- previous_error_counter = self.error_counter
207
+ previous_failure_counter = self.failure_counter
210
208
 
211
209
  begin
212
210
  action.()
213
211
 
212
+ rescue Abort
213
+
214
214
  rescue => error
215
- error(error)
215
+ record_failure
216
+
217
+ output.error(error)
216
218
 
219
+ error_policy.(error)
217
220
  error = nil
218
221
 
219
222
  ensure
220
- result = error_counter == previous_error_counter
223
+ result = failure_counter == previous_failure_counter
221
224
 
222
225
  block.(result, error) unless block.nil?
223
226
  end
@@ -225,17 +228,21 @@ module TestBench
225
228
  result
226
229
  end
227
230
 
228
- def fail!
229
- self.assertion_counter += 1
230
- self.error_counter += 1
231
+ def record_failure
232
+ self.failure_counter += 1
231
233
  end
234
+ alias_method :fail!, :record_failure
232
235
 
233
236
  def failed?
234
- error_counter.nonzero? ? true : false
237
+ failure_counter.nonzero? ? true : false
238
+ end
239
+
240
+ def record_skip
241
+ self.skip_counter += 1
235
242
  end
236
243
 
237
- def skip!
238
- self.skip = true
244
+ def skipped?
245
+ skip_counter.nonzero? ? true : false
239
246
  end
240
247
  end
241
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.2.3.0
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-08-09 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,8 +71,8 @@ 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
- summary: Test object framework
77
+ summary: Test object framework for Ruby and MRuby
78
78
  test_files: []