jonleighton / spring-commands-rspec

MIT License
378 stars 37 forks source link

RSpec not loading its binstub #37

Open FranklinYu opened 8 years ago

FranklinYu commented 8 years ago

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 commented 8 years ago

Unfortunately rake seems to ignore binstub as well.

istana commented 7 years ago

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.

FranklinYu commented 7 years ago

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

istana commented 7 years ago

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.

thebadmonkeydev commented 6 years ago

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.

jaydorsey commented 3 years ago

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

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