Skip to content

Commit 39ae8de

Browse files
committed
Adding values_match? in have_broadcasted_to checker to accept anything as a hash value when data is provided
1 parent ce4b526 commit 39ae8de

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def check(messages)
112112
decoded = ActiveSupport::JSON.decode(msg)
113113
decoded = decoded.with_indifferent_access if decoded.is_a?(Hash)
114114

115-
if @data.nil? || @data === decoded
115+
if @data.nil? || Support::FuzzyMatcher.values_match?(@data, decoded)
116116
@block.call(decoded)
117117
true
118118
else

spec/rspec/rails/matchers/action_cable/have_broadcasted_to_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ def broadcast(stream, msg)
170170
}.to have_broadcasted_to('stream').with(a_hash_including(name: "David", id: 42))
171171
end
172172

173+
it "passes with provided data matchers with anything" do
174+
expect {
175+
broadcast('stream', id: 42, name: "David", message_id: 123)
176+
}.to have_broadcasted_to('stream').with({ name: anything, id: anything, message_id: anything })
177+
end
178+
173179
it "generates failure message when data not match" do
174180
expect {
175181
expect {

0 commit comments

Comments
 (0)