lib/rack/mock.rb in rack-1.2.8 vs lib/rack/mock.rb in rack-1.3.0.beta
- old
+ new
@@ -139,52 +139,47 @@
# Rack::MockResponse provides useful helpers for testing your apps.
# Usually, you don't create the MockResponse on your own, but use
# MockRequest.
- class MockResponse
- def initialize(status, headers, body, errors=StringIO.new(""))
- @status = status.to_i
+ class MockResponse < Rack::Response
+ # Headers
+ attr_reader :original_headers
+ # Errors
+ attr_accessor :errors
+
+ def initialize(status, headers, body, errors=StringIO.new(""))
@original_headers = headers
- @headers = Rack::Utils::HeaderHash.new
- headers.each { |field, values|
- @headers[field] = values
- @headers[field] = "" if values.empty?
- }
+ @errors = errors.string if errors.respond_to?(:string)
+ @body_string = nil
- @body = ""
- body.each { |part| @body << part }
-
- @errors = errors.string if errors.respond_to?(:string)
+ super(body, status, headers)
end
- # Status
- attr_reader :status
-
- # Headers
- attr_reader :headers, :original_headers
-
- def [](field)
- headers[field]
- end
-
-
- # Body
- attr_reader :body
-
def =~(other)
- @body =~ other
+ body =~ other
end
def match(other)
- @body.match other
+ body.match other
end
+ def body
+ # FIXME: apparently users of MockResponse expect the return value of
+ # MockResponse#body to be a string. However, the real response object
+ # returns the body as a list.
+ #
+ # See spec_showstatus.rb:
+ #
+ # should "not replace existing messages" do
+ # ...
+ # res.body.should == "foo!"
+ # end
+ super.join
+ end
- # Errors
- attr_accessor :errors
-
-
- include Response::Helpers
+ def empty?
+ [201, 204, 304].include? status
+ end
end
end