Rspec integration / request specifications and controller specifications with a focus on JSON api

I accepted an application that has some testing coverage, but most tests are of mixed quality. Most applications work against the JSON api. I was going to write request specifications, but authentication and sending POST with authentication data were not trivial. For testing JSON api would be more appropriate controller specifications?

For instance,

match 'api/login-mobile' => 'api#login_mobile', :as => :login_mobile, :defaults => {:format => 'json' } 

It would seem trivial, but integration with capybara would be required. In addition, capybara does not send session data natively and will require

 page.driver.post ..... 

I get integration tests to test user interface interaction, but this seems like a really bad model for testing JSON api. Am I missing something? Or is there a tutorial for conducting integration / requeset tests? Now I am considering a discourse, and almost all of their tests are controllers .... If the integration / query specifications were bee knees, why would they make this decision?

thanks in advance

+6
source share
1 answer

I would do tests in an integration style, somewhat like this SO post .

Interaction with the API endpoint via JSON is higher than just a controller, so I will probably use the feature and scenario block descriptors provided by RSpec. (example here ).

Functionally, it is not very different from the controller specification, but it helps to push you to the scenario / characteristic type of testing, and not to unit-level testing.

-1
source

All Articles