Permalink
Browse files

Refactors Perfection, every test, and adds Guard

  • Loading branch information...
1 parent 0d48a8b commit aa5fc01626098e2dc24134b86d76455aa50a8331 Alexander Kern committed May 22, 2011
Showing with 1,622 additions and 1,208 deletions.
  1. +0 −5 .autotest
  2. +5 −0 Gemfile
  3. +5 −0 Guardfile
  4. +1 −1 Rakefile
  5. +8 −8 lib/webbed/generic_message.rb
  6. +2 −0 lib/webbed/headers.rb
  7. +12 −12 lib/webbed/helpers/entity_headers_helper.rb
  8. +2 −2 lib/webbed/helpers/rack_request_helper.rb
  9. +4 −2 lib/webbed/helpers/rack_response_helper.rb
  10. +12 −12 lib/webbed/helpers/request_headers_helper.rb
  11. +9 −9 lib/webbed/helpers/response_headers_helper.rb
  12. +8 −11 lib/webbed/http_version.rb
  13. +18 −20 lib/webbed/media_type.rb
  14. +8 −7 lib/webbed/method.rb
  15. +24 −29 lib/webbed/request.rb
  16. +23 −25 lib/webbed/response.rb
  17. +14 −14 lib/webbed/status_code.rb
  18. +17 −0 test/support/assertions.rb
  19. +326 −0 test/support/runner.rb
  20. +8 −1 test/test_helper.rb
  21. +44 −0 test/webbed/generic_message_test.rb
  22. +31 −0 test/webbed/headers_test.rb
  23. +68 −0 test/webbed/helpers/entity_headers_helper_test.rb
  24. +151 −0 test/webbed/helpers/method_helper_test.rb
  25. +48 −0 test/webbed/helpers/rack_request_helper_test.rb
  26. +26 −0 test/webbed/helpers/rack_response_helper_test.rb
  27. +57 −0 test/webbed/helpers/request_headers_helper_test.rb
  28. +32 −0 test/webbed/helpers/request_uri_helper_test.rb
  29. +46 −0 test/webbed/helpers/response_headers_helper_test.rb
  30. +28 −0 test/webbed/helpers/scheme_helper_test.rb
  31. +0 −64 test/webbed/helpers/test_entity_headers_helper.rb
  32. +0 −147 test/webbed/helpers/test_method_helper.rb
  33. +0 −44 test/webbed/helpers/test_rack_request_helper.rb
  34. +0 −22 test/webbed/helpers/test_rack_response_helper.rb
  35. +0 −53 test/webbed/helpers/test_request_headers_helper.rb
  36. +0 −28 test/webbed/helpers/test_request_uri_helper.rb
  37. +0 −42 test/webbed/helpers/test_response_headers_helper.rb
  38. +0 −24 test/webbed/helpers/test_scheme_helper.rb
  39. +52 −0 test/webbed/http_version_test.rb
  40. +100 −0 test/webbed/media_type_test.rb
  41. +160 −0 test/webbed/method_test.rb
  42. +74 −0 test/webbed/request_test.rb
  43. +86 −0 test/webbed/response_test.rb
  44. +105 −0 test/webbed/status_code_test.rb
  45. +0 −42 test/webbed/test_generic_message.rb
  46. +0 −29 test/webbed/test_headers.rb
  47. +0 −47 test/webbed/test_http_version.rb
  48. +0 −98 test/webbed/test_media_type.rb
  49. +0 −158 test/webbed/test_method.rb
  50. +0 −70 test/webbed/test_request.rb
  51. +0 −72 test/webbed/test_response.rb
  52. +0 −106 test/webbed/test_status_code.rb
  53. +8 −4 webbed.gemspec
