Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

ruby

rspec

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)
like image 640
tbone Avatar asked Apr 29 '13 18:04

tbone


2 Answers

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.

like image 109
Aaron K Avatar answered Sep 21 '22 03:09

Aaron K


What worked for me was changing the require statement to a require_relative

I am using windows and an IDE

like image 42
Adrian Badarau Avatar answered Sep 22 '22 03:09

Adrian Badarau