Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matcher for Channel.broadcast_to #9

Closed
TheSmartnik opened this issue Nov 22, 2017 · 4 comments
Closed

Matcher for Channel.broadcast_to #9

TheSmartnik opened this issue Nov 22, 2017 · 4 comments

Comments

@TheSmartnik
Copy link
Contributor

Hi 馃槂

Channels in ActionCable have .broadcast_to method (docs), which can be called both inside and outside of a channel. It also accepts object/record as a first argument. Right now there are a couple of ways to check that this method was called, but I think it'd be a good idea to add a matcher for it.


Possible workarounds

  • Stub
expect(WebNotificationsChannel).to receive (:broadcast_to)
  • Manual construction of a stream
stream = WebNotificationsChannel.broadcasting_for([WebNotificationsChannel.channel_name, session])
expect { perform :action }.to have_broadcasted_to(stream)

Suggestions

  • Rename current have_broadcasted_to matcher to have_broadcasted, and add above functionality to have_broadcasted_to.

I think that will be more straightforward. have_broadcasted corresponds to #broadcast and have_broadcasted_to corresponds to .broadcast_to. However one is an instance method, while the other one is a class method. Maybe matchers should emphasize the difference.

  • Add channel_broadcast_to matcher

This one clearly states the distinction between methods. However, I don't think that it is as intuitive as an option above.

In both ways, though, I don't really know what would be a good syntax for specifying channel name.

What do you think?

@palkan
Copy link
Owner

palkan commented Nov 22, 2017

Hi!

I missed this 'cause I don't use broadcasting_for and prefer to construct streams by myself)

What about making have_broadcasted_to a little bit smarter an handle non-strings differently? I.e. to make it work like this:

expect { perform :action }.to have_broadcasted_to(session)
# call WebNotificationsChannel.broadcasting_for([WebNotificationsChannel.channel_name, session]) under the hood

@TheSmartnik
Copy link
Contributor Author

TheSmartnik commented Nov 22, 2017

That looks good. Thanks.

And what to do in cases when Channel.broadcast_to is called from another channel? Should it be specified with a second argument? Or, maybe there should be a special syntax for it?

@palkan
Copy link
Owner

palkan commented Nov 22, 2017

And what to do in cases when Channel.broadcast_to is called from another channel?

Something like:

expect { perform :action }.to have_broadcasted_to(session).from_channel(SomeChannel)

@palkan
Copy link
Owner

palkan commented Nov 27, 2017

Closed by #10

@palkan palkan closed this as completed Nov 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants