Skip to content

Commit c5c6c73

Browse files
committed
doc: release notes for 3.0 and 2.4
1 parent 2a93cc8 commit c5c6c73

File tree

1 file changed

+70
-6
lines changed

1 file changed

+70
-6
lines changed

README.md

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,54 @@ Only significant changes (new APIs, deprecated APIs or backward-compatible
2222
changes) are documented here, a.k.a. minor or major version bumps. If you want a
2323
detailed changelog, go over the commit log in github (it's pretty low-traffic)
2424

25+
3.0.0:
26+
- Added keyword argument and explicit proc support. Keyword argument support
27+
is Ruby 3.0+ only, getting the support to work on Ruby 2.7 deemed to be too
28+
complicated. See the release notes for 2.4 below for information about how
29+
migration can be done smoothly
30+
- `with` now expects all expected keyword arguments to be explicitly given in a
31+
natural way, for instance:
32+
33+
```
34+
mock.should_receive(:m).with("some", "args", with: 42)
35+
```
36+
37+
The values given to the arguments can be any matcher valid for the positional
38+
arguments
39+
- note that not giving any keyword arguments to `with` is interpreted as a
40+
negative (no keyword arguments are expected), and will fail if some arguments
41+
are given. Call `with_any_kw_args` after the `with` if you do not desire
42+
validation of keyword arguments:
43+
44+
```
45+
mock.should_receive(:m).with("some", "args").with_any_kw_args
46+
```
47+
48+
- for more complex matches, pass a match object to the `with_kw_args` method.
49+
For instance, to match only some keyword arguments, do
50+
51+
```
52+
mock.should_receive(:m).with("some", "args").with_kw_args(hsh(with: 42))
53+
```
54+
55+
- this release also makes matching procs explicit. Instead of passing Proc at
56+
the end of `with` as in 2.x, call `with_block` or `with_no_block`. If neither
57+
are called, flexmock won't validate either way (ignore whether or not a block
58+
was given). The default is to not match blocks, that is working
59+
- The default is to assume that blocks are optional (i.e. flexmock will match
60+
either way). Nonetheless, the method `with_optional_block` is implemented
61+
to help migration from flexmock 2.4.0 (but is a no-op).
62+
63+
2.4.0:
64+
- forward-compatible implementation of `with_kw_args`, `with_any_kw_args`,
65+
`with_block` and `with_no_block`. The objective of this release is to ensure
66+
that any test changes needed to handle Ruby 3 (along with flexmock 3) can run
67+
on ruby 2.7 and flexmock 2.4
68+
- the default behavior of flexmock 2 regarding proc matching, that is that one
69+
needs to match them explicitly, is unchanged. Use `with_optional_block` instead
70+
of passing `optional_proc` to `with`, to match optionally (IMPORTANT
71+
the explicit `with` methods that match blocks are called `block`, not `proc`)
72+
2573
2.3.0:
2674
- implemented validation of call arity for partial mocks. By setting
2775
FlexMock.partials_verify_signatures = true
@@ -546,12 +594,10 @@ determining whether a given expectation matches or not.
546594
series. The last value will be repeatably returned if the number of
547595
matching calls exceeds the number of values.
548596

549-
* <b>and_return { |<em>args</em>, ...| <em>code</em> ... }</b>
597+
* <b>and_return { |<em>*args</em>, <em>**kw</em>, <em>&block</em>| <em>code</em> ... }</b>
550598

551599
Declares that the expected message will return the yielded value of
552600
the block. The block will receive all the arguments in the message.
553-
If the message was provided a block, it will be passed as the last
554-
parameter of the block's argument list.
555601

556602
* <b>returns( ... )</b>
557603

@@ -755,13 +801,15 @@ The following rules are used for argument matching:
755801

756802
will match any even integer.
757803

758-
* If you wish to match a method call where a block is given, add
759-
`Proc` as the last argument to `with`.
804+
* By default, flexmock will ignore given blocks, that is it will assume that
805+
blocks are optional.
806+
807+
* If you wish to verify that a method call received a block, use `with_block`
760808

761809
Example:
762810

763811
```ruby
764-
m.should_receive(:foo).with(Integer,Proc).and_return(:got_block)
812+
m.should_receive(:foo).with(Integer).with_block.and_return(:got_block)
765813
m.should_receive(:foo).with(Integer).and_return(:no_block)
766814
```
767815

@@ -772,6 +820,22 @@ The following rules are used for argument matching:
772820
m.foo(1) => returns :no_block
773821
```
774822

823+
* If you wish to verify that a method call does not receive a block, use `with_no_block`
824+
825+
Example:
826+
827+
```ruby
828+
m.should_receive(:foo).with(Integer).with_no_block.and_return(:no_block)
829+
m.should_receive(:foo).with(Integer).and_return(:got_block)
830+
```
831+
832+
will cause the mock to return the following:
833+
834+
```ruby
835+
m.foo(1) { } => returns :got_block
836+
m.foo(1) => returns :no_block
837+
```
838+
775839
### Creating Partial Mocks
776840

777841
Sometimes it is useful to mock the behavior of one or two methods in

0 commit comments

Comments
 (0)