2

I have the following Sinatra app:

class MyFakeAPI < Sinatra::Base
  get "/" do
    "Hello World"
  end

  get "widgets" do
    # code that renders widgets.json
  end
end

I am attempting, when running integration tests, to serve this Sinatra app for requests to /api to stand in for a lightly used third party api.

The fake api works great when invoked via web mock's to_rack method.

However when I mount like this:

if Rails.env.test?
  mount MyFakeAPI.new => "/api"
end

Visiting /api renders hello world, but visiting /api/widgets generates a rails routing error.

How do I route all traffic under /api to the Sinatra app?

1 Answer 1

3

So the problem ended up being that I missed the leading / before widgets in the get route, so it wasn't being routed correctly.

1

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.