test_bench-fixture 1.3.0.1 → 1.4.0.1

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: 439b3f623746bdb26d4d9e5a30ee5abd7283b829e04383c4240aa175ec4b07e7
4
- data.tar.gz: 73abed890d2945a1854c54ac338b46ec846d8ba5b8c5bdd70d2f7f1a54110680
3
+ metadata.gz: 228f02c0300bbc34a7d8adda502101e505a550acfb0a7321cdfff0be432eded4
4
+ data.tar.gz: c80feb86b41fd7ecac31452405d04514d89a8e105227331f2613804638faac44
5
5
  SHA512:
6
- metadata.gz: cd516904ef461a2fe872abdef28b9f5ced3cd8e8e68608d59f8e182a2c1a37ef27f36f365e7edbf5f7f1dea9b06a349fde016829648147c5d2f2414647a670a9
7
- data.tar.gz: 4d07e52f97d8913db429c665d1dffa709174340086cc4827ab3be365ae984198b25d3c7e64112def9c9b961190d44d1fa039f0aa1d41d58bf78d7f584b14cf94
6
+ metadata.gz: 1fd22f150206d1052906667a11d57a092994045aedc31ef77e8fcdac5ef8af4fbd5873b30cf78754fc48d70118388812b76cfd0f42ed5ea8a0ca68f29c352606
7
+ data.tar.gz: 6b1c46c55223c1ff5fcd7beb25d058a3b2167c43fa13aef953a2b4d8f06f0f1f0aaac531edb0d5367a28c13dde318628130b63f41ebcf6e4281dd199ad3dc24c
@@ -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,32 @@ module TestBench
58
62
  alias_method :session, :test_session
59
63
  alias_method :session=, :test_session=
60
64
 
61
- def comment(text)
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
+
77
+ def comment(text, *additional_lines)
62
78
  test_session.comment(text)
79
+
80
+ additional_lines.each do |text|
81
+ test_session.comment(text)
82
+ end
63
83
  end
64
84
 
65
- def detail(text)
85
+ def detail(text, *additional_lines)
66
86
  test_session.detail(text)
87
+
88
+ additional_lines.each do |text|
89
+ test_session.detail(text)
90
+ end
67
91
  end
68
92
 
69
93
  def assert(value, caller_location: nil)
@@ -95,8 +119,6 @@ module TestBench
95
119
 
96
120
  detail "(No error was raised)"
97
121
 
98
- assert(false, caller_location: caller_location)
99
-
100
122
  rescue error_class => error
101
123
 
102
124
  detail "Raised error: #{error.inspect}#{" (subclass of #{error_class})" if error.class < error_class}"
@@ -112,6 +134,9 @@ module TestBench
112
134
  end
113
135
 
114
136
  assert(result, caller_location: caller_location)
137
+
138
+ else
139
+ assert(false, caller_location: caller_location)
115
140
  end
116
141
 
117
142
  def refute_raises(error_class=nil, strict: nil, caller_location: nil, &block)
@@ -156,6 +181,16 @@ module TestBench
156
181
  test_session.test(text, &block)
157
182
  end
158
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
+
159
194
  def fixture(cls, *args, **kwargs, &block)
160
195
  Fixture.(cls, *args, session: test_session, **kwargs, &block)
161
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
@@ -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.0.1
4
+ version: 1.4.0.1
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-21 00:00:00.000000000 Z
11
+ date: 2021-09-20 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.2.22
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: Test object framework for Ruby and MRuby