gpt4 book ai didi

ruby-on-rails - rails : How to test a controller with routes defined via a scope?

转载 作者:行者123 更新时间:2023-12-04 16:35:53 25 4
gpt4 key购买 nike

给定路线:

  scope :path => 'shipping_reports', :controller => 'ShippingReports', :as => 'shipping_reports' do
get 'index'
end

和以下测试:

class ShippingReportsControllerTest < ActionController::TestCase
test "routing" do
assert_routing '/shipping_reports/index', { :controller => "ShippingReports", :action => "index" }
end

test 'index' do
get :index
assert_response :success
end
end

第一次测试通过,第二次失败:

ActionController::RoutingError: No route matches {:controller=>"shipping_reports"}

有人知道我如何才能通过该测试吗?

最佳答案

我设法完成这项工作的唯一方法是将我的路线更改为:

controller 'shipping_reports', :path => '/shipping_reports', :as => 'shipping_reports'

它读起来更好,测试通过了,但我仍然想知道如何测试问题路径...

关于ruby-on-rails - rails : How to test a controller with routes defined via a scope?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13601089/

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