spring
spring copied to clipboard
Spring does not preserve Rails root as current directory thus making impossible to run tests from a subfolder
For some reason Spring sets working folder to that from where the command was launched instead of keeping it as RAILS_ROOT. It looks like Rails testing framework expects it that way and thus gets broken. Steps to reproduce with Rails 6.1.1:
rails new spring_test
cd spring_test
bundle exec rails generate scaffold Model name:text
bundle exec rails db:migrate
bundle exec rails test
All is good and we see something like
Running via Spring preloader in process 3209
/home/mlt/.rvm/gems/ruby-2.6.6/gems/spring-2.1.1/lib/spring/application.rb:204: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
Run options: --seed 25091
# Running:
.......
Finished in 0.714637s, 9.7952 runs/s, 12.5938 assertions/s.
7 runs, 9 assertions, 0 failures, 0 errors, 0 skips
Now let's move to some project subfolder
cd db
bundle exec rails test
No tests are found because they are being looked for at the wrong place, i.e. db/test/**/*_test.rb.
Running via Spring preloader in process 3381
/home/mlt/.rvm/gems/ruby-2.6.6/gems/spring-2.1.1/lib/spring/application.rb:204: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
Run options: --seed 47427
# Running:
Finished in 0.000600s, 0.0000 runs/s, 0.0000 assertions/s.
Everything gets back to normal once we disable Spring:
[mlt@host db]$ DISABLE_SPRING=1 bundle exec rails test
Run options: --seed 7928
# Running:
.......
Finished in 0.714637s, 9.7952 runs/s, 12.5938 assertions/s.
7 runs, 9 assertions, 0 failures, 0 errors, 0 skips
Can you repro on spring 2.1.0? If you can't, it's likely that it's a regression on 2.1.0 that was reverted, but the revert is not yet released.
Regression it is! With 2.1.0:
[mlt@host db]$ bundle exec rails test
Running via Spring preloader in process 4037
/home/mlt/.rvm/gems/ruby-2.6.6/gems/spring-2.1.0/lib/spring/application.rb:199: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
Run options: --seed 44870
# Running:
.......
Finished in 18.512508s, 0.3781 runs/s, 0.4862 assertions/s.
7 runs, 9 assertions, 0 failures, 0 errors, 0 skips