如何从黄瓜场景中访问初始化常量?
我有一个 Cucumber 功能,在运行它时,我收到以下错误消息:
uninitialized constant ApplicationController::CONFIG (NameError)
./app/controllers/application_controller.rb:25:in `xxx'
CONFIG 常量是 config/initializers/config.rb 中定义的哈希。在开发/生产模式下使用应用程序时,它的定义是正确的,但显然从黄瓜上下文调用时,它的定义不正确。
我尝试使用以下代码在功能/支持中添加初始化程序文件:
Dir[Rails.root + "config/initializers/*.rb"].each do |file|
require file
end
但它不会改变任何内容。
你对此有何看法?
谢谢
I have got a cucumber feature and when running it, I get the following error message:
uninitialized constant ApplicationController::CONFIG (NameError)
./app/controllers/application_controller.rb:25:in `xxx'
That CONFIG constant is a hash defined in config/initializers/config.rb. It is defined correctly when using the application in development/production mode but apparently it's not when called from a cucumber context.
I tried to add an initializer file in features/support with the following code:
Dir[Rails.root + "config/initializers/*.rb"].each do |file|
require file
end
But it doesn't change anything.
What do you think about it?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
黄瓜似乎没有在您的步骤中加载您的环境。
如果您直接在功能/步骤中需要配置文件怎么办?
It seems Cucumber don't load your environment within your steps.
What if you require your config files directly in features/steps?