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

Spring breaks Run in Terminal #20

Open
demccormack opened this issue Jan 26, 2024 · 1 comment
Open

Spring breaks Run in Terminal #20

demccormack opened this issue Jan 26, 2024 · 1 comment

Comments

@demccormack
Copy link

Great work with this! I'd love to get it working fully for my project in VS Code.

My project uses spring to reload the development environment on code changes. When I use the CodeLens Run or Run in Terminal commands, they fail like this:

💥 bundle exec bin/rspec /Users/daniel/myproject/my_spec.rb
/Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/spring-4.1.3/lib/spring/application.rb:100:in `block in preload': Spring reloads, and therefore needs the application to have reloading enabled.
Please, set config.cache_classes to false in config/environments/test.rb.
 (RuntimeError)
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/railties-7.0.8/lib/rails/initializable.rb:32:in `instance_exec'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/railties-7.0.8/lib/rails/initializable.rb:32:in `run'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/railties-7.0.8/lib/rails/initializable.rb:61:in `block in run_initializers'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/3.1.0/tsort.rb:228:in `block in tsort_each'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/3.1.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/3.1.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/3.1.0/tsort.rb:349:in `block in each_strongly_connected_component'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/3.1.0/tsort.rb:347:in `each'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/3.1.0/tsort.rb:347:in `call'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/3.1.0/tsort.rb:347:in `each_strongly_connected_component'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/3.1.0/tsort.rb:226:in `tsort_each'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/3.1.0/tsort.rb:205:in `tsort_each'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/railties-7.0.8/lib/rails/initializable.rb:60:in `run_initializers'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/railties-7.0.8/lib/rails/application.rb:372:in `initialize!'
        from /Users/daniel/docker/tatou/api/config/environment.rb:5:in `<main>'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/bootsnap-1.17.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/bootsnap-1.17.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/spring-4.1.3/lib/spring/application.rb:107:in `preload'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/spring-4.1.3/lib/spring/application.rb:166:in `serve'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/spring-4.1.3/lib/spring/application.rb:148:in `block in run'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/spring-4.1.3/lib/spring/application.rb:142:in `loop'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/spring-4.1.3/lib/spring/application.rb:142:in `run'
        from /Users/daniel/.rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/spring-4.1.3/lib/spring/application/boot.rb:19:in `<top (required)>'
        from <internal:/Users/daniel/.rbenv/versions/3.1.4/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:/Users/daniel/.rbenv/versions/3.1.4/lib/ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from -e:1:in `<main>'

but I can make the same command work in my terminal by putting an environment variable at the start:

DISABLE_SPRING=1 bundle exec bin/rspec /Users/daniel/myproject/my_spec.rb

This is a workaround I picked up from other projects, e.g. ruby-debug/ruby-debug-ide#152 (comment)

Is there a way to customise the command this gem uses to run RSpec?

@st0012
Copy link
Owner

st0012 commented Feb 10, 2024

IMO the right solution to solve this problem is to properly configure your Rails app for Spring: rails/spring#598 (comment)
This workaround may help too: rails/spring#598 (comment)

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

2 participants