sus 0.20.2 → 0.20.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/sus/assertions.rb +46 -21
- data/lib/sus/expect.rb +5 -6
- 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,12 +153,14 @@ module Sus
|
|
147
153
|
end
|
148
154
|
|
149
155
|
class Assert
|
150
|
-
def initialize(identity, assertions)
|
156
|
+
def initialize(identity, backtrace, assertions)
|
151
157
|
@identity = identity
|
158
|
+
@backtrace = backtrace
|
152
159
|
@assertions = assertions
|
153
160
|
end
|
154
161
|
|
155
162
|
attr :identity
|
163
|
+
attr :backtrace
|
156
164
|
attr :assertions
|
157
165
|
|
158
166
|
def each_failure(&block)
|
@@ -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,17 +179,18 @@ module Sus
|
|
170
179
|
def assert(condition, message = nil)
|
171
180
|
@count += 1
|
172
181
|
|
173
|
-
backtrace = Output::Backtrace.first(@identity)
|
174
182
|
identity = @identity&.scoped
|
183
|
+
backtrace = Output::Backtrace.first(identity)
|
184
|
+
assert = Assert.new(identity, backtrace, self)
|
175
185
|
|
176
186
|
if condition
|
177
|
-
@passed <<
|
187
|
+
@passed << assert
|
178
188
|
|
179
189
|
if !@orientation || @verbose
|
180
190
|
@output.puts(:indent, *pass_prefix, message || "assertion passed", backtrace)
|
181
191
|
end
|
182
192
|
else
|
183
|
-
@failed <<
|
193
|
+
@failed << assert
|
184
194
|
|
185
195
|
if @orientation || @verbose
|
186
196
|
@output.puts(:indent, *fail_prefix, message || "assertion failed", backtrace)
|
@@ -188,12 +198,19 @@ module Sus
|
|
188
198
|
end
|
189
199
|
end
|
190
200
|
|
201
|
+
def message
|
202
|
+
{
|
203
|
+
text: @output.string,
|
204
|
+
location: @identity&.to_location
|
205
|
+
}
|
206
|
+
end
|
207
|
+
|
191
208
|
def each_failure(&block)
|
192
209
|
return to_enum(__method__) unless block_given?
|
193
210
|
|
194
|
-
|
195
|
-
|
196
|
-
|
211
|
+
if self.failed? and @distinct
|
212
|
+
return yield(self)
|
213
|
+
end
|
197
214
|
|
198
215
|
@failed.each do |assertions|
|
199
216
|
assertions.each_failure(&block)
|
@@ -247,14 +264,14 @@ module Sus
|
|
247
264
|
|
248
265
|
def message
|
249
266
|
{
|
250
|
-
text: @error.
|
267
|
+
text: @error.full_message,
|
251
268
|
location: @identity&.to_location
|
252
269
|
}
|
253
270
|
end
|
254
271
|
end
|
255
272
|
|
256
273
|
def error!(error)
|
257
|
-
identity = @identity
|
274
|
+
identity = @identity&.scoped(error.backtrace_locations)
|
258
275
|
|
259
276
|
@errored << Error.new(identity, error)
|
260
277
|
|
@@ -269,11 +286,11 @@ module Sus
|
|
269
286
|
@output.write(Output::Backtrace.for(error, @identity))
|
270
287
|
end
|
271
288
|
|
272
|
-
def nested(target, identity:
|
289
|
+
def nested(target, identity: nil, isolated: false, distinct: false, inverted: false, **options)
|
273
290
|
result = nil
|
274
291
|
|
275
292
|
# Isolated assertions need to have buffered output so they can be replayed if they fail:
|
276
|
-
if isolated or
|
293
|
+
if isolated or distinct
|
277
294
|
output = @output.buffered
|
278
295
|
else
|
279
296
|
output = @output
|
@@ -288,7 +305,7 @@ module Sus
|
|
288
305
|
|
289
306
|
output.puts(:indent, target)
|
290
307
|
|
291
|
-
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)
|
292
309
|
|
293
310
|
output.indented do
|
294
311
|
begin
|
@@ -309,15 +326,17 @@ module Sus
|
|
309
326
|
# All child assertions should be resolved by this point:
|
310
327
|
raise "Nested assertions must be fully resolved!" if assertions.deferred?
|
311
328
|
|
312
|
-
if assertions.
|
329
|
+
if assertions.append?
|
313
330
|
# If we are isolated, we merge all child assertions into the parent as a single entity:
|
314
|
-
|
331
|
+
append!(assertions)
|
315
332
|
else
|
316
333
|
# Otherwise, we append all child assertions into the parent assertions:
|
317
|
-
|
334
|
+
merge!(assertions)
|
318
335
|
end
|
319
336
|
end
|
320
337
|
|
338
|
+
protected
|
339
|
+
|
321
340
|
def resolve_into(parent)
|
322
341
|
# If the assertions should be an isolated group, make sure any deferred assertions are resolved:
|
323
342
|
if @isolated and self.deferred?
|
@@ -339,9 +358,14 @@ module Sus
|
|
339
358
|
end
|
340
359
|
end
|
341
360
|
|
361
|
+
# Whether the child assertions should be merged into the parent assertions.
|
362
|
+
def append?
|
363
|
+
@isolated || @inverted || @distinct
|
364
|
+
end
|
365
|
+
|
342
366
|
private
|
343
367
|
|
344
|
-
def
|
368
|
+
def append!(assertions)
|
345
369
|
@count += assertions.count
|
346
370
|
|
347
371
|
if assertions.errored?
|
@@ -363,7 +387,8 @@ module Sus
|
|
363
387
|
end
|
364
388
|
end
|
365
389
|
|
366
|
-
|
390
|
+
# Concatenate the child assertions into this instance.
|
391
|
+
def merge!(assertions)
|
367
392
|
@count += assertions.count
|
368
393
|
@passed.concat(assertions.passed)
|
369
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/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
|