Content type is forced to text/html in non-test mode #500
Description
I have a super simple app that serves up json. I'm using the before
and not_found
hooks to set the content type and response bodies for 404s:
before { content_type "application/json;charset=utf-8" }
not_found { JSON.dump("error" => "Not Found") }
I wrote a test for this with rack-test asserting the content type was "application/json" and it worked. Then I booted the app and hit an undefined endpoint and got a content-type of "text/html". After digging into the problem, it appears that the value of RACK_ENV
affects this. In my test environment, it was set to test
. When I booted my app it defaulted to development
.
It seems wrong that sinatra would honor the content type I have explicitly set in the test environment but not in other environments. It makes it hard to trust your tests when it behaves differently in that environment :(.
I put together a gist demonstrating the issue:
https://gist.github.com/2313727
Notice that the test passes when RACK_ENV=test
is set but fails otherwise.