I am trying to run rspec for Ruby on Rails. I am running Rails 4.1.1. I have installed the gem, have established a spec folder with some tests. I have created a directory
Please install the following gem:
gem install 'rspec-rails'
And then run:
rails generate rspec:install
This will generate the spec folder and rails_helper.rb and spec_helper.rb. Your error should be taken care once this is done.
For newer versions (3.5), if you need to run the generator, rails generate rspec:install
doesn't work for me. I used:
rspec --init
Creates .rspec
and spec/spec_helper.rb
.
EDIT: Just in case, I found out that I installed rspec gem for ruby, not the one for Rails, so rspec:install wasn't available. Should use https://github.com/rspec/rspec-rails.
For someone. If you got that error when you trynna test a specific file. you might can like this
$ bundle exec rspec ./spec/features/user_login_spec.rb
$ bundle exec rspec ./spec/models/user_login_spec.rb
One possibility that worked for me is to make sure you're requiring spec_helper
. RubyMine can default require rspec
and this can sometimes lead to this error.
Always remember to run the
rspec
or the bundle exec rspec
from the root of your project.
Something like:
bundle exec rspec spec/features/file_test_spec.rb
I actually just had this error on rails 4 with rspec 3, but in my case I forgot to run the generator:
rails generate rspec:install
Also I had to remove warnings
from .rspec
, as stated by one of rpsec developers