rspec - command not found

Viewed 17303

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.

4 Answers

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.

Related