From ec49d0eb8489cf3d58d06e15f27c3d44cde8927f Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Wed, 31 May 2023 11:00:51 +0100 Subject: [PATCH] Merge pull request #2680 from Vagab/allow-using-symbol-in-broadcast-to-matcher Allow to use symbols for broadcasting target --- .../rails/matchers/action_cable/have_broadcasted_to.rb | 5 ++++- .../rails/matchers/action_cable/have_broadcasted_to_spec.rb | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb b/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb index 8458fae2f2..674a9113a0 100644 --- a/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +++ b/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb @@ -96,8 +96,11 @@ def from_channel(channel) private def stream - @stream ||= if @target.is_a?(String) + @stream ||= case @target + when String @target + when Symbol + @target.to_s else check_channel_presence @channel.broadcasting_for(@target) diff --git a/spec/rspec/rails/matchers/action_cable/have_broadcasted_to_spec.rb b/spec/rspec/rails/matchers/action_cable/have_broadcasted_to_spec.rb index 7da826eca8..a2b3457a71 100644 --- a/spec/rspec/rails/matchers/action_cable/have_broadcasted_to_spec.rb +++ b/spec/rspec/rails/matchers/action_cable/have_broadcasted_to_spec.rb @@ -50,6 +50,12 @@ def broadcast(stream, msg) }.to have_broadcasted_to('stream') end + it "passes when using symbol target" do + expect { + broadcast(:stream, 'hello') + }.to have_broadcasted_to(:stream) + end + it "passes when using alias" do expect { broadcast('stream', 'hello')