I have searched for my problem and could not find it on stackoverflow. Found similar problems but none exactly like mine.
I am following Hartl's ruby on rails tutorial, however when i try to use rspec like he does i encounter this problem :
harrisspec $ rspec spec/
/home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/configuration.rb:896:in `load': cannot load such file -- /home/harris/rails_projects/myapp/spec/spec (LoadError)
from /home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/configuration.rb:896:in `each'
from /home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/command_line.rb:22:in `run'
from /home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/runner.rb:80:in `run'
from /home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/runner.rb:17:in `block in autorun'
Tried running it in the root of the application folder as well (another thread said this would work) but no dice :
harris~ $ rspec spec/
/home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/configuration.rb:896:in `load': cannot load such file -- /home/harris/spec (LoadError)
from /home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/configuration.rb:896:in `each'
from /home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/command_line.rb:22:in `run'
from /home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/runner.rb:80:in `run'
from /home/harris/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.14.6/lib/rspec/core/runner.rb:17:in `block in autorun'
How do I solve this ? I don't feel comfortable continuing with the tutorial without this as I am not sure how important this is for the development of an application.
Thanks in advance!!
The exception thrown from your second attempt suggests you ran it from your home directory, not the root application directory. Since (presumably) no rspec directory exists there, the LoadError makes sense. Going by the error in your first attempt, the correct directory would be /home/harris/rails_projects/myapp.
cd /home/harris/rails_projects/myapp
rspec spec/
Try that.
Related
I'm teaching myself ruby and have worked with Testfirst.org's curriculum, so I've used rspec before, but in a different directory. Now I'm I'm working through the following guide: http://guides.railsgirls.com/testing-rspec/
...at the first "rspec spec/lib/idea_spec.rb" I get:
Amys-MacBook-Air:railsgirls alightholder$ rspec spec/lib/idea_spec.rb
/Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load': cannot load such file -- /Users/alightholder/Ruby/railsgirls_stuff/railsgirls/spec/lib/idea_spec.rb (LoadError)
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `each'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:96:in `setup'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:84:in `run'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:69:in `run'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:37:in `invoke'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/exe/rspec:4:in `<top (required)>'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/bin/rspec:19:in `load'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/bin/rspec:19:in `<main>'
This looks like a configuration error to me. I've tried inserting /lib/ folder in between my idea_spec.rb and the /spec/ directory, but that didn't seem to help. I'm pretty sure I'm in the right folder and so far none of the guides on this site have been inaccurate or incomplete, so I'm at a loss why I'm getting a load error instead of a test run.
for "rspec spec/idea_spec.rb" I get:
/Users/alightholder/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- idea (LoadError)
from /Users/alightholder/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/alightholder/Ruby/railsgirls_stuff/railsgirls/spec/idea_spec.rb:2:in `<top (required)>'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `block in load_spec_files'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `each'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load_spec_files'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:96:in `setup'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:84:in `run'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:69:in `run'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/runner.rb:37:in `invoke'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/exe/rspec:4:in `<top (required)>'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/bin/rspec:19:in `load'
from /Users/alightholder/.rvm/gems/ruby-1.9.3-p125/bin/rspec:19:in `<main>'
Problem 1. idea_spec.rb (LoadError)
/Users/alightholder/.rvm/gems/ruby-1.9.3-p125/gems/rspec-core-3.1.2/lib/rspec/core/configuration.rb:1105:in `load': cannot load such file -- /Users/alightholder/Ruby/railsgirls_stuff/railsgirls/spec/lib/idea_spec.rb (LoadError)
Try executing rspec spec/idea_spec.rb, i.e., don't include lib.
It looks like you've initialized rspec in a directory called railsgirls which should produce a subdirectory called spec. Once you create your idea_spec.rb within the spec directory, the path to that file should simply be spec/idea_spec.rb as opposed to spec/lib/idea_spec.rb. I can't tell why the author of that guide has included lib. Also, be sure to execute rspec spec/idea_spec.rb from your railsgirls directory.
Problem 2. idea (LoadError)
/Users/alightholder/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- idea (LoadError)
Within idea_spec.rb, try changing
require "idea"
to
require "/Users/alightholder/Ruby/railsgirls_stuff/railsgirls/idea"
I'm assuming that your idea.rb is within your railsgirls directory -- if that's not right, replace the absolute path I used with the correct absolute path to your idea.rb.
After that, if you can run rspec without receiving a LoadError, then change from
require "/Users/alightholder/Ruby/railsgirls_stuff/railsgirls/idea"
(i.e., giving require an absolute path) to simply
require_relative "../idea"
So the Gemfile.lock of my Rails Framework sets my Rspec to v 2.99 while my computer runs 3.0.0. When I run my rspec test, I get:
/Users/MrChan/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0/lib/rspec/core/configuration.rb:1051:in `load': cannot load such file -- /Users/MrChan/Desktop/matt/week_2/db-drill-ar-student-schema-challenge/source/ar-student-schema/db/spec/student_spec.rb (LoadError)
from /Users/MrChan/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0/lib/rspec/core/configuration.rb:1051:in `block in load_spec_files'
from /Users/MrChan/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0/lib/rspec/core/configuration.rb:1051:in `each'
from /Users/MrChan/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0/lib/rspec/core/configuration.rb:1051:in `load_spec_files'
from /Users/MrChan/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0/lib/rspec/core/runner.rb:97:in `setup'
from /Users/MrChan/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0/lib/rspec/core/runner.rb:85:in `run'
from /Users/MrChan/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0/lib/rspec/core/runner.rb:70:in `run'
from /Users/MrChan/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0/lib/rspec/core/runner.rb:38:in `invoke'
from /Users/MrChan/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.0/exe/rspec:4:in `<top (required)>'
from /Users/MrChan/.rbenv/versions/2.1.1/bin/rspec:23:in `load'
from /Users/MrChan/.rbenv/versions/2.1.1/bin/rspec:23:in `<main>'
I know that this may be a stretch, but does anyone have any ideas? I've taken a look at my rspec tests and tried changing be_true to be_truthy in line with Rspec v 3.0, but I'm still getting an error...
Your error doesn't seem to be an Rspec version error. The first line says "cannot load such file (LoadError)" - that indicates it's trying to load a spec file, but can't. The file path is /Users/MrChan/Desktop/matt/week_2/db-drill-ar-student-schema-challenge/source/ar-student-schema/db/spec/student_spec.rb, so you should check:
Does the file exist?
Can you open it?
A common source of this error is trying to run rspec within a project subdirectory. When you run rspec Rspec looks for a spec/ directory. If you're in a subdirectory - maybe db in this example - then Rspec may look in the wrong place. Given that it seems like you're working through this code, I'm pretty sure that's where the error arose.
I just updated my gems (Including rails to 4.1). I ran guard and everything worked fine. Then I created a new model and ran guard again. This time in the console everything looks good but the guard notification says Rspec results failed! I opened the spec of the newly created model (its empty) and just save it without changing. Then in the console i can see the following error :
10:40:15 - INFO - Guard is now watching at '/home/pubudu/Projects/sumaga-asapuwa'
10:43:55 - INFO - Running: spec/models/dcache_spec.rb
/home/pubudu/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load': cannot load such file -- /home/pubudu/Projects/sumaga-asapuwa.bk/spec/models/dcache_spec.rb (LoadError)
from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `block in load'
from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:232:in `load_dependency'
from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/activesupport-4.1.0/lib/active_support/dependencies.rb:241:in `load'
from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `each'
from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:22:in `run'
from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
from /home/pubudu/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'
from /home/pubudu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/pubudu/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
[1] guard(main)>
Any idea how to fix this?
Guard is watching the directory /home/pubudu/Projects/sumaga-asapuwa but it is trying to run a spec file in /home/pubudu/Projects/sumaga-asapuwa.bk/spec/models (i.e. with an extra .bk on the folder name.
In the rspec section of your Guardfile you should have a line like:
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
This is in the instruction to Guard that if a .rb file under the app directory changes, or is created, to run rspec on the corresponding spec file. This is defined to be relative to the directory Guard is watching.
I've this file which I would like to test.
app/workers/station/http.rb
module Worker
module Station
class HTTP
# ...
end
end
end
This is my spec file.
spec/workers/station/http_spec.rb
describe Worker::Station::HTTP do
it "should do something" do
end
end
The problem now is that I'm getting the following error when running the spec file using rspec.
rspec spec/workers/station/http_spec.rb
/Users/linus/.rvm/gems/ruby-2.0.0-p247#global/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:464:in `load_missing_constant': Unable to autoload constant Station::HTTP, expected app/workers/station/http.rb to define it (LoadError)
from /Users/linus/.rvm/gems/ruby-2.0.0-p247#global/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:184:in `const_missing'
from spec/workers/station/http_spec.rb:3:in `<top (required)>'
from /Users/linus/.rvm/gems/ruby-2.0.0-p247#global/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:223:in `load'
from /Users/linus/.rvm/gems/ruby-2.0.0-p247#global/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:223:in `block in load'
from /Users/linus/.rvm/gems/ruby-2.0.0-p247#global/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:214:in `load_dependency'
from /Users/linus/.rvm/gems/ruby-2.0.0-p247#global/gems/activesupport-4.0.4/lib/active_support/dependencies.rb:223:in `load'
from /Users/linus/.rvm/gems/ruby-2.0.0-p247#global/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /Users/linus/.rvm/gems/ruby-2.0.0-p247#global/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `each'
from /Users/linus/.rvm/gems/ruby-2.0.0-p247#global/gems/rspec-core-2.14.8/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /Users/linus/.rvm/gems/ruby-2.0.0-p247#global/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:22:in `run'
from /Users/linus/.rvm/gems/ruby-2.0.0-p247#global/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
from /Users/linus/.rvm/gems/ruby-2.0.0-p247#global/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'
from /Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/linus/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
The strange thing is that everyting works in the console.
$ rails c
[1] pry(main)> Worker::Station::HTTP
=> Worker::Station::HTTP
Why is this happening using rspec and not in rails and how would I fix it?
I'm using
rails (4.0.4)
rspec (2.14.1)
As jfornoff suggests you could add a require statement to the spec with a statement something like the following:
require "app/workers/station/http"
But if you are using the Spring Rails application preloader and the above doesn't resolve the problem, you could also check to see if Spring needs to be restarted. You can test running the spec without using Spring as follows:
bundle exec rspec spec/workers/station/http_spec.rb
... or ...
spring stop # or bin/spring stop
rspec spec/workers/station/http_spec.rb
The app/workers path is not being autoloaded by rspec because it is not standard rails layout, you can add an autoload line to your spec_helper or require the file in the spec directly!
Note: If solutions above/below do not work for you.
In Rails 4.1 and 4.2 I got similar error while trying to run the following command
$ spring rspec spec/classes/email_parser/email_provider_spec.rb:163
even tried
$ rspec spec/classes/email_parser/email_provider_spec.rb:163
Unable to autoload constant Account::Onboarding
Called from /Users/john/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/activesupport-4.2.11.3/lib/active_support/dependencies.rb:238:in `block in load_dependency'
/Users/john/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/activesupport-4.2.11.3/lib/active_support/dependencies.rb:495:in `load_missing_constant': Unable to autoload constant Account::Onboarding, expected /Users/john/Projects/Core/app/models/account/onboarding.rb to define it (LoadError)
from /Users/john/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0/gems/activesupport-4.2.11.3/lib/active_support/dependencies.rb:184:in `const_missing'
from /Users/john/Projects/Core/app/models/account.rb:9:in `<class:Account>'
from /Users/john/Projects/Core/app/models/account.rb:3:in `<top (required)>'
Cause
Turns out, I recently restarted my Mac and forgot to start the PG server. Not finding the PG server to respond to port 5432, the app seems to be crashing with logs that do not make any sense.
Solution that worked for me
I started the PG server.
# For Mac
$ pg_ctl -D /usr/local/var/postgresql#11 start
# For Linux
$ sudo service postgresql start
Working through Michael Hartle's tutorial and I cannot execute RSpec; terminal is presenting with the following error:
/Users/coreymkimball/Canvi/Tutorials/sample_app/spec/requests/static_pages_spec.rb:1:in `require': cannot load such file -- spec-helper (LoadError)
from /Users/coreymkimball/Canvi/Tutorials/sample_app/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
from /Users/coreymkimball/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
It states that there has been a load error in the particular file; not sure how to go about creating a new one, or getting over this troubleshooting hurdle. Any help would be great.
You'll likely find that the file you made in your spec directory is called spec_helper, not spec-helper. Change the require at the top of your static_pages_spec.rb to reflect this.