sus 0.10.4 → 0.11.0

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: cbfd2216a9188a212a020c1e4780bc01e2d7b1246bf2f9475d28ad7e4e939f31
4
- data.tar.gz: 4929af7ca54b12e5e5cf460a097a507c782c64a5eb9265e425df12ed71e5c1b2
3
+ metadata.gz: 1e40571705fc5474aff2158cee00b9fd9b80778fa9d5e7caa30da9d039095368
4
+ data.tar.gz: 94cb197a3d237636360f5e62c1b5095352fb2956c7a4a01c49388d4dceab065d
5
5
  SHA512:
6
- metadata.gz: 7f246c6a57ec8c2ac0bf995e7e7194e1aa2b526f858fc9efb6942b7769b7fe801b7c8095e06c4f5127d71669510813c00185d831cf983624cf2b6ad1776fc2d0
7
- data.tar.gz: 279b9ec5642a6a3a4af069524c0944ff08d0d101066189054ac00ebacd215886a0f84b23dd2a6ae07ad0c65bc6c646bcd6374298910b913d9a9b152259aa64de
6
+ metadata.gz: 9cda6d03170da4badb665d704afe42f02f80f162f51891dad475c9a6ad7539c4b76a315f655293a686ccf24338c4d7128722cabb30e3671018b20ca0959c3373
7
+ data.tar.gz: e4a0f447efe11fcc9a7417277faf55100903b711703a363532f28dedebed0b6d3cb0b13bc6675a8ac1b0c5d8eaa21566cbf305ab9b90cea05c9f77d05d2902c1
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/sus/be.rb CHANGED
@@ -52,6 +52,8 @@ module Sus
52
52
  Be.new(:===, value)
53
53
  end
54
54
  end
55
+
56
+ NIL = Be.new(:nil?)
55
57
  end
56
58
 
57
59
  class Base
@@ -68,7 +70,7 @@ module Sus
68
70
  end
69
71
 
70
72
  def be_nil
71
- Be.new(:nil?)
73
+ Be::NIL
72
74
  end
73
75
  end
74
76
  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
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2021-2022, by Samuel Williams.
5
5
 
6
6
  module Sus
7
- VERSION = "0.10.4"
7
+ VERSION = "0.11.0"
8
8
  end
data/lib/sus.rb CHANGED
@@ -17,6 +17,6 @@ require_relative 'sus/receive'
17
17
 
18
18
  require_relative 'sus/raise_exception'
19
19
  require_relative 'sus/have_duration'
20
- require_relative 'sus/have_attributes'
20
+ require_relative 'sus/have'
21
21
 
22
22
  require_relative 'sus/filter'
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.10.4
4
+ version: 0.11.0
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-26 00:00:00.000000000 Z
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/have_attributes.rb
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
@@ -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