sus 0.10.3 → 0.11.1
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/be.rb +6 -0
- data/lib/sus/clock.rb +6 -0
- data/lib/sus/expect.rb +4 -0
- data/lib/sus/have.rb +103 -0
- data/lib/sus/it.rb +7 -2
- data/lib/sus/output/backtrace.rb +3 -1
- data/lib/sus/raise_exception.rb +15 -3
- data/lib/sus/version.rb +1 -1
- data/lib/sus.rb +1 -0
- data.tar.gz.sig +0 -0
- metadata +3 -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: 4e158f43458d5d3c2bc5835ab0493b22d4c09c8f2c733cb8e42095ed5b7566a0
|
4
|
+
data.tar.gz: 4ef00aa6fe64b16271a8d219ee8f20bab23064ab5546e64885f040bf9cc5a180
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88ec5c608a1e0131702bb1c2a530b0811072a9e47df858f46635dc94fade1855cad48e6005514329de5994a2c30882cb97a8b62b73787fad9bd30ec596d24937
|
7
|
+
data.tar.gz: 1e7551d9b5007a6158bd0b690743b1ab0c448fe0ed507692f0ba14fa1697ba61b49af781ce1b70a24a2c839f72ddfcc5a7de7bd46158f723a97044c1c1a0e6f5
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/sus/be.rb
CHANGED
data/lib/sus/clock.rb
CHANGED
@@ -7,6 +7,10 @@ module Sus
|
|
7
7
|
class Clock
|
8
8
|
include Comparable
|
9
9
|
|
10
|
+
def self.start!
|
11
|
+
self.new.tap(&:start!)
|
12
|
+
end
|
13
|
+
|
10
14
|
def initialize(duration = 0.0)
|
11
15
|
@duration = duration
|
12
16
|
end
|
@@ -40,6 +44,8 @@ module Sus
|
|
40
44
|
@duration += Process.clock_gettime(Process::CLOCK_MONOTONIC) - @start_time
|
41
45
|
@start_time = nil
|
42
46
|
end
|
47
|
+
|
48
|
+
return @duration
|
43
49
|
end
|
44
50
|
end
|
45
51
|
end
|
data/lib/sus/expect.rb
CHANGED
data/lib/sus/have.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2022, by Samuel Williams.
|
5
|
+
|
6
|
+
module Sus
|
7
|
+
module Have
|
8
|
+
class Composite
|
9
|
+
def initialize(predicates)
|
10
|
+
@predicates = predicates
|
11
|
+
end
|
12
|
+
|
13
|
+
def print(output)
|
14
|
+
first = true
|
15
|
+
output.write("have {")
|
16
|
+
@predicates.each do |predicate|
|
17
|
+
if first
|
18
|
+
first = false
|
19
|
+
else
|
20
|
+
output.write(", ")
|
21
|
+
end
|
22
|
+
|
23
|
+
output.write(predicate)
|
24
|
+
end
|
25
|
+
output.write("}")
|
26
|
+
end
|
27
|
+
|
28
|
+
def call(assertions, subject)
|
29
|
+
assertions.nested(self) do |assertions|
|
30
|
+
@predicates.each do |predicate|
|
31
|
+
predicate.call(assertions, subject)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Key
|
38
|
+
def initialize(name, predicate = nil)
|
39
|
+
@name = name
|
40
|
+
@predicate = predicate
|
41
|
+
end
|
42
|
+
|
43
|
+
def print(output)
|
44
|
+
output.write("key ", :variable, @name.inspect, :reset, " ", @predicate, :reset)
|
45
|
+
end
|
46
|
+
|
47
|
+
def call(assertions, subject)
|
48
|
+
assertions.nested(self) do |assertions|
|
49
|
+
assertions.assert(subject.key?(@name), "has key")
|
50
|
+
@predicate&.call(assertions, subject[@name])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Attribute
|
56
|
+
def initialize(name, predicate)
|
57
|
+
@name = name
|
58
|
+
@predicate = predicate
|
59
|
+
end
|
60
|
+
|
61
|
+
def print(output)
|
62
|
+
output.write("attribute ", :variable, @name.to_s, :reset, " ", @predicate, :reset)
|
63
|
+
end
|
64
|
+
|
65
|
+
def call(assertions, subject)
|
66
|
+
assertions.nested(self) do |assertions|
|
67
|
+
assertions.assert(subject.respond_to?(@name), "has attribute")
|
68
|
+
@predicate&.call(assertions, subject.send(@name))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class Base
|
75
|
+
def have(*predicates)
|
76
|
+
Have::Composite.new(predicates)
|
77
|
+
end
|
78
|
+
|
79
|
+
def have_keys(*keys)
|
80
|
+
predicates = []
|
81
|
+
|
82
|
+
keys.each do |key|
|
83
|
+
if key.is_a?(Hash)
|
84
|
+
key.each do |key, predicate|
|
85
|
+
predicates << Have::Key.new(key, predicate)
|
86
|
+
end
|
87
|
+
else
|
88
|
+
predicates << Have::Key.new(key)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
Have::Composite.new(predicates)
|
93
|
+
end
|
94
|
+
|
95
|
+
def have_attributes(**attributes)
|
96
|
+
predicates = attributes.map do |key, value|
|
97
|
+
Have::Attribute.new(key, value)
|
98
|
+
end
|
99
|
+
|
100
|
+
Have::Composite.new(predicates)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/sus/it.rb
CHANGED
@@ -7,7 +7,7 @@ require_relative 'context'
|
|
7
7
|
|
8
8
|
module Sus
|
9
9
|
module It
|
10
|
-
def self.build(parent, description, &block)
|
10
|
+
def self.build(parent, description = nil, &block)
|
11
11
|
base = Class.new(parent)
|
12
12
|
base.extend(It)
|
13
13
|
base.description = description
|
@@ -26,7 +26,12 @@ module Sus
|
|
26
26
|
|
27
27
|
def print(output)
|
28
28
|
self.superclass.print(output)
|
29
|
-
|
29
|
+
|
30
|
+
if description = self.description
|
31
|
+
output.write(" it ", :it, description, :reset, " ", :identity, self.identity.to_s, :reset)
|
32
|
+
else
|
33
|
+
output.write(" and ", :identity, self.identity.to_s, :reset)
|
34
|
+
end
|
30
35
|
end
|
31
36
|
|
32
37
|
def call(assertions)
|
data/lib/sus/output/backtrace.rb
CHANGED
@@ -13,7 +13,9 @@ module Sus
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.for(exception, identity = nil)
|
16
|
-
|
16
|
+
# I've disabled the root filter here, because partial backtraces are not very useful.
|
17
|
+
# We might want to do something to improve presentation of the backtrace based on the root instead.
|
18
|
+
self.new(exception.backtrace_locations) # , identity&.path)
|
17
19
|
end
|
18
20
|
|
19
21
|
def initialize(stack, root = nil, limit = nil)
|
data/lib/sus/raise_exception.rb
CHANGED
@@ -8,6 +8,12 @@ module Sus
|
|
8
8
|
def initialize(exception_class = nil, message: nil)
|
9
9
|
@exception_class = exception_class
|
10
10
|
@message = message
|
11
|
+
@predicate = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def and(predicate)
|
15
|
+
@predicate = predicate
|
16
|
+
return self
|
11
17
|
end
|
12
18
|
|
13
19
|
def call(assertions, subject)
|
@@ -16,14 +22,16 @@ module Sus
|
|
16
22
|
subject.call
|
17
23
|
|
18
24
|
# Didn't throw any exception, so the expectation failed:
|
19
|
-
assertions.assert(false,
|
25
|
+
assertions.assert(false, "raised")
|
20
26
|
rescue @exception_class => exception
|
21
27
|
# Did it have the right message?
|
22
28
|
if @message
|
23
|
-
assertions.assert(@message === exception.message)
|
29
|
+
assertions.assert(@message === exception.message, "raised with message")
|
24
30
|
else
|
25
|
-
assertions.assert(true,
|
31
|
+
assertions.assert(true, "raised")
|
26
32
|
end
|
33
|
+
|
34
|
+
@predicate&.call(assertions, exception)
|
27
35
|
end
|
28
36
|
end
|
29
37
|
end
|
@@ -38,6 +46,10 @@ module Sus
|
|
38
46
|
if @message
|
39
47
|
output.write(" with message ", :variable, @message, :reset)
|
40
48
|
end
|
49
|
+
|
50
|
+
if @predicate
|
51
|
+
output.write(" and ", @predicate)
|
52
|
+
end
|
41
53
|
end
|
42
54
|
end
|
43
55
|
|
data/lib/sus/version.rb
CHANGED
data/lib/sus.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.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -37,7 +37,7 @@ cert_chain:
|
|
37
37
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
38
38
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
39
39
|
-----END CERTIFICATE-----
|
40
|
-
date: 2022-08-
|
40
|
+
date: 2022-08-27 00:00:00.000000000 Z
|
41
41
|
dependencies: []
|
42
42
|
description:
|
43
43
|
email:
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/sus/file.rb
|
63
63
|
- lib/sus/filter.rb
|
64
64
|
- lib/sus/fixtures.rb
|
65
|
+
- lib/sus/have.rb
|
65
66
|
- lib/sus/have_duration.rb
|
66
67
|
- lib/sus/identity.rb
|
67
68
|
- lib/sus/include_context.rb
|
metadata.gz.sig
CHANGED
Binary file
|