Open syakovyn opened 4 years ago
Looks like my suggestion does not help :(
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.
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?
@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
.
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"
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.