2017-01-24 32 views
0

我有以下的末我控制器Rspec的渲染爲直列:location.reload

** some code ** 
respond_to do |format| 
     format.js {render inline: "location.reload();" } 
end 

我不得不寫相同的RSPEC

expect(response).to render_template(:**what should be given here?**) 

或者是否還有其他方法來編寫RSPEC?

+0

的可能的複製http://stackoverflow.com/questions/10908547/rspec -rendering-text – 31piy

+0

是的,我發現這個問題之前檢查,但沒有得到任何想法實現它到我的代碼。 –

+0

鏈接的帖子中的答案告訴你到底你需要知道什麼。如果你看一下'response.body',你會得到響應的主體。那就是,標題之後的所有內容。所以在你的情況下,你會得到'location.reload();'作爲響應字符串,你可以比較。 – mroach

回答

0

感謝您的回覆,我才知道,我們應該指定的xhr代替get/post :method 所以這並獲得成功,

xhr :post, :schedule_message, params, format: :js 
expect(response.body).to eq "location.reload();"