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

会有一股神秘感。 提交于 2019-12-23 09:59:37

问题


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)

回答1:


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.




回答2:


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

I am using windows and an IDE



来源:https://stackoverflow.com/questions/16285326/cant-get-rspec-to-work-require-cannot-load-such-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!