Problems with Rspec and/or Rspec-core - ruby-on-rails

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/

Related

RSpec, Mocha and Rubymine - Undefined method `mocha_setup'

I have two styles of spec in a single folder, one of which uses a full-fat rails environment, with rspec, the other is a light-weight helper which requires gems individually.
Recently I've had some problems running these together in Rubymine.
Right-clicking on a single file of either style runs fine. Right clicking the folder and selecting "Run > All specs in folder" has been returning this error for each spec:
NameError: undefined local variable or method `mocha_setup' for #<RSpec::Core::ExampleGroup::Nested_1:0x0000000ca26d70>
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-expectations-2.14.5/lib/rspec/matchers/method_missing.rb:9:in `method_missing'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/mocking/with_mocha.rb:40:in `setup_mocks_for_rspec'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:299:in `run_before_each'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:113:in `block in run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:254:in `with_around_each_hooks'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example.rb:111:in `run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:390:in `block in run_examples'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:386:in `map'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:386:in `run_examples'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/example_group.rb:371:in `run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:28:in `map'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:28:in `block in run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/reporter.rb:58:in `report'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/command_line.rb:25:in `run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:80:in `run'
/home/ajfaraday/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.14.5/lib/rspec/core/runner.rb:17:in `block in autorun'
This had run together perfectly well until very recently.
I can run all of the specs from the command line without any issues:
rspec --pattern spec/models/auto_ordering/*_spec.rb
This seems to be something specific about running this folder within Rubymine. I've tried invalidating my caches and restarting the IDE. I've tried deleting the configuration for running that folder.
Does anyone know what might be causing this?
Update: I've since discovered that this seems to happen sporadically when calling it through the command line, also.
I eventually solved this issue:
It was nothing to do with Rubymine, it was a load-order issue.
Rubymine was running files in strict alphabetical order, the CLI was running them in an arbitrary order
When the full rails environment was loading first, it was working fine.
When my lean environment was loading first, it was missing this piece of config:
RSpec.configure do |config|
config.mock_framework = :mocha
end
I added this to my light-weight spec helper and I can now run these files in any order.

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 LoadError (Ruby on Rails, Michael Hartl's tutorial)

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.

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

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 :-

Resources