sunnyrjuneja
sunnyrjuneja

Reputation: 6123

Testing Grape with Minitest - What class to inherit from?

My rails application is using minitest. It's unclear to me what class I should be inheriting for my test. I was thinking ActionController::TestCase but that doesn't seem right because it isn't attached to a rails controller. Any suggestions?

Edit: Can't use MiniTest::Unit::TestCase because it doesn't include anything to the test the individual api end points.

Upvotes: 0

Views: 1041

Answers (2)

Mike Walkowiak
Mike Walkowiak

Reputation: 393

I am using ActionDispatch::IntegrationTest class

For example:

class ApiRequestTest < ActionDispatch::IntegrationTest
 test "sample response" do
  get "/api/v1/sample_request"
  assert_equal response.success?, true
  assert_equal response.code, 200
 end
end

Upvotes: 1

sunnyrjuneja
sunnyrjuneja

Reputation: 6123

Instead of inheriting from a specific minitest class, I just included test helpers from Rack.

class V0::YourAPI < ActiveSupport::TestCase
  include Rack::Test::Methods

  def app
    Rails.application
  end
end

Upvotes: 3

Related Questions