辅助规范中未定义路径 [英] paths are not defined in helper specs
问题描述
我刚刚将 Rails 版本从 4.2.6 升级到 5.0.0.rc1 并使用 RSpec 版本 3.5.0.beta4>.
I've just upgraded my Rails version from 4.2.6 to 5.0.0.rc1 and using RSpec version 3.5.0.beta4.
问题是;我有一个方法,它在我的助手中调用 root_path
并且路径没有在助手规范中定义.版本升级后开始出现问题.
Problem is; I have a method which calls root_path
in my helper and paths are not defined in helper specs. Issue started after version upgrade.
运行辅助规范时出现以下错误;
I'm getting the following error when I run my helper spec;
NoMethodError:
undefined method `root_path' for #<#<Class:0x00000002749080>:0x00000011f3e650>
我尝试将以下行添加到我的助手中;
I've tried to add following line to my helper;
include Rails.application.routes.url_helpers
但现在错误如下;
NameError:
undefined local variable or method `default_url_options' for #<#<Class:0x00000001efa550>:0x0000001784ccd8>
如何为帮助程序规范或 default_url_options 定义路径帮助程序?
How can I define path helpers for helper specs or default_url_options?
推荐答案
这似乎是 RSpec 的一个错误,你可以在辅助规范中做的一件事就是自己添加必要的方法.
This seems like it may be a bug with RSpec, one thing you can do in your helper specs is add the necessary methods yourself.
describe MyHelper do
context "doing something" do
helper do
include Rails.application.routes.url_helpers
def default_url_options
{}
end
end
it "should work" do
expect(helper.run_it).to be_truthy
end
end
这篇关于辅助规范中未定义路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!