Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add tests for a POST request.

  • Loading branch information...
commit 93ac35f8da15bb28efd1e400653cbedd1569d975 1 parent 6074002
@Manfred authored
Showing with 22 additions and 5 deletions.
  1. +6 −1 test/functional_test.rb
  2. +1 −1  test/server.rb
  3. +15 −3 test/shl_test.rb
View
7 test/functional_test.rb
@@ -1,8 +1,13 @@
require File.expand_path('../helper', __FILE__)
class SHLFunctionalTest < Test::Unit::TestCase
- def test_request_into_the_wide_world
+ def test_get_request_into_the_wide_world
response = SHL(:verb => :get, :url => 'http://google.com')
assert response.body.include?('html')
end
+
+ def test_post_request_into_the_wide_world
+ response = SHL(:verb => :post, :url => 'http://google.com/?q=shl')
+ assert response.body.include?('html')
+ end
end
View
2  test/server.rb
@@ -3,7 +3,7 @@
class Webserver
N = "\r\n"
PORT = 32776
- REQUEST_LINE = /^(GET)\s+([^\s]+)\s+HTTP\/1\.1\s*$/
+ REQUEST_LINE = /^(GET|POST)\s+([^\s]+)\s+HTTP\/1\.1\s*$/
CODES_AND_PHRASES = {
:ok => '200 OK',
:not_found => '404 Not Found',
View
18 test/shl_test.rb
@@ -13,8 +13,14 @@ def setup
end
def test_returns_a_request_line
- assert_equal "GET / HTTP/1.1",
- @request.request_line
+ [
+ [:get, "GET"],
+ [:post, "POST"]
+ ].each do |verb, expected|
+ @request.verb = verb
+ assert_equal "#{expected} / HTTP/1.1",
+ @request.request_line
+ end
end
def test_returns_serialized_headers
@@ -27,12 +33,18 @@ def test_returns_serialized_body
@request.serialized_body
end
- def test_request
+ def test_get_request
response = SHL(:verb => :get, :url => BASE_URL)
assert_equal "OK!",
response.body
end
+ def test_post_request
+ response = SHL(:verb => :post, :url => BASE_URL)
+ assert_equal "OK!",
+ response.body
+ end
+
# --- Tear down the club
class << self
Please sign in to comment.
Something went wrong with that request. Please try again.