Last active
December 15, 2015 05:39
-
-
Save schuyler/5210852 to your computer and use it in GitHub Desktop.
Rack::Test doesn't pass a request body for GET requests?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if env["REQUEST_METHOD"] == "GET" | |
# merge :params with the query string | |
if params = env[:params] | |
params = parse_nested_query(params) if params.is_a?(String) | |
params.update(parse_nested_query(uri.query)) | |
uri.query = build_nested_query(params) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby test_get_body.rb | |
Run options: | |
# Running tests: | |
.F | |
Finished tests in 0.092553s, 21.6093 tests/s, 21.6093 assertions/s. | |
1) Failure: | |
test_02_get_body(GetBodyTest) [test_get_body.rb:31]: | |
<"wtf\n"> expected but was | |
<"\n">. | |
2 tests, 2 assertions, 1 failures, 0 errors, 0 skips |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'test/unit' | |
require 'rack/test' | |
ENV['RACK_ENV'] = 'test' | |
class GetBody < Sinatra::Application | |
get '/' do | |
request.body.read + "\n" | |
end | |
post '/' do | |
request.body.read + "\n" | |
end | |
end | |
class GetBodyTest < Test::Unit::TestCase | |
include Rack::Test::Methods | |
def app | |
GetBody | |
end | |
def test_01_post_body | |
r = post '/', "wtf" | |
assert_equal "wtf\n", last_response.body | |
end | |
def test_02_get_body | |
r = get '/', 'wtf' | |
assert_equal "wtf\n", last_response.body | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment