无法让 RSpec 工作——“需要":无法加载此类文件 [英] Can't get RSpec to work -- 'require': cannot load such file

查看:47
本文介绍了无法让 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.

这是我的控制台输出:

(在/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)

推荐答案

失败是由以下行引起的:require "hello"

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

这一行告诉 Ruby 它需要搜索名为 hello.rb 的文件的加载路径.但是,当它查看加载路径时,却找不到那个文件.您应该删除该行并直接在规范文件中定义您的代码,或者创建一个 hello.rb 文件.

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.

较新版本的 RSpec(我相信 2.11+)会自动将子目录 lib 添加到加载路径.根据您的 Rakefile,您似乎也在加载当前实验室目录和子目录 solution.

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.

我猜你应该把你的解决方案放在 solution/hello.rb 中.

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

这篇关于无法让 RSpec 工作——“需要":无法加载此类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