Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit 6562230

Browse files
Use a method to create the matcher
1 parent 1d80cf7 commit 6562230

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ expect(double).to receive(:msg).with(hash_including(:a => 5)) # first arg is a h
279279
expect(double).to receive(:msg).with(array_including(5)) # first arg is an array with 5 as one of the key-values
280280
expect(double).to receive(:msg).with(hash_excluding(:a => 5)) # first arg is a hash without a: 5 as one of the key-values
281281
expect(double).to receive(:msg).with(start_with('a')) # any matcher, custom or from rspec-expectations
282-
expect(double).to receive(:msg).with(satisfy{|data| data.dig(:a, :b, :c) == 5 }) # any expectation
282+
expect(double).to receive(:msg).with(satisfy { |data| data.dig(:a, :b, :c) == 5 }) # assert anything you want
283283
```
284284

285285
## Receive Counts

features/setting_constraints/matching_arguments.feature

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ Feature: Matching arguments
7777
"""ruby
7878
RSpec.describe "Using satisfy for complex custom expecations" do
7979
let(:dbl) { double }
80-
before do
81-
expectation = satisfy do |data|
82-
data[:a][:b][:c] == 5
83-
end
84-
expect(dbl).to receive(:foo).with(expectation)
80+
81+
def a_b_c_equals_5
82+
satisfy { |data| data[:a][:b][:c] == 5 }
8583
end
8684
8785
it "passes when the expectation is true" do
86+
expect(dbl).to receive(:foo).with(a_b_c_equals_5)
8887
dbl.foo(a: { b: { c: 5 } })
8988
end
9089
9190
it "fails when the expectation is false" do
91+
expect(dbl).to receive(:foo).with(a_b_c_equals_5)
9292
dbl.foo(a: { b: { c: 3 } })
9393
end
9494
end

0 commit comments

Comments
 (0)