我在我的REST Api應用程序中啓動單元測試實現。 我使用versionist gem。Rails單元測試功能和下劃線模塊
所以,我有一個名爲像這樣的類: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
。 我有這樣的錯誤:
沒有路由匹配{:控制器=> 「API/v0_1_0 /測試」:動作=> 「測試」}
當我啓動rake routes
,我有:
test GET /test(.:format) {:format=>"json", :controller=>"api/V0__1__0/test", :action=>"test"}
隨着V0__1__0
而不是V0_1_0
雙下劃線。
我不知道如何解決這個問題。編輯:我添加routes.rb
。
注:我也張貼在這裏的一個問題:https://github.com/bploetz/versionist/issues/9
你能發佈你的routes.rb嗎? – Domness 2012-04-24 13:34:12
我已經編輯我的文章 – 2012-04-24 13:39:56