- Published Date:Jun. 4, 2016
Article Summary
On Rails, developer can easy to implement ajax.
But, in case of doing rspec test, you must write code in a deffrent way from normal controller rspec test.
This article describes how toimplement "remote ajax rspec".
Environment
- ruby 2.2.4
- rails 4.2.5
- spec-rails 3.0.2
Noraml Controller Implementation
Generally, when developers implement rails controller of rspec, implement like the following example.
/app/controller/test_controller.rb
post :confirm, @params
Detail Explanation
- controller: test_controller.rb
- method : confirm
- method type : post
- parameter : @params
This is general implementation method of rails controller.
Let's change rspec test from this to "remote true" ajax method.
"remote true" ajax method Controller Implementation
Using xhr, Rspec can call ajax method of controller.
/app/controller/test_controller.rb
xhr :post, :confirm, @params
Very easy.
Enjoy Rspec Life.
See you.
0 件のコメント:
コメントを投稿