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

"Web Console is activated in the test environment. This is usually a mistake." #729

Open
ndbroadbent opened this issue Dec 7, 2019 · 1 comment

Comments

@ndbroadbent
Copy link
Contributor

I was previously just using rspec to run my tests, but I've just switched to parallel_tests, and now I'm running into this error when I'm calling the rake task:

$ rake parallel:spec
Web Console is activated in the test environment. This is
usually a mistake. To ensure it's only activated in development
mode, move it to the development group of your Gemfile:

    gem 'web-console', group: :development

If you still want to run it in the test environment (and know
what you are doing), put this in your Rails application
configuration:

    config.web_console.development_only = false

My Gemfile does have the web-console gem in the development group, but I think the initial rake command assumes that the Rails env is development so it loads all of the gems in this group.

There's a few ways I can fix this:

  • Run the parallel_rspec command directly
  • Run RAILS_ENV=test rake parallel:spec
    • Maybe I could shorten this by setting up an alias for my bash profile.
  • Set config.web_console.development_only = false in my application config

I think I'll just use the parallel_rspec command, but I was wondering how people normally resolve this issue? (And maybe something could be added to the README? I'm just not sure about the best solution.)

@ndbroadbent
Copy link
Contributor Author

ndbroadbent commented Dec 7, 2019

Oh I just ran into another issue with Spring. I've patched Spring, I saw the comments in this issue, but it sounds like the only way to run parallel tests with Spring is by running spring rake parallel:spec.

I attempted to fork spring-commands-rspec and create a spring-commands-parallel-rspec gem that adds a parallel_rspec command to Spring (and also includes the Spring patch automatically):

$ spring --help
Version: 2.1.0

Usage: spring COMMAND [ARGS]

Commands for Spring itself:

  binstub         Generate Spring based binstubs. Use --all to generate a binstub for all known commands. Use --remove to revert.
  help            Print available commands.
  server          Explicitly start a Spring server in the foreground
  status          Show current status.
  stop            Stop all Spring processes for this project.

Commands for your application:

  parallel_rspec  Runs the parallel_rspec command
  rails           Run a rails command. The following sub commands will use Spring: console, runner, generate, destroy, test.
  rake            Runs the rake command
  rspec           Runs the rspec command

So this is working without crashing and the tests pass, but it doesn't seem to provide any performance benefit. I think it's loading parallel_rspec inside the preloaded Rails environment, but then parallel_rspec starts it's own nested Rails environments outside of Spring.

I also tried to "springify" the parallel_spec executable, but that has the same issue:

$ bundle exec spring binstub --all

And actually I just tried running spring rake parallel:spec, and I think this also has the same problem. The rake commands starts a bit faster, but the RSpec tests aren't actually using the preloaded Rails environment.

EDIT

This is also happening for the 'helper' rake tasks. I added puts '=> Loading Rails application...' to the top of my config/application.rb, and I'm seeing:

$ rake parallel:create
Running via Spring preloader in process 45252
=> Loading Rails application...
=> Loading Rails application...
=> Loading Rails application...
=> Loading Rails application...
etc...

Also a similar RAILS_ENV issue to the one I mentioned above, because when I run parallel:drop or parallel:create, it is also dropping/creating my development database. I have to prefix the rake commands with RAILS_ENV=test so that it doesn't touch my development database.

EDIT 2

OHHHHHHH I just saw #468 and #469, and I didn't realize that Spring was disabled by default unless I explicitly set DISABLE_SPRING=0. I will send a PR to update the README and make this clearer.

EDIT 3

Awesome, I saw that the code in my spring-commands-parallel-rspec gem actually runs first, so I'm able to call ENV['DISABLE_SPRING'] ||= '0' earlier to force-enable Spring whenever someone intentionally adds the spring-commands-parallel-rspec gem to their Gemfile. So that fixes everything for Spring!

EDIT 4

I realized that I could support all of the commands from parallel_tests (not just rspec), so I've renamed the gem to spring-commands-parallel-tests. Have also opened a PR to add it to the rails/spring README.

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

1 participant