sus 0.12.2 → 0.14.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d505d424da315b800a7343985c211d2cfdb9a74217fb81bd6025edec186e419
4
- data.tar.gz: 5e94dbc0566760d20f937a87c09fa958152c79fb06656827f66e7a189dc40a0a
3
+ metadata.gz: 1aa2de6186ab05050d85b1125c7244bb6cf25b1250f9973bc067f72a405e9396
4
+ data.tar.gz: 0bed63c55b1d2571d981efcb44fd5c008eab6f78e47bb7bf2d53e061b356b59a
5
5
  SHA512:
6
- metadata.gz: 5866a210c3427c7afa83ccd6b45c2915fdff79cd0c3cec8941f8a26f7ebe32d453911be4bbd08375c78bda93ae827a840669d1d9657465feff84cfef1488db7f
7
- data.tar.gz: 87092d555eab03db7ff1993bfea058fdb1a628cb22a2f57dc3bd63341dc29697c1444575664432d8fb277039faa6d4cbd2e78c3ab3f4fc7435be9229711eab64
6
+ metadata.gz: fe13105ac13ba02104c02e512273964b0b784cae3663faec805cd6bb4d3ed2efeb4fe0720521817766ea3a438f81ebf5ffc5a8877c864d131c31fbedaed6ec17
7
+ data.tar.gz: 23abcec32de31cdb6243a43439bc2a41e38842a456feb191808734aa2387c701c75de25af39f15c35474c1c6e222ea78e797b305247a8cd6ed5b646824cf7ea4
checksums.yaml.gz.sig CHANGED
Binary file
@@ -14,12 +14,15 @@ module Sus
14
14
  self.new(**options)
15
15
  end
16
16
 
17
- def initialize(identity: nil, target: nil, output: Output.buffered, inverted: false, isolated: false, measure: false, verbose: false)
17
+ # @parameter orientation [Boolean] Whether the assertions are positive or negative in general.
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)
18
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.
19
21
  @identity = identity
20
22
  @target = target
21
23
  @output = output
22
24
  @inverted = inverted
25
+ @orientation = orientation
23
26
  @isolated = isolated
24
27
  @verbose = verbose
25
28
 
@@ -39,7 +42,13 @@ module Sus
39
42
  attr :target
40
43
  attr :output
41
44
  attr :level
45
+
46
+ # Whether this aset of assertions is inverted
42
47
  attr :inverted
48
+
49
+ # The absolute orientation of this set of assertions:
50
+ attr :orientation
51
+
43
52
  attr :isolated
44
53
  attr :verbose
45
54
 
@@ -118,14 +127,14 @@ module Sus
118
127
  if condition
119
128
  @passed << self
120
129
 
121
- if @inverted || @verbose
122
- @output.puts(:indent, :passed, pass_prefix, message || "assertion", Output::Backtrace.first(@identity))
130
+ if !@orientation || @verbose
131
+ @output.puts(:indent, *pass_prefix, message || "assertion", Output::Backtrace.first(@identity))
123
132
  end
124
133
  else
125
134
  @failed << self
126
135
 
127
- if !@inverted || @verbose
128
- @output.puts(:indent, :failed, fail_prefix, message || "assertion", Output::Backtrace.first(@identity))
136
+ if @orientation || @verbose
137
+ @output.puts(:indent, *fail_prefix, message || "assertion", Output::Backtrace.first(@identity))
129
138
  end
130
139
  end
131
140
  end
@@ -158,7 +167,7 @@ module Sus
158
167
 
159
168
  lines = error.message.split(/\r?\n/)
160
169
 
161
- @output.puts(:indent, :error, fail_prefix, "Unhandled exception ", :value, error.class, ":", :reset, " ", lines.shift)
170
+ @output.puts(:indent, *fail_prefix, "Unhandled exception ", :value, error.class, ":", :reset, " ", lines.shift)
162
171
 
163
172
  lines.each do |line|
164
173
  @output.puts(:indent, "| ", line)
@@ -177,9 +186,16 @@ module Sus
177
186
  output = @output
178
187
  end
179
188
 
189
+ # Inverting a nested assertions causes the orientation to flip:
190
+ if inverted
191
+ orientation = !@orientation
192
+ else
193
+ orientation = @orientation
194
+ end
195
+
180
196
  output.puts(:indent, target)
181
197
 
