sus 0.32.0 → 0.33.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: 30853f93c0da945d2bb067d53fceba5fdc873ddc87c69369c364f2e61a5cce96
4
- data.tar.gz: b3564630a2abe168125dedb7d16d9d70ef1116a99f6f9596fa39e0e215a4a437
3
+ metadata.gz: db29c44268893d062be3e45b5719a6dbc19e262f35176dd0c42d94cb2353d799
4
+ data.tar.gz: 9ec4e241579b44e02c319c96d58556629e58f3d293802abbc162ea0d503788d8
5
5
  SHA512:
6
- metadata.gz: 812cc85caf14056ae5536b0847d1ccbe90b3ef74608c15168176aef9360b339e704c64c7c0c6b99f42951c3587c2d193bce82f09e98ccf0815504097b46e9507
7
- data.tar.gz: f932395d4a5e082d5e5ee9a2ddb9e0bba304cca73cb3f66c9856838f91ae34e96d096da22490af6b27cad405fbcd11b02a6e6be75a25eef9efb44bb4ce167b7f
6
+ metadata.gz: a21e37fc13db88ab62f707aced7c459f6db1e12b51b70c872e82274f6fe2f70392dcd3248286dfd5714c02662205e72f4e554a70f23df42a3016d5ca03a585de
7
+ data.tar.gz: 8076f874b40ee4aab71dbf34c2efc0270a2d0e802a0455503d842935beeca28fa35333939304eee3f54ea06183e3c0bee6667776d66357076ffc6f32ddb59b21
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/sus/receive.rb CHANGED
@@ -7,9 +7,7 @@ require_relative "respond_to"
7
7
 
8
8
  module Sus
9
9
  class Receive
10
- CALL_ORIGINAL = Object.new
11
-
12
- def initialize(base, method)
10
+ def initialize(base, method, &block)
13
11
  @base = base
14
12
  @method = method
15
13
 
@@ -17,7 +15,8 @@ module Sus
17
15
  @arguments = nil
18
16
  @options = nil
19
17
  @block = nil
20
- @returning = CALL_ORIGINAL
18
+
19
+ @returning = block
21
20
  end
22
21
 
23
22
  def print(output)
@@ -60,12 +59,27 @@ module Sus
60
59
  return self
61
60
  end
62
61
 
63
- def and_return(*returning)
64
- if returning.size == 1
65
- @returning = returning.first
62
+ def and_return(*returning, &block)
63
+ if block_given?
64
+ if returning.any?
65
+ raise ArgumentError, "Cannot specify both a block and returning values."
66
+ end
67
+
68
+ @returning = block
69
+ elsif returning.size == 1
70
+ @returning = proc{returning.first}
66
71
  else
67
- @returning = returning
72
+ @returning = proc{returning}
73
+ end
74
+
75
+ return self
76
+ end
77
+
78
+ def and_raise(...)
79
+ @returning = proc do
80
+ raise(...)
68
81
  end
82
+
69
83
  return self
70
84
  end
71
85
 
@@ -97,7 +111,7 @@ module Sus
97
111
 
98
112
  validate(mock, assertions, arguments, options, block)
99
113
 
100
- next @returning
114
+ next @returning.call(*arguments, **options, &block)
101
115
  end
102
116
  end
103
117
 
@@ -110,7 +124,7 @@ module Sus
110
124
  end
111
125
 
112
126
  def call_original?
113
- @returning == CALL_ORIGINAL
127
+ @returning.nil?
114
128
  end
115
129
 
116
130
  class WithArguments
@@ -128,7 +142,7 @@ module Sus
128
142
  end
129
143
  end
130
144
  end
131
-
145
+
132
146
  class WithOptions
133
147
  def initialize(predicate)
134
148
  @predicate = predicate
@@ -153,7 +167,7 @@ module Sus
153
167
  def print(output)
154
168
  output.write("with block", @predicate)
155
169
  end
156
-
170
+
157
171
  def call(assertions, subject)
158
172
  assertions.nested(self) do |assertions|
159
173
 
@@ -161,7 +175,7 @@ module Sus
161
175
  end
162
176
  end
163
177
  end
164
-
178
+
165
179
  class Times
166
180
  ONCE = Be.new(:==, 1)
167
181
 
@@ -172,7 +186,7 @@ module Sus
172
186
  def print(output)
173
187
  output.write("with call count ", @condition)
