2015-04-27 62 views
0

我正從RSpec轉換到MiniTest,並且遇到了一些困難。我一直在下面的一些例子,我發現:爲什麼在MiniTest中有兩種控制器測試?

class ArticlesControllerTest < ActionController::TestCase 
    test "should get index" do 
    get :index 
    assert_response :success 
    assert_not_nil assigns(:articles) 
    end 
end 

所以這是從的ActionController :: TestCase的,這是有道理的繼承的類。

但後來也有其他的例子是這樣的:

require 'test_helper' 

describe ThingsController do 
    describe "#create" do 

    it do "valid" 
     login_user 
     post :create, { catalog: { name: "My Thing", description: "Description of my thing."}} 
     assert_redirected_to thing_path(Thing.last) 
    end 

    end 
end 

爲什麼這兩種風格不同?我使用第二個例子,我的重定向沒有一個像我的開發系統一樣工作。試圖達到它的底部。

+2

首先是經典的測試::單位的風格,第二個更Rspec的味道。不過,除了聲明測試的方式之外,它們在功能上應該是相同的。 – tadman

回答

2

第一個是MINITEST ::單元測試語法解釋here

二更像是Rspec的語法,你可以使用minitest-spec-rails寶石爲

相關問題