When I use controller/request specs and when I don't
07-Nov-2020 2090
Every so often I come across a question of controller or request specs and when to use them.Before I can address this I need to get some terminology out of the way. In RSpec there are controller tests and request specs which are similar but subtly different. Let’s talk about what the difference is.Controller specs vs. request specsAs of (apparently) July 2016, the Rails team and the RSpec core team recommend using request specs instead of controller specs. Here’s why, in their words: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.If I had to extract a TL.
When I use controller/request specs and when I don't #ruby #rubydeveloper #rubyonrails #controller/request #specs #don't https://rubyonrails.ba/link/when-i-use-controller-request-specs-and-when-i-don-t