sus 0.37.1 → 0.37.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adb6aea1bd43dd00163501093a72b5e3ed4e599462248a7aacc4bd98732fd35e
4
- data.tar.gz: 603c5afe02ea770e0826ab158b84543f4b64e2ece0de9c303b8efa22ab092812
3
+ metadata.gz: 356b7bfa38432ef766bae5c9ef40f7e0d08cacf9423544c1226ac86c92e78f16
4
+ data.tar.gz: 21ea8115de9084304ad615db7d33d7facafa7255e1d3bafd408c9885ce14044e
5
5
  SHA512:
6
- metadata.gz: 5c3b7d6b3a32c817fa0b4e473556a272acd573a41d3b0a54ff760208f9037944d8b6c07725e70d96399058cc9e0ae6cf25c3f4aa50714e06aeb5a3b1ecd3f436
7
- data.tar.gz: 11e25dfb46c632ffe7f02ea0a3ccc63b8932749b58cba9564f8d465481b80db4d90504ab1db07e1648a31e7034cd32b99d3a2f9743a35d5032fa750faff2e366
6
+ metadata.gz: a3db361e81379abc117c1f977a979b66f6dcd1c42270fee895db1cb1d1bef0f6c64ed45fe51084de4d0e4671d6a83475cc7dc74523221340dbfeee5921bdbc8f
7
+ data.tar.gz: fe44089f8600b62d4255ecdaeb3b8e15060735a7ad8e5e9d78a8e5a5dfb05a63ae999b0681ccba55ce18048fa9cd5c94c8cbb221561b72328eee96b273d002f1
checksums.yaml.gz.sig CHANGED
@@ -1 +1 @@
1
- ?�T�̎5U���^r�%�<��5;VTG���x�WWH�w�᷽�8�;��ƚD�sx�����) {�n���A1VX';e�n�ڔ�G���
1
+ R�[��>wS޾� ��gyPK���)�w��:
data/lib/sus/be.rb CHANGED
@@ -46,7 +46,7 @@ module Sus
46
46
  # @parameter other [Object] Another predicate to combine.
47
47
  # @returns [Or] A new OR predicate.
48
48
  def |(other)
49
- Or.new(self, other)
49
+ Or.new([self, other])
50
50
  end
51
51
  end
52
52
 
@@ -93,7 +93,7 @@ module Sus
93
93
  # @parameter other [Object] Another predicate to combine.
94
94
  # @returns [And] A new AND predicate.
95
95
  def &(other)
96
- And.new(self, other)
96
+ And.new([self, other])
97
97
  end
98
98
 
99
99
  # Combine this predicate with another using OR logic.
data/lib/sus/config.rb CHANGED
@@ -196,13 +196,16 @@ module Sus
196
196
 
197
197
  # Print feedback about the test suite.
198
198
  # @parameter output [Output] The output handler.
199
- # @parameter assertions [Assertions] The assertions instance.
200
- def print_test_feedback(output, assertions)
201
- duration = @clock.duration
202
- rate = assertions.count / duration
203
-
204
- total = assertions.total
205
- count = assertions.count
199
+ # @parameter assertions [Assertions | Nil] The assertions instance.
200
+ # @parameter duration [Float] The total duration of the test suite.
201
+ # @parameter count [Integer] The number of assertions.
202
+ # @parameter total [Integer] The number of tests.
203
+ def print_test_feedback(output, assertions = nil,
204
+ duration: @clock.duration,
205
+ count: assertions.count,
206
+ total: assertions.total
207
+ )
208
+ rate = count / duration
206
209
 
207
210
  if total < 10 or count < 10
208
211
  output.puts "😭 You should write more tests and assertions!"
@@ -212,7 +215,7 @@ module Sus
212
215
  end
213
216
 
214
217
  # Check whether there is at least, on average, one assertion (or more) per test:
215
- assertions_per_test = assertions.count / assertions.total
218
+ assertions_per_test = count / total
216
219
  if assertions_per_test < 1.0
217
220
  output.puts "😩 Your tests don't have enough assertions (#{assertions_per_test.round(1)} < 1.0)!"
218
221
  end
@@ -242,6 +245,8 @@ module Sus
242
245
  end
243
246
  end
244
247
 
248
+ public :print_test_feedback
249
+
245
250
  # Print information about slow tests.
246
251
  # @parameter output [Output] The output handler.
247
252
  # @parameter assertions [Assertions] The assertions instance.
data/lib/sus/context.rb CHANGED
@@ -24,28 +24,6 @@ module Sus
24
24
  base.children = Hash.new
25
25
  end
26
26
 
27
- unless respond_to?(:set_temporary_name)
28
- # Set a temporary name for this context.
29
- # @parameter name [String] The temporary name.
30
- def set_temporary_name(name)
31
- # No-op.
32
- end
33
-
34
- # @returns [String] A string representation of this context.
35
- def to_s
36
- (self.description || self.name).to_s
37
- end
38
-
39
- # @returns [String] An inspect representation of this context.
40
- def inspect
41
- if description = self.description
42
- "\#<#{self.name || "Context"} #{self.description}>"
43
- else
44
- self.name
45
- end
46
- end
47
- end
48
-
49
27
  # Add a child context or test to this context.
50
28
  # @parameter child [Object] The child to add.
51
29
  def add(child)
@@ -4,6 +4,7 @@
4
4
  # Copyright, 2025-2026, by Samuel Williams.
5
5
 
6
6
  require "tmpdir"
7
+ require "fileutils"
7
8
 
8
9
  module Sus
9
10
  module Fixtures
@@ -12,10 +13,17 @@ module Sus
12
13
  # Set up a temporary directory before the test and clean it up after.
13
14
  # @yields {|&block| ...} The test block to execute.
14
15
  def around(&block)
15
- Dir.mktmpdir do |root|
16
+ root = Dir.mktmpdir
17
+
18
+ begin
16
19
  @root = root
20
+
17
21
  super(&block)
22
+ ensure
18
23
  @root = nil
24
+
25
+ # Use forced removal so cleanup tolerates paths which were already removed by the test or an external process.
26
+ FileUtils.remove_entry(root, true)
19
27
  end
20
28
  end
21
29
 
@@ -24,4 +32,3 @@ module Sus
24
32
  end
25
33
  end
26
34
  end
27
-
data/lib/sus/identity.rb CHANGED
@@ -142,7 +142,7 @@ module Sus
142
142
  end
143
143
  else
144
144
  # In theory this should be a bit faster:
145
- each_caller_location do |location|
145
+ Thread.each_caller_location do |location|
146
146
  if location.path == @path
147
147
  return self.with_line(location.lineno)
148
148
  end
@@ -154,16 +154,6 @@ module Sus
154
154
 
155
155
  protected
156
156
 
157
- if Thread.respond_to?(:each_caller_location)
158
- def each_caller_location(&block)
159
- Thread.each_caller_location(&block)
160
- end
161
- else
162
- def each_caller_location(&block)
163
- caller_locations(1).each(&block)
164
- end
165
- end
166
-
167
157
  def append_unique_key(key, unique = @unique)
168
158
  if @parent
169
159
  @parent.append_unique_key(key)
data/lib/sus/it.rb CHANGED
@@ -107,17 +107,19 @@ module Sus
107
107
 
108
108
  # Skip the test unless the Ruby version meets the minimum requirement.
109
109
  # @parameter version [String] The minimum Ruby version required.
110
- def skip_unless_minimum_ruby_version(version)
111
- unless RUBY_VERSION >= version
112
- skip "Ruby #{version} is required, but running #{RUBY_VERSION}!"
110
+ # @parameter ruby_version [String] The Ruby version to check.
111
+ def skip_unless_minimum_ruby_version(version, ruby_version = RUBY_VERSION)
112
+ unless compare_ruby_version(ruby_version, version) >= 0
113
+ skip "Ruby #{version} is required, but running #{ruby_version}!"
113
114
  end
114
115
  end
115
116
 
116
117
  # Skip the test if the Ruby version exceeds the maximum supported version.
117
118
  # @parameter version [String] The maximum Ruby version supported.
118
- def skip_if_maximum_ruby_version(version)
119
- if RUBY_VERSION >= version
120
- skip "Ruby #{version} is not supported, but running #{RUBY_VERSION}!"
119
+ # @parameter ruby_version [String] The Ruby version to check.
120
+ def skip_if_maximum_ruby_version(version, ruby_version = RUBY_VERSION)
121
+ if compare_ruby_version(ruby_version, version) >= 0
122
+ skip "Ruby #{version} is not supported, but running #{ruby_version}!"
121
123
  end
122
124
  end
123
125
 
@@ -128,5 +130,23 @@ module Sus
128
130
  skip "Ruby platform #{match} is not supported!"
129
131
  end
130
132
  end
133
+
134
+ private
135
+
136
+ def compare_ruby_version(left, right)
137
+ left_segments = left.split(".").map(&:to_i)
138
+ right_segments = right.split(".").map(&:to_i)
139
+ length = [left_segments.size, right_segments.size].max
140
+
141
+ length.times do |index|
142
+ left_segment = left_segments[index] || 0
143
+ right_segment = right_segments[index] || 0
144
+
145
+ return -1 if left_segment < right_segment
146
+ return 1 if left_segment > right_segment
147
+ end
148
+
149
+ return 0
150
+ end
131
151
  end
132
152
  end
@@ -21,9 +21,9 @@ module Sus
21
21
  parameters = @parameters.dup
22
22
 
23
23
  assertions.nested(self) do |assertions|
24
- expected_name = parameters.shift
25
-
26
24
  subject.each do |type, name|
25
+ expected_name = parameters.shift
26
+
27
27
  case type
28
28
  when :req
29
29
  assertions.assert(name == expected_name, "parameter #{expected_name} is required, but was #{name}")
data/lib/sus/version.rb CHANGED
@@ -5,5 +5,5 @@
5
5
 
6
6
  # @namespace
7
7
  module Sus
8
- VERSION = "0.37.1"
8
+ VERSION = "0.37.2"
9
9
  end
data/readme.md CHANGED
@@ -33,6 +33,10 @@ Please see the [project documentation](https://socketry.github.io/sus/) for more
33
33
 
34
34
  Please see the [project releases](https://socketry.github.io/sus/releases/index) for all releases.
35
35
 
36
+ ### v0.37.2
37
+
38
+ - Make `Sus::Fixtures::TemporaryDirectoryContext` ignore temporary directory cleanup failures.
39
+
36
40
  ### v0.37.1
37
41
 
38
42
  - Fixed `Sus::Mock#wrap` to forward blocks to the original method, and fixed `receive(...).with_block(...)` to use the supplied predicate.
data/releases.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases
2
2
 
3
+ ## v0.37.2
4
+
5
+ - Make `Sus::Fixtures::TemporaryDirectoryContext` ignore temporary directory cleanup failures.
6
+
3
7
  ## v0.37.1
4
8
 
5
9
  - Fixed `Sus::Mock#wrap` to forward blocks to the original method, and fixed `receive(...).with_block(...)` to use the supplied predicate.
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.37.1
4
+ version: 0.37.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file