2017-01-24 20 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();"