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

undefined method `env' for #<ActionCable::Channel::ConnectionStub> #684

Closed
iduuck opened this issue Jan 13, 2021 · 2 comments
Closed

undefined method `env' for #<ActionCable::Channel::ConnectionStub> #684

iduuck opened this issue Jan 13, 2021 · 2 comments
Assignees
Labels

Comments

@iduuck
Copy link

iduuck commented Jan 13, 2021

Describe the bug

I am currently trying to make my RSpec test working, and I recently stumbled upon a failure, which I think is a bug in the system.

When I use the stub_connection helper. I am getting the following error.

#<NoMethodError: undefined method `env' for #<ActionCable::Channel::ConnectionStub:0x00007f81883a57d0>
Did you mean?  end>

To Reproduce

Steps to reproduce the behavior:

  • Using AppSignal for Ruby gem version 2.11.2
  • In my app using framework/library/gem ... version 6.0.3.2
  • With this code:
    context 'with a valid pubsub token' do
        let(:user) { create(:user) }
    
        before do
          stub_connection(identified_as: :user, current_user: user, token: <TOKEN-HERE>)
        end
    
        it 'confirms the subscription' do
          subscribe
    
          expect(subscription.confirmed?).to eq(true)
        end
      end
    
@iduuck iduuck added the bug label Jan 13, 2021
@iduuck iduuck changed the title undefinde method `env' for #<ActionCable::Channel::ConnectionStub> undefined method `env' for #<ActionCable::Channel::ConnectionStub> Jan 13, 2021
@tombruijn tombruijn self-assigned this Feb 12, 2021
@tombruijn
Copy link
Member

I've reproduced the problem and am working on a fix.

tombruijn added a commit to appsignal/test-setups that referenced this issue Feb 12, 2021
Allow testing of appsignal/appsignal-ruby#684
in a test setups environment.
tombruijn added a commit that referenced this issue Feb 15, 2021
When an Rails 6+ app test suite calls `stub_connection` for ActionCable
tests in an app AppSignal integrates with, it would fail with the
following error as reported in #684:

```
undefined method `env' for #<ActionCable::Channel::ConnectionStub>
```

To fix this, check if the `env` method is available before calling it to
prevent the error from occurring. Ideally we fix this upstream and make
the `ConnectionStub` behave more like an actual connection but with this
fix it at least works from our end now.

This change breaks on Rails 5 as there is no
`action_cable/channel/test_case` file/helper, it appears to use the real
connection class in that version.
tombruijn added a commit that referenced this issue Feb 18, 2021
When an Rails 6+ app test suite calls `stub_connection` for ActionCable
tests in an app AppSignal integrates with, it would fail with the
following error as reported in #684:

```
undefined method `env' for #<ActionCable::Channel::ConnectionStub>
```

To fix this, check if the `env` method is available before calling it to
prevent the error from occurring. Ideally we fix this upstream and make
the `ConnectionStub` behave more like an actual connection but with this
fix it at least works from our end now.

This change breaks on Rails 5 as there is no
`action_cable/channel/test_case` file/helper, it appears to use the real
connection class in that version.
@tombruijn
Copy link
Member

@iduuck Thanks again for the report! A fix for this has been released in Ruby gem 2.11.7. Please upgrade and let us know if you run into any problems :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants