sus 0.10.4 → 0.11.2
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 +3 -1
- data/lib/sus/clock.rb +26 -9
- data/lib/sus/have.rb +103 -0
- data/lib/sus/version.rb +1 -1
- data/lib/sus.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
- data/lib/sus/have_attributes.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f878b94ac4b8236fdb411866336061b34cca3c59a9573e4cb0ef238d545ffe3d
|
4
|
+
data.tar.gz: c61aaee1228f6ab7796811ee739de195a5b59cf1a014f304d08f3d64488c94ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 181ee960cee58bf710d7de09a6f83f72a71f01d25716d18dd386562bf2984e14f690cfa1561b298d36bc068d06676481979866f48ee2a2716866e725a9d3c07f
|
7
|
+
data.tar.gz: 206fa66d07315578142b07b3802a66af629668502a2745dbf4a3f60cbebf4c8d8cc8c2edd4011397a22b7d039c753874409fe576d42890745629d4d5ac57a906
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/sus/be.rb
CHANGED
data/lib/sus/clock.rb
CHANGED
@@ -7,27 +7,41 @@ 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
|
13
17
|
|
14
|
-
|
18
|
+
def duration
|
19
|
+
if @start_time
|
20
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
21
|
+
@duration += now - @start_time
|
22
|
+
@start_time = now
|
23
|
+
end
|
24
|
+
|
25
|
+
return @duration
|
26
|
+
end
|
15
27
|
|
16
28
|
def <=>(other)
|
17
|
-
|
29
|
+
duration <=> other.to_f
|
18
30
|
end
|
19
31
|
|
20
32
|
def to_f
|
21
|
-
|
33
|
+
duration
|
22
34
|
end
|
23
35
|
|
24
36
|
def to_s
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
"#{(
|
37
|
+
duration = self.duration
|
38
|
+
|
39
|
+
if duration < 0.001
|
40
|
+
"#{(duration * 1_000_000).round(1)}µs"
|
41
|
+
elsif duration < 1.0
|
42
|
+
"#{(duration * 1_000).round(1)}ms"
|
29
43
|
else
|
30
|
-
"#{
|
44
|
+
"#{duration.round(1)}s"
|
31
45
|
end
|
32
46
|
end
|
33
47
|
|
@@ -37,9 +51,12 @@ module Sus
|
|
37
51
|
|
38
52
|
def stop!
|
39
53
|
if @start_time
|
40
|
-
|
54
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
55
|
+
@duration += now - @start_time
|
41
56
|
@start_time = nil
|
42
57
|
end
|
58
|
+
|
59
|
+
return duration
|
43
60
|
end
|
44
61
|
end
|
45
62
|
end
|
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/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.2
|
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,7 +62,7 @@ files:
|
|
62
62
|
- lib/sus/file.rb
|
63
63
|
- lib/sus/filter.rb
|
64
64
|
- lib/sus/fixtures.rb
|
65
|
-
- lib/sus/
|
65
|
+
- lib/sus/have.rb
|
66
66
|
- lib/sus/have_duration.rb
|
67
67
|
- lib/sus/identity.rb
|
68
68
|
- lib/sus/include_context.rb
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/sus/have_attributes.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Released under the MIT License.
|
4
|
-
# Copyright, 2021-2022, by Samuel Williams.
|
5
|
-
|
6
|
-
module Sus
|
7
|
-
class HaveAttributes
|
8
|
-
def initialize(attributes)
|
9
|
-
@attributes = attributes
|
10
|
-
end
|
11
|
-
|
12
|
-
def print(output)
|
13
|
-
first = true
|
14
|
-
output.write("have attributes {")
|
15
|
-
@attributes.each do |key, predicate|
|
16
|
-
if first
|
17
|
-
first = false
|
18
|
-
else
|
19
|
-
output.write(", ")
|
20
|
-
end
|
21
|
-
|
22
|
-
output.write(:variable, key.to_s, :reset, " ", predicate, :reset)
|
23
|
-
end
|
24
|
-
output.write("}")
|
25
|
-
end
|
26
|
-
|
27
|
-
def call(assertions, subject)
|
28
|
-
assertions.nested(self) do |assertions|
|
29
|
-
@attributes.each do |key, predicate|
|
30
|
-
predicate.call(assertions, subject.public_send(key))
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class Base
|
37
|
-
def have_attributes(...)
|
38
|
-
HaveAttributes.new(...)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|