Rails rspec issues (cannot load such file --b (LoadError)) - ruby-on-rails

I'm following Hartl's guide to Ruby on Rails, and I'm currently trying to set up "guard" and "spork" for automating "rspec" testing. When I try to run
bundle exec rspec spec/requests/static_pages_spec.rb
I get the following errors:
/home/throne/.rvm/gems/ruby-1.9.3-p392#rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:434:in `require': cannot load such file -- b (LoadError)
from /home/throne/.rvm/gems/ruby-1.9.3-p392#rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:434:in `block in requires='
from /home/throne/.rvm/gems/ruby-1.9.3-p392#rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:434:in `map'
from /home/throne/.rvm/gems/ruby-1.9.3-p392#rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:434:in `requires='
from /home/throne/.rvm/gems/ruby-1.9.3-p392#rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:20:in `block in configure'
from /home/throne/.rvm/gems/ruby-1.9.3-p392#rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:19:in `each'
from /home/throne/.rvm/gems/ruby-1.9.3-p392#rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:19:in `configure'
from /home/throne/.rvm/gems/ruby-1.9.3-p392#rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:21:in `run'
from /home/throne/.rvm/gems/ruby-1.9.3-p392#rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
from /home/throne/.rvm/gems/ruby-1.9.3-p392#rails3tutorial2ndEd/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'
I looked at other solutions for people who had similar kinds of problems (things like reinstalling gems, using absolute paths and fixing do / end statements in the target file), but none of them seemed to even change the issue. Thanks for any help!

Rewrite your Gemfile. Change 'selenium-webdriver' to '~> 2.35.1', reinstall bundle and everything has to be OK!

I had same error when tried to run test with single dash in params (need to run with --rdb).

This page came up when I was researching the same problem using the same tutorial. After some added investigation, I discovered that I was typing only a single dash on the --drb option. With a single dash rspec enables debugging and tries to require the file 'b'. Very different from connecting to a DRb server :-

Related

Problems with Rspec and/or Rspec-core

I installed rspec and also did rspec --init. (I've gone through directions from here http://rspec.codeschool.com/levels/1 multiple times).
However, every time I try to run a spec from my command line, it won't load (please see below). Please help if you know what may be going wrong.
/Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in require': cannot load such file -- zombie (LoadError)
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /Users/Qureshi/spec/lib/zombie_spec.rb:2:in <top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1226:inload'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1226:in block in load_spec_files'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1224:ineach'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1224:in load_spec_files'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:97:insetup'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:85:in run'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:70:inrun'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:38:in invoke'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.2.0/exe/rspec:4:in'
from /usr/bin/rspec:23:in load'
from /usr/bin/rspec:23:in'
Try putting the following at the top of your spec_helper.rb:
require_relative '../lib/zombie'
Be sure your terminal's current folder is Users/Qureshi then run the command rspec spec
If it does not work, your file (or entire folder) is access blocked, or does not exist in /Users/Qureshi/spec/lib/

Rspec: Running Rspec v 2.99 in Rails but have v 3.0 installed

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.

"Unable to autoload constant" using rspec but not rails

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

Rspec invalid option-f OptionParser

I recently started the "Intro to Rails" screencast on nettuts. So I am not very familiar with Rails obviously and only know a little about Ruby. Everything else in the code will run correctly however when I run guard-rspec it displays this:
/Users/hanssingh/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:1013:in `block in process_args': invalid option: -f (OptionParser::InvalidOption)
from /Users/hanssingh/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:992:in `new'
from /Users/hanssingh/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:992:in `process_args'
from /Users/hanssingh/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:1042:in `_run'
from /Users/hanssingh/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/minitest/unit.rb:1035:in `run'
from /Users/hanssingh/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:21:in `run'
from /Users/hanssingh/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:774:in `run'
from /Users/hanssingh/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:366:in `block (2 levels) in autorun'
from /Users/hanssingh/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:27:in `run_once'
from /Users/hanssingh/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/test/unit.rb:365:in `block in autorun'
I am not very sure what this error means and how do I get rid of it?
Seems to be caused by the turn gem (I suspect you have it). Remove it from your Gemfile, run bundle again, and then try your tests with guard once more. This worked for me.
Was having a similar issue getting Test::Unit errors when running Guard:
/usr/local/var/rbenv/versions/1.9.3-p327/lib/ruby/1.9.1/test/unit.rb:49:in `process_args': invalid option: -f (OptionParser::InvalidOption)
According to https://github.com/guard/guard/issues/170 this was caused by having the shoulda gem included in my Gemfile. Changing this to should-matchers fixed the issue for me without having to lose the loveliness of shoulda.
Studying the Nettuts 'Intro to Rails' Gemfile it seems to contain the 'turn' gem which is minitest-based. So removing this from your Gemfile should help, as #kladd suggests.

Rspec stops working suddenly because of `require': no such file to load

Rspec has been running fine for a while but then I suddenly encounter this issue when running any rspec tests:
/Users/joseph/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:437:in `require': no such file to load -- rspec/instafail (LoadError)
from /Users/joseph/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:437:in `block in requires='
from /Users/joseph/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:435:in `map'
from /Users/joseph/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:435:in `requires='
from /Users/joseph/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:20:in `block in configure'
from /Users/joseph/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:19:in `each'
from /Users/joseph/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.11.1/lib/rspec/core/configuration_options.rb:19:in `configure'
from /Users/joseph/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:21:in `run'
from /Users/joseph/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:66:in `rescue in run'
from /Users/joseph/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:62:in `run'
from /Users/joseph/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'
I usually have a couple of checkouts of my project (i.e. git clone twice into separate directories). For some reason rspec would encounter this issue only in one of my checkouts and not the other even when using the same version of the code. I eventually circumvented the issue by creating another clone. This issue has popped up again for some reason, and I don't want to have to keep creating clones to avoid the issue. Does anyone know what might be the root cause?
Turns out the issue was gems like rspec-instafail were grouped as a development gem. At some point in the past I had run 'bundle install --without development' and apparently subsequent bundle installs are done with that option automatically. As a result, those gems weren't on my $LOAD_PATH.
To fix it, I just ran 'bundle install --without asdf' and since there isn't an 'asdf' group it installed all the gems. There's probably a more appropriate option to re-add those groups, but this worked for me.

Resources