174
188
  end
175
-
189
+
176
190
  def call(assertions, subject)
177
191
  assertions.nested(self) do |assertions|
178
192
  Expect.new(assertions, subject).to(@condition)
@@ -182,8 +196,8 @@ module Sus
182
196
  end
183
197
 
184
198
  class Base
185
- def receive(method)
186
- Receive.new(self, method)
199
+ def receive(method, &block)
200
+ Receive.new(self, method, &block)
187
201
  end
188
202
  end
189
203
  end
data/lib/sus/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2021-2024, by Samuel Williams.
5
5
 
6
6
  module Sus
7
- VERSION = "0.32.0"
7
+ VERSION = "0.33.0"
8
8
  end
data/readme.md CHANGED
@@ -29,6 +29,11 @@ Please see the [project documentation](https://socketry.github.io/sus/) for more
29
29
 
30
30
  Please see the [project releases](https://socketry.github.io/sus/releases/index) for all releases.
31
31
 
32
+ ### v0.33.0
33
+
34
+ - Add support for `agent-context` gem.
35
+ - [`receive` now supports blocks and `and_raise`.](https://socketry.github.io/sus/releases/index#receive-now-supports-blocks-and-and_raise.)
36
+
32
37
  ### v0.32.0
33
38
 
34
39
  - `Sus::Config` now has a `prepare_warnings!` hook which enables deprecated warnings by default. This is generally considered good behaviour for a test framework.
data/releases.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Releases
2
2
 
3
+ ## v0.33.0
4
+
5
+ - Add support for `agent-context` gem.
6
+
7
+ ### `receive` now supports blocks and `and_raise`.
8
+
9
+ The `receive` predicate has been enhanced to support blocks and the `and_raise` method, allowing for more flexible mocking of method calls.
10
+
11
+ ``` ruby
12
+ # `receive` with a block:
13
+ expect(interface).to receive(:implementation) {10}
14
+
15
+ # `and_return` with a block:
16
+ expect(interface).to receive(:implementation).and_return{FakeImplementation.new}
17
+
18
+ # `and_raise` for error handling:
19
+ expect(interface).to receive(:implementation).and_raise(StandardError, "An error occurred")
20
+ ```
21
+
3
22
  ## v0.32.0
4
23
 
5
24
  - `Sus::Config` now has a `prepare_warnings!` hook which enables deprecated warnings by default. This is generally considered good behaviour for a test framework.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,12 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.0
4
+ version: 0.33.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  - Brad Schrag
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain:
12
11
  - |
@@ -38,15 +37,13 @@ cert_chain:
38
37
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
39
38
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
40
39
  -----END CERTIFICATE-----
41
- date: 2024-11-08 00:00:00.000000000 Z
40
+ date: 1980-01-02 00:00:00.000000000 Z
42
41
  dependencies: []
43
- description:
44
- email:
45
42
  executables:
46
43
  - sus
44
+ - sus-host
47
45
  - sus-parallel
48
46
  - sus-tree
49
- - sus-host
50
47
  extensions: []
51
48
  extra_rdoc_files: []
52
49
  files:
@@ -109,7 +106,6 @@ metadata:
109
106
  documentation_uri: https://socketry.github.io/sus/
110
107
  funding_uri: https://github.com/sponsors/ioquatix/
111
108
  source_code_uri: https://github.com/socketry/sus.git
112
- post_install_message:
113
109
  rdoc_options: []
114
110
  require_paths:
115
111
  - lib
@@ -124,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
120
  - !ruby/object:Gem::Version
125
121
  version: '0'
126
122
  requirements: []
127
- rubygems_version: 3.5.22
128
- signing_key:
123
+ rubygems_version: 3.6.7
129
124
  specification_version: 4
130
125
  summary: A fast and scalable test runner.
131
126
  test_files: []
metadata.gz.sig CHANGED
@@ -1,2 +1 @@
1
- �2���pi��ٓc��p{^���
2
- ��NU�M��.iQ �����&�1l)뀘�P�$@e���z����6�Hv�?��f��|���ڜ �7���w�h[<� ��z�m>�nee'�쬋d��!�ܙ�
1
+ �3���}�!s������1 ����i����0Z�@��[�m�ӗ�@h0v��T��Iϧ&6� � V��2�=ā�ƺ'=�G���n�bS���h�F(Xb.���GVx �0Z9�K<���,��/