@@ -22,6 +22,54 @@ Only significant changes (new APIs, deprecated APIs or backward-compatible
22
22
changes) are documented here, a.k.a. minor or major version bumps. If you want a
23
23
detailed changelog, go over the commit log in github (it's pretty low-traffic)
24
24
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
+
25
73
2.3.0:
26
74
- implemented validation of call arity for partial mocks. By setting
27
75
FlexMock.partials_verify_signatures = true
@@ -546,12 +594,10 @@ determining whether a given expectation matches or not.
546
594
series. The last value will be repeatably returned if the number of
547
595
matching calls exceeds the number of values.
548
596
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 >
550
598
551
599
Declares that the expected message will return the yielded value of
552
600
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.
555
601
556
602
* <b >returns( ... )</b >
557
603
@@ -755,13 +801,15 @@ The following rules are used for argument matching:
755
801
756
802
will match any even integer.
757
803
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 `
760
808
761
809
Example:
762
810
763
811
``` 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 )
765
813
m.should_receive(:foo ).with(Integer ).and_return(:no_block )
766
814
```
767
815
@@ -772,6 +820,22 @@ The following rules are used for argument matching:
772
820
m.foo(1 ) => returns :no_block
773
821
```
774
822
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
+
775
839
### Creating Partial Mocks
776
840
777
841
Sometimes it is useful to mock the behavior of one or two methods in
0 commit comments