182
- assertions = self.class.new(identity: identity, target: target, output: output, isolated: isolated, inverted: inverted, verbose: @verbose, **options)
198
+ assertions = self.class.new(identity: identity, target: target, output: output, isolated: isolated, inverted: inverted, orientation: orientation, verbose: @verbose, **options)
183
199
 
184
200
  output.indented do
185
201
  begin
@@ -264,13 +280,24 @@ module Sus
264
280
  # @output.puts
265
281
  # end
266
282
  end
267
-
283
+
284
+ PASSED_PREFIX = [:passed, "✓ "].freeze
285
+ FAILED_PREFIX = [:failed, "✗ "].freeze
286
+
268
287
  def pass_prefix
269
- "✓ "
288
+ if @orientation
289
+ PASSED_PREFIX
290
+ else
291
+ FAILED_PREFIX
292
+ end
270
293
  end
271
294
 
272
295
  def fail_prefix
273
- "✗ "
296
+ if @orientation
297
+ FAILED_PREFIX
298
+ else
299
+ PASSED_PREFIX
300
+ end
274
301
  end
275
302
 
276
303
  def inform_prefix
data/lib/sus/be_within.rb CHANGED
@@ -26,7 +26,9 @@ module Sus
26
26
  end
27
27
 
28
28
  def of(value)
29
- Bounded.new(Range.new(value - @tolerance, value + @tolerance))
29
+ tolerance = @tolerance.abs
30
+
31
+ return Bounded.new(Range.new(value - tolerance, value + tolerance))
30
32
  end
31
33
 
32
34
  def percent_of(value)
data/lib/sus/expect.rb CHANGED
@@ -51,9 +51,5 @@ module Sus
51
51
  Expect.new(@__assertions__, subject)
52
52
  end
53
53
  end
54
-
55
- def is_expected
56
- expect(subject)
57
- end
58
54
  end
59
55
  end
@@ -0,0 +1,37 @@
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 All
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
+ end
37
+ end
@@ -0,0 +1,45 @@
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 Any
9
+ def initialize(predicates)
10
+ @predicates = predicates
11
+ end
12
+
13
+ def print(output)
14
+ first = true
15
+ output.write("have any {")
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
+
34
+ if assertions.passed.any?
35
+ # We don't care about any failures in this case, as long as one of the values passed:
36
+ assertions.failed.clear
37
+ else
38
+ # Nothing passed, so we failed:
39
+ assertions.assert(false, "could not find any matching value")
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
data/lib/sus/have.rb CHANGED
@@ -3,37 +3,11 @@
3
3
  # Released under the MIT License.
4
4
  # Copyright, 2022, by Samuel Williams.
5
5
 
6
+ require_relative 'have/all'
7
+ require_relative 'have/any'
8
+
6
9
  module Sus
7
10
  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
11
  class Key
38
12
  def initialize(name, predicate = nil)
39
13
  @name = name
@@ -69,11 +43,29 @@ module Sus
69
43
  end
70
44
  end
71
45
  end
46
+
47
+ class Value
48
+ def initialize(predicate)
49
+ @predicate = predicate
50
+ end
51
+
52
+ def print(output)
53
+ output.write("value ", @predicate, :reset)
54
+ end
55
+
56
+ def call(assertions, subject)
57
+ subject.each_with_index do |value, index|
58
+ assertions.nested("[#{index}] = #{value.inspect}") do |assertions|
59
+ @predicate&.call(assertions, value)
60
+ end
61
+ end
62
+ end
63
+ end
72
64
  end
73
65
 
74
66
  class Base
75
67
  def have(*predicates)
76
- Have::Composite.new(predicates)
68
+ Have::All.new(predicates)
77
69
  end
78
70
 
79
71
  def have_keys(*keys)
@@ -89,7 +81,7 @@ module Sus
89
81
  end
90
82
  end
91
83
 
92
- Have::Composite.new(predicates)
84
+ Have::All.new(predicates)
93
85
  end
94
86
 
95
87
  def have_attributes(**attributes)
@@ -97,7 +89,15 @@ module Sus
97
89
  Have::Attribute.new(key, value)
98
90
  end
99
91
 
100
- Have::Composite.new(predicates)
92
+ Have::All.new(predicates)
93
+ end
94
+
95
+ def have_any(*predicates)
96
+ Have::Any.new(predicates)
97
+ end
98
+
99
+ def have_value(predicate)
100
+ Have::Any.new([Have::Value.new(predicate)])
101
101
  end
