Reputation: 687
As part of assignment I am creating a basic website. When rails server is not running and I execute "rspec" for root directory, the rspec is executed. However tests fail. When I start rails server and execute rspec from another terminal window (after going to root directory), rspec doesnt work. I get the following message -
Tushars-MacBook-Pro:recipefinder tusharsaurabh$ rspec -bash: rspec: command not found
Please let me know, how to fix it.
Upvotes: 16
Views: 24143
Reputation: 421
I solved this problem using: gem install rspec
. There are others solutions that I didn't try like: sudo gem install rspec
, another one bundle exec rspec spec
Upvotes: 7
Reputation: 29098
I had this same challenge when working on a Rails 6 application:
After adding rspec
to my Gemfile
using:
group :test do
gem 'rspec-rails', '~> 5.0'
end
And installing it using bundle install
when I run the command rspec
I get the error:
rspec command not found
Here's how I fixed it:
Solution 1
Since rspec
is not globally installed on your system, but in your project, you will need to run the command each time:
bundle exec rspec
Solution 2
Instead of the verbose bundle exec rspec
we could generate binstubs for rspec so can that we run our specs with bin/rspec
or just rspec
using the command:
bundle binstubs rspec-core
Note: Close your current terminal/shell and reopen a new one after running the command.
Now you can run the command rspec
and everything will be fine.
Upvotes: 1
Reputation: 2092
Maybe your rspec
command isn't installed system-wide, that's ok, try running
bundle exec rspec
It should work.
Upvotes: 35
Reputation: 1349
You don't need to run the rails server to execute the rspec. Rspec runs standalone. just run the rspec spec
. It will run the specs you have written in the spec folder of your project.
If you need both to be running then you need to do something like this.It might work. Please try it.
add to your gem file:
group :development, :test do
gem 'rspec-rails'
end
hit bundle from your console.
bundle
rails generate rspec:install
Upvotes: 2