This repository was archived by the owner on Nov 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +62
-7
lines changed Expand file tree Collapse file tree 2 files changed +62
-7
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,15 @@ def meth_2(x)
12
12
yield x , :additional_yielded_arg
13
13
end
14
14
15
- def meth_3 ( x :)
15
+ def meth_3 ( **kwargs )
16
+ kwargs
17
+ end
18
+
19
+ def meth_4 ( x : 1 )
20
+ x
21
+ end
22
+
23
+ def meth_5 ( x :)
16
24
x
17
25
end
18
26
@@ -129,9 +137,24 @@ def inst.foo; :bar; end
129
137
expect ( klass . new . meth_1 ) . to eq ( :original )
130
138
end
131
139
132
- it 'works for instance methods that use keyword arguments ' do
140
+ it 'works for instance methods that use double splat ' do
133
141
expect_any_instance_of ( klass ) . to receive ( :meth_3 ) . and_call_original
134
- expect ( klass . new . meth_3 ( x : :kwarg ) ) . to eq ( :kwarg )
142
+ expect ( klass . new . meth_3 ( x : :kwarg ) ) . to eq ( { x : :kwarg } )
143
+ end
144
+
145
+ it 'works for instance methods that use optional keyword arguments' do
146
+ expect_any_instance_of ( klass ) . to receive ( :meth_4 ) . and_call_original
147
+ expect ( klass . new . meth_4 ) . to eq ( 1 )
148
+ end
149
+
150
+ it 'works for instance methods that use optional keyword arguments with an argument supplied' do
151
+ expect_any_instance_of ( klass ) . to receive ( :meth_4 ) . and_call_original
152
+ expect ( klass . new . meth_4 ( x : :kwarg ) ) . to eq ( :kwarg )
153
+ end
154
+
155
+ it 'works for instance methods that use required keyword arguments' do
156
+ expect_any_instance_of ( klass ) . to receive ( :meth_5 ) . and_call_original
157
+ expect ( klass . new . meth_5 ( x : :kwarg ) ) . to eq ( :kwarg )
135
158
end
136
159
137
160
it 'works for instance methods defined on the superclass of the class' do
Original file line number Diff line number Diff line change @@ -32,12 +32,44 @@ module Mocks
32
32
expect ( receiver . foo ) . to eq ( 4 )
33
33
end
34
34
35
- it 'allows a `do...end` block implementation with keyword args to be provided' do
36
- wrapped . to receive ( :foo ) do |**kwargs |
37
- kwargs [ :kw ]
35
+ if RSpec ::Support ::RubyFeatures . kw_args_supported?
36
+ binding . eval ( <<-RUBY , __FILE__ , __LINE__ )
37
+ it 'allows a `do...end` block implementation with keyword args to be provided' do
38
+ wrapped.to receive(:foo) do |**kwargs|
39
+ kwargs[:kw]
40
+ end
41
+
42
+ expect(receiver.foo(kw: :arg)).to eq(:arg)
43
+ end
44
+
45
+ it 'allows a `do...end` block implementation with optional keyword args to be provided' do
46
+ wrapped.to receive(:foo) do |kw: :arg|
47
+ kw
48
+ end
49
+
50
+ expect(receiver.foo(kw: 1)).to eq(1)
51
+ end
52
+
53
+ it 'allows a `do...end` block implementation with optional keyword args to be provided' do
54
+ wrapped.to receive(:foo) do |kw: :arg|
55
+ kw
56
+ end
57
+
58
+ expect(receiver.foo).to eq(:arg)
38
59
end
60
+ RUBY
61
+ end
39
62
40
- expect ( receiver . foo ( kw : :arg ) ) . to eq ( :arg )
63
+ if RSpec ::Support ::RubyFeatures . required_kw_args_supported?
64
+ binding . eval ( <<-RUBY , __FILE__ , __LINE__ )
65
+ it 'allows a `do...end` block implementation with required keyword args' do
66
+ wrapped.to receive(:foo) do |kw:|
67
+ kw
68
+ end
69
+
70
+ expect(receiver.foo(kw: :arg)).to eq(:arg)
71
+ end
72
+ RUBY
41
73
end
42
74
43
75
it 'allows chaining off a `do...end` block implementation to be provided' do
You can’t perform that action at this time.
0 commit comments