st0012 / ruby-lsp-rspec

A Ruby LSP addon for RSpec tests
MIT License
127 stars 7 forks source link

Spring breaks Run in Terminal #20

Open demccormack opened 10 months ago

demccormack commented 10 months ago

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. https://github.com/ruby-debug/ruby-debug-ide/issues/152#issuecomment-432741366

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

st0012 commented 9 months ago

IMO the right solution to solve this problem is to properly configure your Rails app for Spring: https://github.com/rails/spring/issues/598#issuecomment-554030462 This workaround may help too: https://github.com/rails/spring/issues/598#issuecomment-1268885973