Rspec没有在Linux中加载ControllerMacros模块(在OS X上很好) [英] Rspec not loading ControllerMacros module in Linux (but fine on OS X)

查看:107
本文介绍了Rspec没有在Linux中加载ControllerMacros模块(在OS X上很好)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Devise和Rspec的Rails应用程序中编写了一些控制器测试。以下本指南,我在/ spec / support /目录中创建了一个 controller_macros.rb 。同一目录中还有一个 devise.rb 文件,其中:

  RSpec.configure do | config | 
config.include Devise :: TestHelpers,键入:controller
config.extend ControllerMacros,:type => :控制器
end

这两个文件都是在 spec_helper .rb 文件,使用以下行:

 目录[Rails.root.join(spec /支持/ ** / *。rb)]。每个{| f |要求f} 

现在这里是奇怪的:这种方法工作正常在OS X笔记本电脑上,但在我的Linux桌面上失败。他们都使用相同的RVM设置,相同的gemsets,相同的一切。



我在Linux中运行测试时遇到的错误是:

 未初始化的常量ControllerMacros(NameError)

显然,$ code> controller_macros.rb 模块在Linux中无法加载。我已经看到这样的答案,建议 config.extend 可以更改为 config.include ,但不会解决问题。



任何想法,我可以看看或我可以测试来帮助隔离问题?



我正在使用Rails 4.1.8和Rspec 3.1.7。

解决方案

我通过添加

  require Rails.root.join(spec / support / macros / controller_macros.rb)
/ pre>

到我的spec / support / devise.rb文件的顶部


I have written some controller tests in a Rails app that uses Devise and Rspec. Following this guide, I've created a controller_macros.rb in the /spec/support/ directory. There is also a devise.rb file in the same directory, with:

RSpec.configure do |config|
  config.include Devise::TestHelpers, type: :controller
  config.extend ControllerMacros, :type => :controller
end

Both files are being required in the spec_helper.rb file, with this line:

Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

Now here is what is weird: this approach works fine on an OS X laptop, but fails in my Linux desktop. They both use the same RVM settings, same gemsets, same everything.

The error I get when running the tests in Linux is:

uninitialized constant ControllerMacros (NameError)

Obviously the controller_macros.rb module is failing to load in Linux. I've seen SO answers suggesting that config.extend could be changed to config.include, but that doesn't fix the problem.

Any ideas where I can look or what I can test to help isolate the issue?

I'm using Rails 4.1.8 and Rspec 3.1.7.

解决方案

I solved this by adding

require Rails.root.join("spec/support/macros/controller_macros.rb")

to the top of my spec/support/devise.rb file

这篇关于Rspec没有在Linux中加载ControllerMacros模块(在OS X上很好)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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