-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
actioncable channel helpers not being included for rails 5.2 projects #2377
Comments
As far as I remember What happens if you add require 'rspec/rails/matchers/action_cable' to your I couldn't find any reason why we only support it for Rails 6. @palkan, do you think it's safe to adjust the condition to support at least 5.2, or remove the version check altogether and rely on |
Well, it does define that method, but something else is missing. I get further, into my test and get this error
Note that this is a test that used to pass, and when I run the code locally (testing manually), it does work, so there is something else broken in the test. Not sure what part of actioncable testing does the broadcasting? |
the complete spec is
(so it's not missing the subscribe) |
Ok, so maybe I'm stumbling across the next error and should file a separate ticket for that? |
Are you up for some debugging? I suggest setting a breakpoint here https://github.com/rspec/rspec-rails/blob/main/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb#L120 and check why the broadcasted message doesn't match exactly. |
of course! just let me sleep on it and get back to you tomorrow ;) |
There is a similar issue I have for
I'm afraid it could make things worse. Probably, a better alternative would be to check a specific class presence not a version, say: def has_action_cable_testing?
return false unless defined?(::ActionCable)
begin
# trigger autoload here
ActionCable::Channel::TestCase
rescue NameError
false
end
end |
@palkan I'm confused, does Rails 5.2 have your patches to support testing channels? Or is this a case of your gem provides the patches and we don't (so your gem works with Rails 5.2, but we can't?) |
@prij when I set a breakpoint in there, messages is an empty array. |
near as I can tell, lib/action_cable/subscription_adapter/test.rb isn't being loaded or called. (in the action-cable-testing gem) |
Nope, Rails 5.2 has no action cable testing built-in. The current workaround is to patch require "action_cable/testing"
require "rspec/rails/feature_check"
RSpec::Rails::FeatureCheck.module_eval do
module_function
def has_action_cable_testing?
true
end
end
require "rspec/rails" Should we make rspec-rails checks version-independent (see #2377 (comment)) or should we add a patch to action-cable-testing to handle this? I think, the latter one is better: feature checking is good when it works and confusing when it doesn't (e.g., someone can add a fake |
Ok, can you suggest a feature check for detecting either your gem or the Rails 6 functionality? I'm guessing the ActionCable constant itself is not enough because on its own 5.2 will have that but won't have your helpers? |
The following should work: def has_action_cable_testing?
defined?(::ActionCable) && (ActionCable::VERSION::MAJOR >= 6 || defined?(::ActionCable::Channel::TestCase))
end Rails 6 setups autoload for |
@palkan Thanks! @robmathews Can you please check if the above work for you on Rails 5.2 and |
This change is up on |
What Ruby, Rails and RSpec versions are you using?
Ruby version: 2.7.1
Rails version: 5.2.4.3
RSpec version: rspec-rails (4.0.1)
Observed behaviour
I write a channel rspec like this:
and it fails with
Expected Behaviour
I expect stub_connection to be defined. Perhaps the version check here should allow rails 5.2:
tl; dr section
I've tracked this down to a mismatch in version numbers. rspec-rails has the following method:
rspec-rails-4.0.1/lib/rspec/rails/matchers.rb:
And also,
rspec-rails-4.0.1/lib/rspec/rails/feature_check.rb:
In my project, rails is '5.2.4.3' and so actioncable is version 5.2.4.3.
Now, I'm happy to continue using action-cable-testing, but unfortunately, it detects that rspec defines " has_action_cable_testing?", issues a deprecation warning, and then doesn't load.
Maybe I should file the bug report over there? Not sure, plus I know that he's deprecating that gem, so starting here.
The text was updated successfully, but these errors were encountered: