2015-01-04 48 views
0

我的rails應用程序正在使用minitest。我不清楚我應該爲我的測試繼承什麼課程。我在想ActionController :: TestCase,但這看起來不正確,因爲它沒有連接到軌道控制器。有什麼建議麼?用Minitest測試葡萄 - 從哪個類繼承?

編輯: 不能使用MiniTest::Unit::TestCase,因爲它不包含任何東西來測試個別api結束點。

+0

我花了30秒,谷歌 「MINITEST」,它看起來像答案應該是'MINITEST ::單位:: TestCase的'? – Adrian

+0

對不起,如果我聽起來對你感到高興,我不是故意的。你的「api終點」是什麼意思? – Adrian

+0

Grape是Ruby創建HTTP API的庫。您可以在一定程度上將它集成到導軌中。在編寫測試時,您需要在HTTP端點上使用GET,POST。 ActionController :: TestCase爲你提供了一個調用控制器和動作的get方法,但在這種情況下不起作用。我正在尋找什麼繼承,所以我可以得到一個get/post方法和任何其他HTTP幫助。 – sunnyrjuneja

回答

3

而不是從一個特定的minitest類繼承,我只包括來自Rack的測試助手。

class V0::YourAPI < ActiveSupport::TestCase 
    include Rack::Test::Methods 

    def app 
    Rails.application 
    end 
end 
0

我使用ActionDispatch::IntegrationTest

例如:

class ApiRequestTest < ActionDispatch::IntegrationTest 
test "sample response" do 
    get "/api/v1/sample_request" 
    assert_equal response.success?, true 
    assert_equal response.code, 200 
end 
end