bey*_*gan 6 rspec ruby-on-rails
我刚刚将我的Rails版本从4.2.6升级到5.0.0.rc1并使用RSpec版本3.5.0.beta4.
问题是; 我有一个调用root_path我的帮助器的方法,并且没有在辅助规范中定义路径.版本升级后问题开始.
当我运行我的帮助规范时,我收到以下错误;
NoMethodError:
undefined method `root_path' for #<#<Class:0x00000002749080>:0x00000011f3e650>
Run Code Online (Sandbox Code Playgroud)
我试图在我的助手上添加以下内容;
include Rails.application.routes.url_helpers
Run Code Online (Sandbox Code Playgroud)
但现在错误如下;
NameError:
undefined local variable or method `default_url_options' for #<#<Class:0x00000001efa550>:0x0000001784ccd8>
Run Code Online (Sandbox Code Playgroud)
如何为辅助规范或default_url_options定义路径助手?
这看起来可能是 RSpec 的一个错误,您可以在帮助器规范中做的一件事就是自己添加必要的方法。
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
491 次 |
| 最近记录: |