Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doing a `git checkout` while running `rspec`

Tags:

git

ruby

rspec

While executing a long-running test suite with RSpec, I would like to checkout another git branch.

How does RSpec behave in this case? Does it read all files into memory as part of its boot-up process (in which case changing branch would have no effect), or does it read them only when they are needed?

like image 429
asymmetric Avatar asked Sep 16 '15 10:09

asymmetric


1 Answers

If you checkout while the tests are already running, it will keep executing the specs associated to the previous branch as long as the process doesn't start other processes (e.g. using rake test may start different test suites in different processes if they are provided as different tasks).

However, if your specs need to access resources outside the Ruby environment at runtime, such as writing/reading a file on the file system, and that resource is not available in the new branch or it's changed, then the specs may return invalid result.

In other words, as long as the specs only relies on code that may be loaded by the Ruby virtual machine when the process is stared, then you'll be fine.

Whether this is recommended or not, that's another story. I would personally avoid it to prevent unplanned side effects.

like image 160
Simone Carletti Avatar answered Oct 15 '22 05:10

Simone Carletti