Skip to content

Spring does not preserve Rails root as current directory thus making impossible to run tests from a subfolder #641

Description

@mlt

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions