8000 action-cable-testing does not work with rspec-rails 4.0 and rails 5 · Issue #76 · palkan/action-cable-testing · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

action-cable-testing does not work with rspec-rails 4.0 and rails 5 #76

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

Open
syakovyn opened this issue Mar 27, 2020 · 5 comments
Open

Comments

@syakovyn
Copy link
8000 syakovyn commented Mar 27, 2020

The issue happens due to the following check in action_cable/testing/rspec.rb:
if RSpec::Rails::FeatureCheck.respond_to?(:has_action_cable_testing?).
It does not account for a fact that though the method is present it still returns false for Rails 5.

I suggest using if RSpec::Rails::FeatureCheck.respond_to?(:has_action_cable_testing?) && RSpec::Rails::FeatureCheck.has_action_cable_testing? instead.

@syakovyn
Copy link
Author

Looks like my suggestion does not help :(

@syakovyn
Copy link
Author
syakovyn commented Mar 27, 2020

I finally solved the issue by doing the following in rails_spec.rb:

module RSpec::Rails::FeatureCheck
  module_function

  def has_action_cable_testing?
    true
  end
end
require 'rspec/rails'

and completely removing require 'action_cable/testing/rspec' from that file while keeping action-cable-testing in Gemfile to provide the missing piece of testing functionality.

@palkan
Copy link
Owner
palkan commented Mar 29, 2020

Seems that feature check in rspec-rails is checking the Rails version: https://github.com/rspec/rspec-rails/blob/d810df59bb3b4ea7f3a2a0d0b169f2f2b9d390ac/lib/rspec/rails/feature_check.rb#L27

I think, that's correct: event though rspec-rails implementation is extracted from this gem, they could go out of sync. So, it's better to rely on the gem in Rails 5 even with the latest rspec-rails.

What was the problem with if RSpec::Rails::FeatureCheck.respond_to?(:has_action_cable_testing?) && RSpec::Rails::FeatureCheck.has_action_cable_testing? patch?

@syakovyn
Copy link
Author
syakovyn commented Mar 29, 2020

@palkan, it looks like require "rspec/rails" from action_cable/testing/rspec causes to load rspec/rails/example/channel_example_group.rb from rspec-rails before has_action_cable_testing? get a chance to be redefined to return true resulting in RSpec::Rails::ChannelExampleGroup being empty.
RSpec::Rails::ChannelExampleGroup is not loaded from action-cable-testing as it was already loaded from rspec-rails with an incomplete definition.

The workaround I use seems right to me. It tells rspec-rails to assume ActionCable testing is present and action-cable-testing gem is needed indirectly to provide the missing piece of functionality that was extracted into ActionCable 6. The other part is already in rspec-rails.

@alecdotninja
Copy link
alecdotninja commented Jun 23, 2020

I had trouble getting the sample from @syakovyn to work in my case. If I didn't require "rspec/rails" before the monkey patch, RSpec::Rails::FeatureCheck was not defined. On the other hand, if I required it after the money patch, not all the methods were defined.

This is the solution that seems to be working for me:

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"

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

3 participants
0