View
@@ -1,5 +0,0 @@
-require 'bundler/setup'
-
-Autotest.add_hook :initialize do |at|
- at.testlib = 'minitest/unit'
-end
View
@@ -1,2 +1,7 @@
source :gemcutter
+
+# This is temporary until guard-minitest accepts my patch.
+gem 'guard-minitest', :git => 'git://github.com/CapnKernul/guard-minitest.git'
+gem 'rb-fsevent'
+
gemspec
View
@@ -0,0 +1,5 @@
+guard 'minitest', :notify => true do
+ watch(/^test\/(.*)_test.rb/)
+ watch(/^lib\/(.*)\.rb/) { |m| "test/#{m[1]}_test.rb" }
+ watch(/^test\/test_helper.rb/) { 'test' }
+end
View
@@ -7,5 +7,5 @@ require 'rake/testtask'
Rake::TestTask.new do |t|
t.ruby_opts += ['-rubygems']
t.libs << 'test'
- t.pattern = 'test/**/test_*.rb'
+ t.pattern = 'test/**/*_test.rb'
end
@@ -1,33 +1,33 @@
module Webbed
- # Generic methods used for both {Request}'s and {Response}'s
+ # Generic methods used for both {Request}'s and {Response}'s.
#
# @abstract Include and implement `#status_line`.
module GenericMessage
- # The HTTP-Version of the message
+ # The HTTP-Version of the message.
#
# The method automatically converts the new value to an instance of
# {HTTPVersion} if it is not already one.
#
# @return [HTTPVersion]
attr_reader :http_version
- def http_version=(new_http_version)
- @http_version = Webbed::HTTPVersion.new(new_http_version)
+ def http_version=(http_version)
+ @http_version = Webbed::HTTPVersion.new(http_version)
end
- # The Headers of the message
+ # The Headers of the message.
#
# The method automatically converts the new value to an instance of
# {Headers} if it is not already one.
#
# @return [Headers]
attr_reader :headers
- def headers=(new_headers)
- @headers = Webbed::Headers.new(new_headers)
+ def headers=(headers)
+ @headers = Webbed::Headers.new(headers)
end
- # The Entity Body of the message
+ # The Entity Body of the message.
#
# @return [#to_s]
attr_accessor :entity_body
View
@@ -1,4 +1,6 @@
module Webbed
+ # Representation of HTTP headers.
+ #
# This class is stolen directly from Rack.
class Headers < Hash
def self.new(hash={})
@@ -11,9 +11,9 @@ def content_length
# Sets the Content-Length of the Entity (as defined in the Content-Length Header).
#
- # @param [#to_s] new_content_length
- def content_length=(new_content_length)
- headers['Content-Length'] = new_content_length.to_s
+ # @param [#to_s] content_length
+ def content_length=(content_length)
+ headers['Content-Length'] = content_length.to_s
end
# The Content-Location of the Entity (as defined in the Content-Location Header).
@@ -25,9 +25,9 @@ def content_location
# Sets the Content-Location of the Entity (as defined in the Content-Location Header).
#
- # @param [#to_s] new_content_location
- def content_location=(new_content_location)
- headers['Content-Location'] = new_content_location.to_s
+ # @param [#to_s] content_location
+ def content_location=(content_location)
+ headers['Content-Location'] = content_location.to_s
end
# The Content-MD5 of the Entity (as defined in the Content-MD5 Header).
@@ -39,9 +39,9 @@ def content_md5
# Sets the Content-MD5 of the Entity (as defined in the Content-MD5 Header).
#
- # @param [String] new_content_md5
- def content_md5=(new_content_md5)
- headers['Content-MD5'] = new_content_md5
+ # @param [String] content_md5
+ def content_md5=(content_md5)
+ headers['Content-MD5'] = content_md5
end
# The Content-Type of the Entity (as defined in the Content-Type Header).
@@ -53,9 +53,9 @@ def content_type
# Sets the Content-Type of the Entity (as defined in the Content-Type Header).
#
- # @param [#to_s] new_content_type
- def content_type=(new_content_type)
- headers['Content-Type'] = new_content_type.to_s
+ # @param [#to_s] content_type
+ def content_type=(content_type)
+ headers['Content-Type'] = content_type.to_s
end
end
end
@@ -29,7 +29,7 @@ def from_rack(rack_env)
headers['Content-Type'] = env.delete('CONTENT_TYPE')
headers['Content-Length'] = env.delete('CONTENT_LENGTH')
- request = new([method, request_uri, headers, entity_body], {
+ request = new(method, request_uri, headers, entity_body, {
:http_version => http_version,
:scheme => scheme
})
@@ -55,4 +55,4 @@ def self.included(base)
end
end
end
-end
+end
@@ -19,8 +19,10 @@ def to_rack
# Converts the Response to an array
#
- # The array has the same format as the one that you use in order to create
- # a Response.
+ # The array has a similar format to the format defined in the Rack specification with some modifications:
+ #
+ # 1. The Reason Phrase is included with the Status Code.
+ # 2. The Entity Body does not need to respond to `#each`.
#
# @return [Array]
# @note This will *not* return a Rack-compatible response array.
@@ -11,9 +11,9 @@ def host
# Sets the Host of the Request (as defined in the Host Header)
#
- # @param [String] new_host
- def host=(new_host)
- headers['Host'] = new_host
+ # @param [String] host
+ def host=(host)
+ headers['Host'] = host
end
# The From email of the Request (as defined in the From Header)
@@ -25,9 +25,9 @@ def from
# Sets the From email of the Request (as defined in the From Header)
#
- # @param [String] new_from
- def from=(new_from)
- headers['From'] = new_from
+ # @param [String] from
+ def from=(from)
+ headers['From'] = from
end
# The Max-Forwards of the Request (as defined in the Max-Forwards Header)
@@ -39,9 +39,9 @@ def max_forwards
# Sets the Max-Forwards of the Request (as defined in the Max-Forwards Header)
#
- # @param [#to_s] new_max_forwards
- def max_forwards=(new_max_forwards)
- headers['Max-Forwards'] = new_max_forwards.to_s
+ # @param [#to_s] max_forwards
+ def max_forwards=(max_forwards)
+ headers['Max-Forwards'] = max_forwards.to_s
end
# The Referer of the Request (as defined in the Referer Header)
@@ -53,9 +53,9 @@ def referer
# Sets the Referer of the Request (as defined in the Referer Header)
#
- # @param [#to_s] new_referer
- def referer=(new_referer)
- headers['Referer'] = new_referer.to_s
+ # @param [#to_s] referer
+ def referer=(referer)
+ headers['Referer'] = referer.to_s
end
end
end
@@ -11,9 +11,9 @@ def etag
# Sets the ETag of the Response (as defined in the ETag Header)
#
- # @param [String] new_etag
- def etag=(new_etag)
- headers['ETag'] = new_etag
+ # @param [String] etag
+ def etag=(etag)
+ headers['ETag'] = etag
end
# The Age of the Response (as defined in the Age Header)
@@ -25,9 +25,9 @@ def age
# Sets the Age of the Response (as defined in the Age Header)
#
- # @param [#to_s] new_age
- def age=(new_age)
- headers['Age'] = new_age.to_s
+ # @param [#to_s] age
+ def age=(age)
+ headers['Age'] = age.to_s
end
# The Location of the Response (as defined in the Location Header)
@@ -39,9 +39,9 @@ def location
# Sets the Location of the Response (as defined in the Location Header)
#
- # @param [#to_s] new_location
- def location=(new_location)
- headers['Location'] = new_location.to_s
+ # @param [#to_s] location
+ def location=(location)
+ headers['Location'] = location.to_s
end
end
end
View
@@ -1,4 +1,6 @@
module Webbed
+ # Representation of an HTTP HTTP Version.
+ #
# Webbed supports both primary versions of HTTP, HTTP/1.0 and HTTP/1.1.
# Although the use of HTTP/1.1 has been strongly encouraged since its creation
# in 1999, it remains relatively common for older command line tools (such as
@@ -20,11 +22,9 @@ module Webbed
class HTTPVersion
include Comparable
- # Regular expression for retrieving the major and minor version numbers from
- # an HTTP-Version
REGEX = /^HTTP\/(\d+)\.(\d+)$/
- # Creates a new HTTP-Version
+ # Creates a new HTTP-Version.
#
# Only HTTP/1.0 and HTTP/1.1 versions are cached. All other versions will be
# created at runtime each time this method is called.
@@ -42,7 +42,7 @@ def initialize(http_version)
end
end
- # Converts the HTTP-Version to a string according to RFC 2616
+ # Converts the HTTP-Version to a string according to RFC 2616.
#
# @example
# version = Webbed::HTTPVersion.new(1.1)
@@ -53,7 +53,7 @@ def to_s
@http_version
end
- # Converts the HTTP-Version to a float
+ # Converts the HTTP-Version to a float.
#
# @example
# version = Webbed::HTTPVersion.new('HTTP/1.1')
@@ -65,7 +65,7 @@ def to_f
"#{$1}.#{$2}".to_f
end
- # Compares the HTTP-Version to another HTTP-Version
+ # Compares the HTTP-Version to another HTTP-Version.
#
# @example
# version_1_1 = Webbed::HTTPVersion.new(1.1)
@@ -80,7 +80,7 @@ def <=>(other_http_version)
to_f <=> other_http_version.to_f
end
- # The major HTTP-Version number
+ # The major HTTP-Version number.
#
# @example
# version = Webbed::HTTPVersion.new('HTTP/6.9')
@@ -92,7 +92,7 @@ def major
$1.to_i
end
- # The minor HTTP-Version number
+ # The minor HTTP-Version number.
#
# @example
# version = Webbed::HTTPVersion.new('HTTP/4.2')
@@ -104,10 +104,7 @@ def minor
$2.to_i
end
- # HTTP/1.1
ONE_POINT_ONE = HTTPVersion.new(1.1)
-
- # HTTP/1.0
ONE_POINT_OH = HTTPVersion.new(1.0)
end
end
Oops, something went wrong.

0 comments on commit aa5fc01

Please sign in to comment.