Skip to content
Permalink
Browse files

Add new `Response.[]` and `MockResponse.[]` which are very similar. F…

…ixes #1094.
  • Loading branch information
ioquatix committed Jan 10, 2020
1 parent 256ea3e commit 4e10997915ca7c529b5730de321c9ceefb16e4f9
Showing with 30 additions and 0 deletions.
  1. +4 −0 lib/rack/mock.rb
  2. +4 −0 lib/rack/response.rb
  3. +11 −0 test/spec_mock.rb
  4. +11 −0 test/spec_response.rb
@@ -157,6 +157,10 @@ def self.env_for(uri = "", opts = {})
# MockRequest.

class MockResponse < Rack::Response
class << self
alias [] new
end

# Headers
attr_reader :original_headers, :cookies

@@ -21,6 +21,10 @@ module Rack
# Your application's +call+ should end returning Response#finish.

class Response
def self.[] (status, headers, body)
self.new(body, status, headers)
end

attr_accessor :length, :status, :body
attr_reader :header
alias headers header
@@ -248,6 +248,17 @@
end

describe Rack::MockResponse do
it 'has standard constructor' do
headers = { "header" => "value" }
body = ["body"]

response = Rack::MockResponse[200, headers, body]

response.status.must_equal 200
response.headers.must_equal headers
response.body.must_equal body.join
end

it "provide access to the HTTP status" do
res = Rack::MockRequest.new(app).get("")
res.must_be :successful?
@@ -6,6 +6,17 @@
require 'stringio'

describe Rack::Response do
it 'has standard constructor' do
headers = { "header" => "value" }
body = ["body"]

response = Rack::Response[200, headers, body]

response.status.must_equal 200
response.headers.must_equal headers
response.body.must_equal body
end

it 'has cache-control methods' do
response = Rack::Response.new
cc = 'foo'

0 comments on commit 4e10997

Please sign in to comment.
You can’t perform that action at this time.