gpt4 book ai didi

ruby-on-rails - Rspec:引擎路径助手

转载 作者:行者123 更新时间:2023-12-02 22:04:23 25 4
gpt4 key购买 nike

路线:

Users::Engine.routes.draw do
get "test/step1", to: "test#step1", as: "step1"
get "test/step2", to: "test#step2", as: "step2"
end

Controller 规范:

describe Users::Test do
it "sample" do
get :test2, use_route: "users"
response.should redirect_to users.step1_path
end
end

rake 路:

Routes for Users::Engine:
step1 GET /test/step1(.:format) users/test#step1
step2 GET /test/step2(.:format) users/test#step2
....

我有错误:

Failure/Error: response.should redirect_to users.step1_path
NameError:
undefined local variable or method `users' for #<RSpec::Core::ExampleGroup::Nested_9::Nested_3:0xb7496f8>

我如何在 Controller 规范中使用像 users.step1_path 这样的引擎路径助手?

最佳答案

我正在使用 Rails 4 和 Rspec 3。我通过在规范中包含路由助手来让它工作,如下所示:

describe Users::Test do

include Users::Engine.routes.url_helpers

it "sample" do
get :test2
response.should redirect_to step1_path
end

end

关于ruby-on-rails - Rspec:引擎路径助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16360501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com