[RSpec] コントローラーのテストで Ajax リクエストを送る方法
RSpec で、コントローラーのテストで Ajax リクエストを送るには xhr を使えば良いらしいです。
■ Ajax GET
xhr :get, :index |
■ Ajax POST
xhr :post, :create, id: 1 |
下記のような感じで使えます。カンタンですね!
describe "Ajax GET 'index'" do it "returns http success" do xhr :get, :index response.should be_success end end |
・[参考]:ruby on rails – How do you test an AJAX request with RSpec/RoR? – Stack Overflow