0

Does anybody have any examples of using minitest and reacktest together to create request specs?

I want to be able to request a resource:

get '/api/resource', format: :json

And then test the response.

fearless_fool
  • 33,645
  • 23
  • 135
  • 217
dagda1
  • 26,856
  • 59
  • 237
  • 450

1 Answers1

0

You can simply use rack-test, as you suggested! Write your specs/unit-tests and with rack-test you can do:

def test_api_ressource_json
    get "/api/resource.json"

    assert last_response.ok?
    assert last_response.body.include?("something")

    # Test whatever you like with last_response.body
end

And that should be it.

PhilG
  • 1,253
  • 1
  • 9
  • 18
  • In Rails 4.2, including `require rails/test_help` first, say in your `test_helper.rb` file in the `test` folder, and then adding the Rack Test mixin via `include Rack::Test::Methods` inside your test class, is needed for tests to run using Rack's mock testing infrastructure. Then you get helper methods like `last_response`, `post`, `get`, etc. – sameers Feb 20 '15 at 04:32