0

在 config/routes.rb 中:

match 'app_config/:version' => "application#appconfig"

测试/功能/application_controller_test.rb:

require 'test_helper'
class ApplicationControllerTest < ActionController::TestCase
  test "app config" do
    get "/app_config/v2"
    assert_response :success
  end
end

rake test

  1) Error:
test_app_config(ApplicationControllerTest):
ActionController::RoutingError: No route matches {:controller=>"application", :action=>"/app_config/v2"}

$ curl localhost:3000/app_config/v2有效,并返回我期望的响应,并按rake routes预期显示路线。知道发生了什么,或者如何进一步调查?这基本上是项目中唯一的代码。

4

1 回答 1

1

get方法不采取路线。它需要一个动作名称和一个参数的哈希值。

如果你想测试这个动作,你的测试应该是这样的:

test "for success" do
  get :appconfig, :version => "v2"
  assert_response :success
end

如果您想测试路由,文档中有一个教程

test "should route to appconfig" do
  assert_routing '/app_config/v2', { :controller => "application", :action => "appconfig", :version => "v2" }
end
于 2012-12-06T23:35:57.453 回答