0

I try to setup a new Rails 5.2.1 "Api only"-app.

While following some tutorials I was surprised that a lot of them (if not all) are only writing request specs. What I also found is the type: :api option in some of their tutorials.

What is the difference in type: :request and type: :api ?

  1. So I am a bit confused. Is this common practice to drop controller specs?
  2. Or is logic tested in request specs instead of controller specs?, because of no view logic?

    RSpec.describe 'Authentications', type: :request do
     ...
    end
    
    RSpec.describe UsersController, type: :api do
     ...
    end
    

Thank you in advance

Jan
  • 12,992
  • 9
  • 53
  • 89
  • 1
    controller tests are shallow and do not go through middleware/routes so most folks avoid them now. I don't know what `api` is, it's probably a custom attribute. – Anthony Nov 26 '18 at 17:55
  • @Anthony, yes you are right it seems to be that "api" is a custom type people are using. I try now to avoid controller specs, but they are still generated by scaffolding – Jan Nov 30 '18 at 11:12
  • This seems relevant: [Controller Specs vs Request Specs](https://stackoverflow.com/questions/40851705/controller-specs-vs-request-specs). Consensus was that controller specs are passe. – aridlehoover Dec 12 '18 at 11:07

0 Answers0