2017-11-17 115 views
1

我有兩個測試。每個的結果取決於用戶數量。Rails:如何忽略用於單一測試的燈具

目前,我沒有用戶裝置。第二個測試在其設置方法中引入了一個用戶。如果db中有用戶,則第一個測試會失敗。

但我想介紹users.yml中的用戶。因此,由於現有用戶,第一次測試將失敗。有什麼辦法可以指導這個測試忽略fixtures/users.yml

require 'test_helper' 

class UsersSignupTestWithoutExistingUsers < ActionDispatch::IntegrationTest 
    test "Signup page is accessible" do 
    get new_user_registration_path 
    assert_response :success 
    end 
end 

class UsersSignupTestWithExistingUsers < ActionDispatch::IntegrationTest 
    def setup 
    post user_registration_path, params: {user: { 
     email:     "[email protected]", 
     password:    "password", 
     password_confirmation: "password" 
    }} 
    end 

    test "Signup page will redirect" do 
    get new_user_registration_path 
    assert_response :redirect 
    end 
end 

回答

0

於不需要用戶在數據庫中,你可以存根,看起來在數據庫中的用戶,使其返回該測試空集的方法測試。