sus 0.20.1 → 0.20.3
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/sus/assertions.rb +50 -26
- data/lib/sus/expect.rb +5 -6
- data/lib/sus/raise_exception.rb +1 -1
- data/lib/sus/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a47f7f10111ec9ad45da1d73eced17433ac9cd5c3a7ccf5ab89e5b0d035b9715
|
4
|
+
data.tar.gz: 34d46a116559b3b41d991910fed083903f2074b18c5887ab0c84dc72a4a28707
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c348795bf5c272968060506cd0db933724b4210a36bad55d60088371ee70731aabd66aa6bd07a5c9df4bc9e6a9a59c094e28f7415b9175ba379486f23ccf07d8
|
7
|
+
data.tar.gz: 920a983053b676658d1aafab0fcce16b178203e69c5d949f70426ed874d00ed2026fe30da2b97e0a36b904433206c3d0bd299f6d541564d2dc9610550825fbeb
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/sus/assertions.rb
CHANGED
@@ -16,7 +16,7 @@ module Sus
|
|
16
16
|
|
17
17
|
# @parameter orientation [Boolean] Whether the assertions are positive or negative in general.
|
18
18
|
# @parameter inverted [Boolean] Whether the assertions are inverted with respect to the parent.
|
19
|
-
def initialize(identity: nil, target: nil, output: Output.buffered, inverted: false, orientation: true, isolated: false, measure: false, verbose: false)
|
19
|
+
def initialize(identity: nil, target: nil, output: Output.buffered, inverted: false, orientation: true, isolated: false, distinct: false, measure: false, verbose: false)
|
20
20
|
# In theory, the target could carry the identity of the assertion group, but it's not really necessary, so we just handle it explicitly and pass it into any nested assertions.
|
21
21
|
@identity = identity
|
22
22
|
@target = target
|
@@ -24,6 +24,7 @@ module Sus
|
|
24
24
|
@inverted = inverted
|
25
25
|
@orientation = orientation
|
26
26
|
@isolated = isolated
|
27
|
+
@distinct = distinct
|
27
28
|
@verbose = verbose
|
28
29
|
|
29
30
|
if measure
|
@@ -46,13 +47,18 @@ module Sus
|
|
46
47
|
attr :output
|
47
48
|
attr :level
|
48
49
|
|
49
|
-
# Whether this aset of assertions is inverted
|
50
|
+
# Whether this aset of assertions is inverted, i.e. the assertions are expected to fail relative to the parent. Used for grouping assertions and ensuring they are added to the parent passed/failed array correctly.
|
50
51
|
attr :inverted
|
51
52
|
|
52
|
-
# The absolute orientation of this set of assertions
|
53
|
+
# The absolute orientation of this set of assertions, i.e. whether the assertions are expected to pass or fail regardless of the parent. Used for correctly formatting the output.
|
53
54
|
attr :orientation
|
54
55
|
|
56
|
+
# Whether this set of assertions is isolated from the parent. This is used to ensure taht any deferred assertions are competed before the parent is completed. This is used by `receive` assertions which are deferred until the user code of the test has completed.
|
55
57
|
attr :isolated
|
58
|
+
|
59
|
+
# Distinct is used to identify a set of assertions as a single statement for the purpose of user feedback. It's used by top level ensure statements to ensure that error messages are captured and reported on those statements.
|
60
|
+
attr :distinct
|
61
|
+
|
56
62
|
attr :verbose
|
57
63
|
|
58
64
|
attr :clock
|
@@ -147,13 +153,15 @@ module Sus
|
|
147
153
|
end
|
148
154
|
|
149
155
|
class Assert
|
150
|
-
def initialize(identity,
|
156
|
+
def initialize(identity, backtrace, assertions)
|
151
157
|
@identity = identity
|
152
|
-
@
|
158
|
+
@backtrace = backtrace
|
159
|
+
@assertions = assertions
|
153
160
|
end
|
154
161
|
|
155
162
|
attr :identity
|
156
|
-
attr :
|
163
|
+
attr :backtrace
|
164
|
+
attr :assertions
|
157
165
|
|
158
166
|
def each_failure(&block)
|
159
167
|
yield self
|
@@ -161,7 +169,8 @@ module Sus
|
|
161
169
|
|
162
170
|
def message
|
163
171
|
{
|
164
|
-
text
|
172
|
+
# It's possible that several Assert instances might share the same output text. This is because the output is buffered for each test and each top-level test expectation.
|
173
|
+
text: @assertions.output.string,
|
165
174
|
location: @identity&.to_location
|
166
175
|
}
|
167
176
|
end
|
@@ -170,31 +179,38 @@ module Sus
|
|
170
179
|
def assert(condition, message = nil)
|
171
180
|
@count += 1
|
172
181
|
|
173
|
-
message ||= "Assertion"
|
174
|
-
backtrace = Output::Backtrace.first(@identity)
|
175
182
|
identity = @identity&.scoped
|
183
|
+
backtrace = Output::Backtrace.first(identity)
|
184
|
+
assert = Assert.new(identity, backtrace, self)
|
176
185
|
|
177
186
|
if condition
|
178
|
-
@passed <<
|
187
|
+
@passed << assert
|
179
188
|
|
180
189
|
if !@orientation || @verbose
|
181
|
-
@output.puts(:indent, *pass_prefix, message, backtrace)
|
190
|
+
@output.puts(:indent, *pass_prefix, message || "assertion passed", backtrace)
|
182
191
|
end
|
183
192
|
else
|
184
|
-
@failed <<
|
193
|
+
@failed << assert
|
185
194
|
|
186
195
|
if @orientation || @verbose
|
187
|
-
@output.puts(:indent, *fail_prefix, message, backtrace)
|
196
|
+
@output.puts(:indent, *fail_prefix, message || "assertion failed", backtrace)
|
188
197
|
end
|
189
198
|
end
|
190
199
|
end
|
191
200
|
|
201
|
+
def message
|
202
|
+
{
|
203
|
+
text: @output.string,
|
204
|
+
location: @identity&.to_location
|
205
|
+
}
|
206
|
+
end
|
207
|
+
|
192
208
|
def each_failure(&block)
|
193
209
|
return to_enum(__method__) unless block_given?
|
194
210
|
|
195
|
-
|
196
|
-
|
197
|
-
|
211
|
+
if self.failed? and @distinct
|
212
|
+
return yield(self)
|
213
|
+
end
|
198
214
|
|
199
215
|
@failed.each do |assertions|
|
200
216
|
assertions.each_failure(&block)
|
@@ -248,14 +264,14 @@ module Sus
|
|
248
264
|
|
249
265
|
def message
|
250
266
|
{
|
251
|
-
text: @error.
|
267
|
+
text: @error.full_message,
|
252
268
|
location: @identity&.to_location
|
253
269
|
}
|
254
270
|
end
|
255
271
|
end
|
256
272
|
|
257
273
|
def error!(error)
|
258
|
-
identity = @identity
|
274
|
+
identity = @identity&.scoped(error.backtrace_locations)
|
259
275
|
|
260
276
|
@errored << Error.new(identity, error)
|
261
277
|
|
@@ -270,11 +286,11 @@ module Sus
|
|
270
286
|
@output.write(Output::Backtrace.for(error, @identity))
|
271
287
|
end
|
272
288
|
|
273
|
-
def nested(target, identity:
|
289
|
+
def nested(target, identity: nil, isolated: false, distinct: false, inverted: false, **options)
|
274
290
|
result = nil
|
275
291
|
|
276
292
|
# Isolated assertions need to have buffered output so they can be replayed if they fail:
|
277
|
-
if isolated or
|
293
|
+
if isolated or distinct
|
278
294
|
output = @output.buffered
|
279
295
|
else
|
280
296
|
output = @output
|
@@ -289,7 +305,7 @@ module Sus
|
|
289
305
|
|
290
306
|
output.puts(:indent, target)
|
291
307
|
|
292
|
-
assertions = self.class.new(identity: identity, target: target, output: output, isolated: isolated, inverted: inverted, orientation: orientation, verbose: @verbose, **options)
|
308
|
+
assertions = self.class.new(identity: identity, target: target, output: output, isolated: isolated, inverted: inverted, orientation: orientation, distinct: distinct, verbose: @verbose, **options)
|
293
309
|
|
294
310
|
output.indented do
|
295
311
|
begin
|
@@ -310,15 +326,17 @@ module Sus
|
|
310
326
|
# All child assertions should be resolved by this point:
|
311
327
|
raise "Nested assertions must be fully resolved!" if assertions.deferred?
|
312
328
|
|
313
|
-
if assertions.
|
329
|
+
if assertions.append?
|
314
330
|
# If we are isolated, we merge all child assertions into the parent as a single entity:
|
315
|
-
|
331
|
+
append!(assertions)
|
316
332
|
else
|
317
333
|
# Otherwise, we append all child assertions into the parent assertions:
|
318
|
-
|
334
|
+
merge!(assertions)
|
319
335
|
end
|
320
336
|
end
|
321
337
|
|
338
|
+
protected
|
339
|
+
|
322
340
|
def resolve_into(parent)
|
323
341
|
# If the assertions should be an isolated group, make sure any deferred assertions are resolved:
|
324
342
|
if @isolated and self.deferred?
|
@@ -340,9 +358,14 @@ module Sus
|
|
340
358
|
end
|
341
359
|
end
|
342
360
|
|
361
|
+
# Whether the child assertions should be merged into the parent assertions.
|
362
|
+
def append?
|
363
|
+
@isolated || @inverted || @distinct
|
364
|
+
end
|
365
|
+
|
343
366
|
private
|
344
367
|
|
345
|
-
def
|
368
|
+
def append!(assertions)
|
346
369
|
@count += assertions.count
|
347
370
|
|
348
371
|
if assertions.errored?
|
@@ -364,7 +387,8 @@ module Sus
|
|
364
387
|
end
|
365
388
|
end
|
366
389
|
|
367
|
-
|
390
|
+
# Concatenate the child assertions into this instance.
|
391
|
+
def merge!(assertions)
|
368
392
|
@count += assertions.count
|
369
393
|
@passed.concat(assertions.passed)
|
370
394
|
@failed.concat(assertions.failed)
|
data/lib/sus/expect.rb
CHANGED
@@ -5,16 +5,15 @@
|
|
5
5
|
|
6
6
|
module Sus
|
7
7
|
class Expect
|
8
|
-
def initialize(assertions, subject, inverted: false,
|
8
|
+
def initialize(assertions, subject, inverted: false, distinct: false)
|
9
9
|
@assertions = assertions
|
10
10
|
@subject = subject
|
11
11
|
@inverted = inverted
|
12
|
-
@
|
12
|
+
@distinct = true
|
13
13
|
end
|
14
14
|
|
15
15
|
attr :subject
|
16
16
|
attr :inverted
|
17
|
-
attr :assertions
|
18
17
|
|
19
18
|
def not
|
20
19
|
self.dup.tap do |expect|
|
@@ -36,7 +35,7 @@ module Sus
|
|
36
35
|
# This gets the identity scoped to the current call stack, which ensures that any failures are logged at this point in the code.
|
37
36
|
identity = @assertions.identity&.scoped
|
38
37
|
|
39
|
-
@assertions.nested(self, inverted: @inverted,
|
38
|
+
@assertions.nested(self, inverted: @inverted, identity: identity, distinct: @distinct) do |assertions|
|
40
39
|
predicate.call(assertions, @subject)
|
41
40
|
end
|
42
41
|
|
@@ -51,9 +50,9 @@ module Sus
|
|
51
50
|
class Base
|
52
51
|
def expect(subject = nil, &block)
|
53
52
|
if block_given?
|
54
|
-
Expect.new(@__assertions__, block,
|
53
|
+
Expect.new(@__assertions__, block, distinct: true)
|
55
54
|
else
|
56
|
-
Expect.new(@__assertions__, subject,
|
55
|
+
Expect.new(@__assertions__, subject, distinct: true)
|
57
56
|
end
|
58
57
|
end
|
59
58
|
end
|
data/lib/sus/raise_exception.rb
CHANGED
data/lib/sus/version.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.20.
|
4
|
+
version: 0.20.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
160
|
- !ruby/object:Gem::Version
|
161
161
|
version: '0'
|
162
162
|
requirements: []
|
163
|
-
rubygems_version: 3.4.
|
163
|
+
rubygems_version: 3.4.7
|
164
164
|
signing_key:
|
165
165
|
specification_version: 4
|
166
166
|
summary: A fast and scalable test runner.
|
metadata.gz.sig
CHANGED
Binary file
|