Hi, recently I uninstalled RVM from my system in favor of Rbenv.
Apperently uninstalled all my gems like Rails and Rspec
So I reïnstalled them. However now I’m having an issue with Rspec when I run the test in my Rails project:
/Users/acandael/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.5/lib/bundler/runtime.rb:34:in `block in setup': You have already activated rspec-core 3.0.3, but your Gemfile requires rspec-core 2.14.8. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
I can run my test, but I have to prepend it with ‘bundle exec’:
bundle exec rspec
Is there a way to solve this issue, so I can run my test again by simply typing:
thanks for your help,
Hi @acandael_acanda, I usually just use
bundle exec aliased to
be. You can however use rbenv-gemsets so that you use gems on per project basis. There are probably other ways to achieve this though.
Hi pedro, thanks for the information. I think I’ll just type bundle exec. How did you alias the command to shorten it to ‘be’ ?
I actually got that by using thoughtbot’s dotfiles.
It is just a definition in
alias be="bundle exec"
You might also want to check that you have a binstub for rspec and that when you type
which rspec from your app’s root that you get the binstub (meaning it’s in the proper location in your path). You shouldn’t have to be using
bundle exec very often with a modern Rails app for things like
rake with proper binstubs.
just created the ~/.aliases file and add the alias, and it works
How can I create this ‘binstub’ ?
When I type the command: ‘which rspec’ in my Rails app root, I get:
@acandael_acanda I do the following:
~/.bashrc if on bash) on my machine, one-time setup:
For each Ruby app I work in, one-time setup per app to safely load binstubs:
mkdir -p .git/safe
To create the binstubs, one-time setup per app:
bundle binstubs --all
Or, if you want just the RSpec binstubs:
bundle binstub rspec-core
You can check that binstub into version control so your teammates also have it.
Now, I can run the command without
Hi Dan, thanks for the instructions. Do I need to literaly add:
to my ~/.bashrc file, or are the dots (…) placeholders for something else?
@acandael_acanda, the commands @croaky pasted should be used exactly as they are, there’s nothing to replace.
The dots tell your shell that for any original folder that has a subfolder with
.git/safe in it, that the
bin folder located in the original folder (two folders above
safe, which is back where you started) should be in your path.
The reason this approach works is that it’s not possible to put things into the
.git folder of a repository that get stored as repository contents, so if you were to download a git repository from someone else, that repo could only be declared as “trusted” by you adding
safe to the
BTW, it’s important that
safe is a folder and not a file, or else the entry won’t be valid in your path and your shell will ignore it.
Thanks a lot! I just added the Rspec binstub and it works!
how odd, all of a sudden, after all was working fine, I get the same error again when trying to do run my testsuite with ‘rspec’:
/Users/acandael/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.5/lib/bundler/runtime.rb:34:in `block in setup': You have already activated rspec-core 3.0.3, but your Gemfile requires rspec-core 2.14.8. Prepending `bundle exec` to your command may solve this. (Gem::LoadError
to fix this I ran this command again:
bundle binstub rspec-core
but then I get the message
Skipped autospec and rspec since they already exist.
I would try two things at this point:
- Make sure that
which rspec is executing the binstub (verify the returned path).
- Delete the rspec binstub and then regenerate it the same way you did before with bundler.
If #1 is OK and you do #2, that should fix your version conflicts.
when I type the command
I that the rspec binstub I need to delete, or is the rspec binstub located in my Rails project folder?
That output means that your binstub is not coming first in the path. What’s the output of
echo $PATH when you type that in the shell?
the outpu of $echo PATH is:
OK, it looks like you need to go back and try to implement the edits to
.zshrc.local that @croaky described above. The two things you need to fix are:
- Check that no further path editing statements prevent
.git/safe/../../bin:$PATH from ending up at the front of your path. Rbenv loading will modify the path (by inserting its shims in the front), so do that before you try to add the git safe entry to the path.
- Make sure that you have a
safe folder in your app’s
.git folder. It has to be a folder, it can’t be a file.
If those two items are corrected, and you have an
rspec binstub in your binstubs folder, you should get the binstub as the result of
Hi Geoff thanks,
I don’t know how to check for editing statements preventing .git/safe/…/…/bin:$PATH from ending up at the front of my path.
The only thing I did was switch the two statements in my .bashrc file:
then I ran the command: bundle binstub rspec-core --force
again, and know I’m able again to run my tests again with:
bundle exec rspec