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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve implicit description for RSpec::Rails::Matchers::ActionCable::HaveBroadcastedTo #2795

Merged

Conversation

boardfish
Copy link
Contributor

@boardfish boardfish commented Sep 4, 2024

Previously, tests defined like this:

it do
  expect { some_action }.to have_broadcasted_to("stream_name").from_channel(SomeChannel).with("some_data")
end

would implicitly be given the description have broadcasted to, which is derived from the name of the matcher method.
This didn't carry any extra information about the data we're expecting to be broadcast from the channel - behaviour
which would be very welcome in combination with Turbo Streams. With a matcher for Turbo Streams, we might benefit from
a description like "broadcast exactly 1 messages to stream with turbo-stream[action="append"][target="some_list"]".

@boardfish boardfish marked this pull request as ready for review September 4, 2024 15:41
@boardfish boardfish force-pushed the implicit-description-for-have-broadcasted-to branch from 622523a to 045fe57 Compare September 4, 2024 15:42
Copy link
Member

@JonRowe JonRowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good improvements here, just some minor tweaks to the specs and a removal of a private api in favour of the public one

@boardfish boardfish force-pushed the implicit-description-for-have-broadcasted-to branch 2 times, most recently from 02b8639 to 7ca8249 Compare September 5, 2024 09:37
@boardfish
Copy link
Contributor Author

Thank you both for your speedy reviews! I think I've addressed everything you've mentioned 👍

@@ -151,7 +160,7 @@ def data_description(data)
if data.is_a?(RSpec::Matchers::Composable)
data.description
else
data
data.inspect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What did this actually come from, I'm on the fence wether letting user values user to_s is fine or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect a matcher to use this if mentioning an object. The default description for the eq matcher does this:

it { expect("foo").to eq("foo") }

Resultant description:

is expected to eq "foo"

This adds some clarity to what the object is in context.

lib/rspec/rails/matchers/action_cable.rb Outdated Show resolved Hide resolved
…:HaveBroadcastedTo

Previously, tests defined like this:

```rb
it do
  expect { some_action }.to have_broadcasted_to("stream_name").from_channel(SomeChannel).with("some_data")
end
```

would implicitly be given the description `have broadcasted to`, which is derived from the name of the matcher method.
This didn't carry any extra information about the data we're expecting to be broadcast from the channel - behaviour
which would be very welcome in combination with Turbo Streams. With a matcher for Turbo Streams, we might benefit from
a description like "broadcast exactly 1 messages to stream with turbo-stream[action="append"][target="some_list"]".

Co-authored-by: Jon Rowe <hello@jonrowe.co.uk>
Co-authored-by: Phil Pirozhkov <pirj@users.noreply.github.com>
@boardfish boardfish force-pushed the implicit-description-for-have-broadcasted-to branch from 7ca8249 to 86db479 Compare September 5, 2024 15:32
Copy link
Member

@JonRowe JonRowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thank you for this

@JonRowe JonRowe merged commit 531992c into rspec:main Sep 7, 2024
17 checks passed
JonRowe added a commit that referenced this pull request Sep 7, 2024
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

Successfully merging this pull request may close these issues.

3 participants