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

irb: warn: can't alias context from irb_context. (3.5.0.beta4 and 3.5.0 final) #1645

Closed
marcusg opened this issue Jun 28, 2016 · 18 comments · Fixed by #1678
Closed

irb: warn: can't alias context from irb_context. (3.5.0.beta4 and 3.5.0 final) #1645

marcusg opened this issue Jun 28, 2016 · 18 comments · Fixed by #1678

Comments

@marcusg
Copy link

marcusg commented Jun 28, 2016

Hey,

After upgrading from 3.5.0.beta3 to 3.5.0.beta4 I receive a warning when using the rails console command like:

bundle exec rails console
Loading development environment (Rails 5.0.0.rc2)
irb: warn: can't alias context from irb_context.
irb(main):001:0>

Version beta3 works well, the warning is only visible in beta4.

@jasnow
Copy link
Contributor

jasnow commented Jun 28, 2016

That did not help - i know

@myronmarston
Copy link
Member

That warning is coming from IRB here:

https://github.com/ruby/ruby/blob/32674b167bddc0d737c38f84722986b0f228b44b/lib/irb/extend-command.rb#L188

It's apparently happening because rspec-core, when loaded, defines context on the top level unless you disable monkey patching.

Can you provide a repo that repros this? I tried reproing it in isolation and have failed so far.

@marcusg
Copy link
Author

marcusg commented Jun 28, 2016

@myronmarston ah thanks, I'll try to create a repro the next days. Do you mean this line config.disable_monkey_patching! in spec_helper.rb? It seems monkeypatching is disabled in both of my scenarios, but only with rspec-rails-3.5.0.beta4 the warning gets printed.

@myronmarston
Copy link
Member

Do you mean this line config.disable_monkey_patching! in spec_helper.rb? It seems monkeypatching is disabled in both of my scenarios, but only with rspec-rails-3.5.0.beta4 the warning gets printed.

Correct, that's what I meant, but I just realized why that doesn't solve the problem here: because you have to opt-in to disabling monkey patching (instead of opting in to monkey patching), the monkey patches, including context being defined on main still happen up-front, and then the config option disables them. So it still triggers the IRB warning.

@fables-tales
Copy link
Member

hey @marcusg could you provide us with a reproduction case for this issue? Just a repository we can clone that demonstrates the problem. With that we can debug :)

@marcusg
Copy link
Author

marcusg commented Jul 8, 2016

@samphippen yes, of course. I'll add repro steps as soon as possible.

@marcusg
Copy link
Author

marcusg commented Jul 8, 2016

I've created a repro app https://github.com/marcusg/rspec-rails-issue-1645

  • ruby 2.2.3p173 and 2.3.0p0
  • a fresh rails 5.0.0 app
  • only rspec-rails added
  • using rspec-rails-3.5.0.beta3 works fine
  • using rspec-rails-3.5.0 produces warning when running "bundle exec rails"

@marcusg marcusg changed the title 3.5.0.beta4: irb: warn: can't alias context from irb_context. irb: warn: can't alias context from irb_context. (3.5.0.beta4 and 3.5.0 final) Jul 9, 2016
@fables-tales
Copy link
Member

Repro confirmed.

@ghost
Copy link

ghost commented Jul 22, 2016

I've got the same warning after upgrading rspec-rails to 3.5.1

myronmarston added a commit that referenced this issue Jul 22, 2016
This reverts commit 994cb7a.

The original fix was never shown to have fixed anything, and looks
to have triggered #1645 and rspec/rspec-core#2301.

Fixes #1645.
@myronmarston
Copy link
Member

There's an attempted fix in #1678 -- can one of you who has ran into this issue give that a try?

JonRowe pushed a commit that referenced this issue Jul 23, 2016
This reverts commit 994cb7a.

The original fix was never shown to have fixed anything, and looks
to have triggered #1645 and rspec/rspec-core#2301.

Fixes #1645.
@myronmarston
Copy link
Member

Can you merge this into the 3-5 branch as well?

Sent from my iPhone

On Jul 22, 2016, at 7:01 PM, Jon Rowe [email protected] wrote:

Closed #1645 via #1678.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

JonRowe pushed a commit that referenced this issue Jul 23, 2016
This reverts commit 994cb7a.

The original fix was never shown to have fixed anything, and looks
to have triggered #1645 and rspec/rspec-core#2301.

Fixes #1645.
@JonRowe
Copy link
Member

JonRowe commented Jul 23, 2016

Done.

@marcusg
Copy link
Author

marcusg commented Jul 23, 2016

Works for me with 3-5-maintenance branch, thank you guys!

@ClaudioFloreani
Copy link

ClaudioFloreani commented Jun 22, 2017

I'm still having issues with:

  • ruby 2.3.1p112
  • Rails 4.2.8
  • rspec (3.6.0)
  • rspec-core (3.6.0)
  • rspec-expectations (3.6.0)
  • rspec-mocks (3.6.0)
  • rspec-rails (3.6.0)
  • rspec-support (3.6.0)
$ rails c
Loading development environment (Rails 4.2.8)
irb: warn: can't alias context from irb_context.
2.3.1 :001 > exit

[EDIT] Just learned many other gems could cause this — I will investigate this further.

sebjacobs pushed a commit to futurelearn/rspec-rails that referenced this issue Mar 15, 2019
This reverts commit 994cb7a.

The original fix was never shown to have fixed anything, and looks
to have triggered rspec#1645 and rspec/rspec-core#2301.

Fixes rspec#1645.
n-b added a commit to betagouv/conseillers-entreprises that referenced this issue May 7, 2019
Don’t require rspec_junit_formatter gem

It’s only needed when running tests (for circleci).

It messes with the console, when running `rails c` it causes this warning:
```
irb: warn: can't alias context from irb_context
```

This is related to rspec monkey_patching a `context` method on `Object` (rspec/rspec-rails#1645)
n-b added a commit to demarches-simplifiees/demarches-simplifiees.fr that referenced this issue May 20, 2019
Don’t require rspec_junit_formatter gem
It’s only needed when running tests (for circleci).
It messes with the console, when running `rails c` it causes this warning:
```
irb: warn: can't alias context from irb_context
```
This is related to rspec monkey_patching a `context` method on `Object` (rspec/rspec-rails#1645)
@eagleas
Copy link

eagleas commented Apr 8, 2021

Hi! This solve warning for me:

  1. Add
RSpec.configure do |config|
...
  config.disable_monkey_patching!
...
end
  1. Patch in Gemfile
    gem 'rspec_junit_formatter'
    to:
    gem 'rspec_junit_formatter', require: false

@pirj
Copy link
Member

pirj commented Apr 8, 2021

Also, config.disable_monkey_patching! will be the set by default in RSpec 4.

@x-yuri
Copy link

x-yuri commented Sep 24, 2021

db-query-matchers also triggers this warning by requiring rspec/core. Do you think this line is needed? It seems like it's not.

P.S. Here's where the methods (including context) are supposedly added to main:
https://github.com/rspec/rspec-core/blob/v3.10.1/lib/rspec/core/dsl.rb#L84

@philippfrank
Copy link

Happened via guard-rspec for me. See guard/guard-rspec#396.

gem 'guard-rspec', require: false fixed this.

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

Successfully merging a pull request may close this issue.

10 participants