How do you test an AJAX request with RSpec/RoR?

后端 未结 3 1829
忘掉有多难
忘掉有多难 2020-12-28 11:46

I\'m fairly new to RoR and recently started learning BDD/Rspec for testing my application. I\'ve been looking for a way to spec an AJAX request, but so far I haven\'t found

3条回答
  •  执念已碎
    2020-12-28 12:26

    If you're talking about testing it inside your controller specs, where you normally call

    get :index
    

    to make an HTTP request to the index action, you would instead call

    xhr :get, :index
    

    to make an XmlHttpRequest (AJAX) request to the index action using GET.

提交回复
热议问题