0
我有我想測試的Rails UJS發起的AJAX調用。具體來說,我已經使用Rails UJS ajax事件來提供錯誤情況。Stub Rails UJS/Ajax響應狀態以測試Rspec /水豚功能測試中的返回消息
我想測試他們,但我不知道怎麼告訴rspec的/水豚爲「存根」,並承擔錯誤代碼
$("button").
on('ajax:error',function(event,xhr, status, error){
if(status == "timeout") {
var msg;
msg = Messenger().post({
message: "This is taking too long"
});
} else {
var msg;
msg = Messenger().post({
message: "it seems there is a bug. Please try again."
});
};
});
我想這樣做如下:
describe "test returning error message", js: true do
it "should be successful" do
visit deal_page_path(deal)
first('a.button').click
stub(:xhr.status) = "timeout"
expect(page).to have_content('This is taking too long')
end
end
如何做到這一點?
注意:ajax請求是內部的,它們不會去第三方API或服務(例如,前者的facebook)。
謝謝,我偶然發現了puffung比利。但似乎更重視http而不是樁鐵路ujs ajax模態。我可以和膨化比利一起做嗎? – Mathieu
@Mathieu。你正在尋找僞造一個http請求的狀態響應,這正是膨化比利讓你做的 –
謝謝。 – Mathieu