且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

RSpec 找不到我的控制器未初始化的常量

更新时间:2021-12-02 22:36:25

我添加了

require File.expand_path("../../config/environment", __FILE__)

到 spec_helper.rb 文件,这解决了错误.我不确定为什么 spec_helper 需要这个,但我认为这与 Rails 定位文件相对于另一个文件的路径的能力有关,我怀疑这会扰乱 RSpec 找到合适的控制器、模型、等

to the spec_helper.rb file and this resolved the error. I'm not sure why the spec_helper needs this, but I think it has something to do with Rails' ability to locate a file's path relative to another file, and I suspect this was messing up RSpec's ability to find the appropriate controllers, models, etc.

我做了一些研究,发现以前我们在 RSpec 2.14 上,现在在 3.2 上,我认为 rspec 使用这两个文件的方式可能存在一些差异.在我们旧的 spec_helper 文件中,我们有这一行:

I did some research and found that previously we were on RSpec 2.14 and we're now on 3.2, and I think there may be some differences in the way rspec uses these two files. In our old spec_helper file we had this line:

require File.expand_path("../../config/environment", __FILE__)