我在我的 REST Api 应用程序中启动单元测试实现。我使用版本主义 gem。
所以,我有一个这样的类:Api::V0_1_0::TestController
class Api::V0_1_0::TestController < Api::V0_1_0::BaseController
def test
respond_with({
:message => "done"
})
end
end
routes.rb
(没有所有路线,但只是必要的):
MyApp::Application.routes.draw do
# -----------------------------------------------------------------------------------------------------------------------------------------
# ApiVersions
#
scope :module => "api",
:defaults => {:format => "json"} do
# ---------------------------------------------------------------------------------------------------
# V0.1.0
# Default version
#
api_version :module => "V0__1__0",
:header => "X-Version", :value => "0.1.0" do
# Test controller
get "/test" => "test#test"
end
# ---------------------------------------------------------------------------------------------------
# ---------------------------------------------------------------------------------------------------
# V0.1.1
# Default version
#
api_version :module => "V0__1__1",
:header => "X-Version", :value => "0.1.1" do
# Test Controller
get "/test" => "test#test"
end
# -----------------------------------------------------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------------------------------------
# ActiveAdmin routes
#
ActiveAdmin.routes(self)
devise_for :admin_users, ActiveAdmin::Devise.config
# -----------------------------------------------------------------------------------------------------------------------------------------
end
功能测试文件:
class Api::V0_1_0::TestControllerTest < ActionController::TestCase
test "should get test" do
get :test
assert_response :success
end
end
当我启动rake test:functionals
. 我有这个错误:
没有路由匹配 {:controller=>"api/v0_1_0/test", :action=>"test"}
当我启动时rake routes
,我有:
test GET /test(.:format) {:format=>"json", :controller=>"api/V0__1__0/test", :action=>"test"}
带有双下划线 forV0__1__0
和 not V0_1_0
。
我不知道如何解决这个问题。
编辑:我添加了routes.rb
.
注意:我在这里也发布了一个问题:https ://github.com/bploetz/versionist/issues/9