Controller Specs vs Request Specs?

前端 未结 3 1219
伪装坚强ぢ
伪装坚强ぢ 2021-02-03 19:29

I\'m working on a rails API and I\'m now planning on writing some RSpec tests for the controllers. I\'ve been reading around and I haven\'t been able to figure out what the act

3条回答
  •  青春惊慌失措
    2021-02-03 20:17

    Indeed, the RSpec team officially states controller specs are now obsolete.

    http://rspec.info/blog/2016/07/rspec-3-5-has-been-released/

    For new Rails apps: we don't recommend adding the rails-controller-testing gem to your application. The official recommendation of the Rails team and the RSpec core team is to write request specs instead. Request specs allow you to focus on a single controller action, but unlike controller tests involve the router, the middleware stack, and both rack requests and responses. This adds realism to the test that you are writing, and helps avoid many of the issues that are common in controller specs. In Rails 5, request specs are significantly faster than either request or controller specs were in rails 4, thanks to the work by Eileen Uchitelle1 of the Rails Committer Team.

提交回复
热议问题