I am trying to use Rspec for my test. When I run
$ rspec mytest_spec.rb
I get the following error due to the
/home/bastien/.merbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- rails_helper (LoadError)
I have tried many things and somehow if I run
rspec spec
or
bundle exec rspec
from the folder where my .rspec file is I do not get any error. I have created an app just to dry test this issue (I created a new rail app, added rspec in my Gemfile, run the bundle install command and the rspec:install command, generated a scaffold and run the tests. Could anyone explain to me why I get this issue and how I can get rid of it? Do I do something wrong when I try to run only one single spec? Thanks.
For those that the answers above didn't help:
You just need to add gem 'rexml'
to your Gemfile.rb
, run bundle install
and try again.
You are getting that error because you're trying to call your spec like this...
rspec mytest_spec.rb
You need to call it like this from your app's root folder , not inside the spec folder. So first get in the right folder
cd ~/
cd path_to_your_rails_app
Then call your spec
rspec spec/the_rest_of_the_path_to_your_spec/mytest_spec.rb
for instance
rspec spec/models/mytest_spec.rb
For others who find this:
I got this error, 'require': cannot load such file -- rails_helper (LoadError)
, when I had included the rspec-rails gem but hadn't run rails generate rspec:install
which generates the spec/rails_helper.rb
file. So if the other solution doesn't help you, make sure you've done that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With