On Rails的2.3.2我試圖在功能測試Rails的功能測試assert_select覺得沒有什麼AJAX後發佈
def test_view
get :form
xhr :post, :add_to_cart, {:id => 1}
post :create, {:param => value}
assert_select 'title', 'Success!'
end
測試的視圖,但總是收到一個錯誤:
預計至少要1元素匹配「標題」,找到0. 不正確。
據我所知,你不能在xhr調用後使用'assert_select',但在這種情況下,我會在普通的post請求後執行它。
如果我把XHR請求
def test_view
get :form
post :create, {:param => value}
assert_select 'title', 'Success!'
end
然後它就像魅力。 我可以手動設置購物車(我在會話中存儲),但後來我不會真的測試視圖...
任何想法?
您可以使用功能測試來測試儘可能多的動作。這是有道理的,如果你想檢查一個動作是否成功,即post:update,get:show,format :: json –