1

I can't really get my head around it. Let's say I have a controller as follows:

get :test do
  status 201
  body "test"
end

after do
  status 404
  body "not found"
end

Now, visiting /test produces response with status 404 and body "test". How do I do this properly?

Also, I noticed I can omit body like

get :test do
  status 201
  "test"
end

and the response stays the same, but calling response.body later returns empty array instead of the actual content. Why is this so confusing, is that some kind of inconsistency between Padrino and Sinatra? What am I missing here, anyone care to explain?

jahmaican
  • 162
  • 2
  • 8
  • What are you trying to achieve? – Sir l33tname Apr 14 '15 at 14:03
  • 1
    if you're doing this in an actual test scope (such as with capybara) - then this is a fairly well known issue. response.body does not update quickly enough to give meaningful data during testing – dax Apr 15 '15 at 20:20

1 Answers1

0

I presume you want to override the sefault Sinatra not found message ? You could do that like this

get :test do
  "test"
end

error Sinatra::NotFound do
  content_type 'text/plain'
  [404, 'Not Found']
end
peter
  • 41,770
  • 5
  • 64
  • 108