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.

1

1 Answer 1

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.

1
  • 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, 2015 at 4:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.