102
102
  end
103
103
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2022, by Samuel Williams.
4
+ # Copyright, 2021-2022, by Samuel Williams.
5
5
 
6
6
  require_relative 'bar'
7
7
  require_relative 'status'
@@ -26,7 +26,7 @@ module Sus
26
26
  rescue @exception_class => exception
27
27
  # Did it have the right message?
28
28
  if @message
29
- assertions.assert(@message === exception.message, "raised with message")
29
+ @message.call(assertions, exception.message)
30
30
  else
31
31
  assertions.assert(true, "raised")
32
32
  end
data/lib/sus/receive.rb CHANGED
@@ -24,21 +24,27 @@ module Sus
24
24
  output.write("receive ", :variable, @method.to_s, :reset, " ")
25
25
  end
26
26
 
27
- def with_arguments(*arguments)
28
- @arguments = WithArguments.new(arguments)
27
+ def with_arguments(predicate)
28
+ @arguments = WithArguments.new(predicate)
29
29
  return self
30
30
  end
31
-
32
- def with_options(*options)
33
- @options = WithOptions.new(options)
31
+
32
+ def with_options(predicate)
33
+ @options = WithOptions.new(predicate)
34
34
  return self
35
35
  end
36
-
37
- def with_block
38
- @block = WithBlock.new
36
+
37
+ def with_block(predicate = Be.new(:!=, nil))
38
+ @block = WithBlock.new(predicate)
39
39
  return self
40
40
  end
41
-
41
+
42
+ def with(*arguments, **options)
43
+ with_arguments(Be.new(:==, arguments)) if arguments.any?
44
+ with_options(Be.new(:==, options)) if options.any?
45
+ return self
46
+ end
47
+
42
48
  def once
43
49
  @times = Times.new(Be.new(:==, 1))
44
50
  end
@@ -101,44 +107,49 @@ module Sus
101
107
  end
102
108
 
103
109
  class WithArguments
104
- def initialize(arguments)
105
- @arguments = arguments
110
+ def initialize(predicate)
111
+ @predicate = predicate
106
112
  end
107
113
 
108
114
  def print(output)
109
- output.write("with arguments ", :variable, @arguments.inspect)
115
+ output.write("with arguments ", @predicate)
110
116
  end
111
117
 
112
118
  def call(assertions, subject)
113
119
  assertions.nested(self) do |assertions|
114
- Expect.new(assertions, subject).to(Be == @arguments)
120
+ @predicate.call(assertions, subject)
115
121
  end
116
122
  end
117
123
  end
118
124
 
119
125
  class WithOptions
120
- def initialize(options)
121
- @options = options
126
+ def initialize(predicate)
127
+ @predicate = predicate
122
128
  end
123
129
 
124
130
  def print(output)
125
- output.write("with options ", :variable, @options.inspect)
131
+ output.write("with options ", @predicate)
126
132
  end
127
133
 
128
134
  def call(assertions, subject)
129
135
  assertions.nested(self) do |assertions|
130
- Expect.new(assertions, subject).to(Be.new(:include?, @options))
136
+ @predicate.call(assertions, subject)
131
137
  end
132
138
  end
133
139
  end
134
140
 
135
141
  class WithBlock
142
+ def initialize(predicate)
143
+ @predicate = predicate
144
+ end
145
+
136
146
  def print(output)
137
- output.write("with block")
147
+ output.write("with block", @predicate)
138
148
  end
139
149
 
140
150
  def call(assertions, subject)
141
151
  assertions.nested(self) do |assertions|
152
+
142
153
  Expect.new(assertions, subject).not.to(Be == nil)
143
154
  end
144
155
  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.12.2"
7
+ VERSION = "0.14.0"
8
8
  end
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.12.2
4
+ version: 0.14.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-28 00:00:00.000000000 Z
40
+ date: 2022-10-03 00:00:00.000000000 Z
41
41
  dependencies:
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bake-test
@@ -105,6 +105,8 @@ files:
105
105
  - lib/sus/filter.rb
106
106
  - lib/sus/fixtures.rb
107
107
  - lib/sus/have.rb
108
+ - lib/sus/have/all.rb
109
+ - lib/sus/have/any.rb
108
110
  - lib/sus/have_duration.rb
109
111
  - lib/sus/identity.rb
110
112
  - lib/sus/include_context.rb
metadata.gz.sig CHANGED
Binary file