stinkydiesel stinkydiesel - 7 months ago 34
Ruby Question

Can't get RSpec to work -- 'require': cannot load such file

I just spent three days of my life banging my head against the wall trying to figure out why a simple 'rake' would not pass my spec file.

If this happens to you: Do not have a space in any folder path!. Seriously. In fact do not have a space in anything you name from here on out.

Here is my console output:

(in

/Users/*****/Desktop/Learning Ruby/learn_ruby
)

$ rake
/Users/*******/Desktop/Learning Ruby/learn_ruby/00_hello/hello_spec.rb:116:
in `require': cannot load such file -- hello (LoadError)

Answer

The failure is caused by the line: require "hello"

This line tells Ruby that it needs to search the load path for a file named hello.rb. However, when it looks at the load path, it can't find that file. You should either remove that line and define your code directly in the spec file, or create a hello.rb file.

Newer versions of RSpec (2.11+ I believe) automatically add subdirectory lib to the load path. Based on your Rakefile it seems you are also loading the current lab directory and the subdirectory solution.

I'm guessing you're expected to put your solution in solution/hello.rb.

Comments