rspec_rails_4 icon indicating copy to clipboard operation
rspec_rails_4 copied to clipboard

Ch.5 - JSON API should be tested in request specs?

Open JunichiIto opened this issue 10 years ago • 2 comments

You are testing JSON API in controller specs, but some people say it should be tested in request specs:

http://matthewlehner.net/rails-api-testing-guidelines/

Use RSpec Request Specs

Since we’ve established that we’ll be using Rack::Test to drive the tests, RSpec request specs make the most sense. There’s no need to get fancy and add extra weight to your testing tools for this.

Request specs provide a thin wrapper around Rails’ integration tests, and are designed to drive behavior through the full stack, including routing (provided by Rails) and without stubbing (that’s up to you).

I think this idea is reasonable, so it might be worth moving it to request specs.

JunichiIto avatar Mar 27 '14 08:03 JunichiIto

That's the plan for the Rails 4/RSpec 3 version.

ruralocity avatar Mar 28 '14 01:03 ruralocity

Okay, it's a good news!

JunichiIto avatar Mar 28 '14 01:03 JunichiIto