Search code examples
rspecmockingrspec-mocks

rspec: "no such file to load -- rspec/mocks"


I'm trying to run a test on some very simple Ruby. I have ruby and rails installed on my linux machine. I also have rspec installed. My gem list is:

LOCAL GEMS

actionmailer (3.2.8)
actionpack (3.2.8)
activemodel (3.2.8)
activerecord (3.2.8)
activeresource (3.2.8)
activesupport (3.2.8)
arel (3.0.2)
builder (3.0.0)
bundler (1.2.0, 1.1.5)
diff-lcs (1.1.3)
erubis (2.7.0)
hike (1.2.1)
i18n (0.6.1, 0.6.0)
journey (1.0.4)
json (1.7.5)
mail (2.4.4)
mime-types (1.19)
multi_json (1.3.6)
polyglot (0.3.3)
rack (1.4.1)
rack-cache (1.2)
rack-ssl (1.3.2)
rack-test (0.6.1)
rails (3.2.8)
railties (3.2.8)
rake (0.9.2.2)
rdoc (3.12)
rspec (2.11.0)
rspec-core (2.11.1)
rspec-expectations (2.11.2)
rspec-mocks (2.11.2)
rubygems-bundler (1.0.7)
rvm (1.11.3.5)
sprockets (2.4.5, 2.1.3)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.10)
tzinfo (0.3.33)

But when I run

 rspec my_test_file.rb

I get the following error:

/usr/lib/ruby/vendor_ruby/rspec/core/mocking/with_rspec.rb:1:in `require': no such file to load -- rspec/mocks (LoadError)
from /usr/lib/ruby/vendor_ruby/rspec/core/mocking/with_rspec.rb:1
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:116:in `require'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:116:in `mock_framework'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:376:in `configure_mock_framework'
from /usr/lib/ruby/vendor_ruby/rspec/core/command_line.rb:19:in `run'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:55:in `run_in_process'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:46:in `run'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:10:in `autorun'
from /usr/bin/rspec:4

This seems specific to rspec/mocks (unlike the other "no such file to load" ruby errors posted on SE). So what am I missing?


Solution

  • This isn't a rspec problem at all. My machine just didn't know where to look for the gem files. I had to update my .bashrc file as follows:

    PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
    [[ -s "/home/jason/.rvm/scripts/rvm" ]] && . "/home/jason/.rvm/scripts/rvm" # Load RVM function
    

    Everything works now.