spring-commands-rspec icon indicating copy to clipboard operation
spring-commands-rspec copied to clipboard

RSpec not loading its binstub

Open FranklinYu opened this issue 9 years ago • 6 comments
trafficstars

Currently if I do bin/rspec then Spring is used as expected, but simply rspec doesn't make use of Spring. rails, in contrast, does respect its binstub (I tested by adding something in the binstub). My current workaround is zsh-autoenv, but not that neat.

I am not sure whether this issue belongs to this repository or to RSpec. If the latter, then which repository of @rspec?

FranklinYu avatar Sep 06 '16 06:09 FranklinYu

Unfortunately rake seems to ignore binstub as well.

FranklinYu avatar Sep 06 '16 06:09 FranklinYu

rspec itself or rake are not aware of spring so this behavior is expected. bin/rspec contains a piece of code which loads spring. This means you should always call bin/rspec.

istana avatar Apr 12 '17 13:04 istana

@istana binstub is not spring-specific; Bundler also generates that, to save you from bundle exec.

FranklinYu avatar Apr 12 '17 17:04 FranklinYu

you're right, but bin/rspec will use spring only if it's added to binstub. I still don't see a reason why rspec command should load binstub instead of the executable from the gem (or rbenv, ...) automatically.

If you don't want to write bin/rspec every time, you can use alias command in shell (alias rspec="bin/rspec"). Or as you mentioned zsh-autoenv. Or modify PATH variable, so binstub directory will be preferred over gem directories.

istana avatar Apr 24 '17 09:04 istana

I know this is a bit old, but I recently ran into similar issues...the problem here is that by calling rspec or bundle exec rspec you are using the executable that is installed with the gem (if you're using rvm like me, then it's under the ~/.rvm/gems directory). This executable has no knowledge of spring. If you setup spring binstubs with bundle exec spring binstubs --all or similar it adds a snippet of code to the top of bin/rake, bin/rails, and (with this gem) bin/rspec. This is how the rspec executable knows to load from spring. You will not ever be able to run rspec through spring without using bin/rspec. It's just the nature of the setup.

thebadmonkeydev avatar Mar 23 '18 20:03 thebadmonkeydev

Just to summarize some of the above; all 3 commands below start the spring server and/or use spring, for me:

  • bin/rails c
  • bundle exec rails c
  • rails c

In contrast, the only command that starts spring when running rspec is bin/rspec.

I think it would be nice/expected behavior if rspec behaved the same way.

The mechanism behind how rails loads it isn't clear (to me). Maybe it's a function of the boot/config process?

I'm using asdf-ruby + zsh and i know there are some shims/tools (like autoenv mentioned in OP) that will alias rails to bin/rails for example. I don't have anything like this configured.The spring docs recommend direnv for automatically using the bin aliases

jaydorsey avatar May 07 '21 15:05 jaydorsey