Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use to_enum instead of Enumerator.new to remove Ruby 2.0 warnings

This commit avoid warn message
Enumerator.new without a block is deprecated; use Object#to_enum
  • Loading branch information...
commit a69b08e4c2cc132b99e2c29f41d43bc3106a9639 1 parent 3d30e8f
@spastorino spastorino authored
View
6 test/spec_chunked.rb
@@ -3,18 +3,16 @@
require 'rack/mock'
describe Rack::Chunked do
- ::Enumerator = ::Enumerable::Enumerator unless Object.const_defined?(:Enumerator)
-
def chunked(app)
proc do |env|
app = Rack::Chunked.new(app)
response = Rack::Lint.new(app).call(env)
# we want to use body like an array, but it only has #each
- response[2] = Enumerator.new(response[2]).to_a
+ response[2] = response[2].to_enum.to_a
response
end
end
-
+
before do
@env = Rack::MockRequest.
env_for('/', 'HTTP_VERSION' => '1.1', 'REQUEST_METHOD' => 'GET')
View
9 test/spec_content_length.rb
@@ -1,19 +1,16 @@
-require 'enumerator'
require 'rack/content_length'
require 'rack/lint'
require 'rack/mock'
describe Rack::ContentLength do
- ::Enumerator = ::Enumerable::Enumerator unless Object.const_defined?(:Enumerator)
-
def content_length(app)
Rack::Lint.new Rack::ContentLength.new(app)
end
-
+
def request
Rack::MockRequest.env_for
end
-
+
should "set Content-Length on Array bodies if none is set" do
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
response = content_length(app).call(request)
@@ -81,6 +78,6 @@ def to_ary; end
response = content_length(app).call(request)
expected = %w[one two three]
response[1]['Content-Length'].should.equal expected.join.size.to_s
- Enumerator.new(response[2]).to_a.should.equal expected
+ response[2].to_enum.to_a.should.equal expected
end
end
View
17 test/spec_deflater.rb
@@ -1,4 +1,3 @@
-require 'enumerator'
require 'stringio'
require 'time' # for Time#httpdate
require 'rack/deflater'
@@ -7,12 +6,10 @@
require 'zlib'
describe Rack::Deflater do
- ::Enumerator = ::Enumerable::Enumerator unless Object.const_defined?(:Enumerator)
-
def deflater(app)
Rack::Lint.new Rack::Deflater.new(app)
end
-
+
def build_response(status, body, accept_encoding, headers = {})
body = [body] if body.respond_to? :to_str
app = lambda do |env|
@@ -129,7 +126,7 @@ class << body; def each; yield("foo"); yield("bar"); end; end
response[0].should.equal(200)
response[1].should.equal({ "Vary" => "Accept-Encoding", "Content-Type" => "text/plain" })
- Enumerator.new(response[2]).to_a.should.equal(["Hello world!"])
+ response[2].to_enum.to_a.should.equal(["Hello world!"])
end
should "be able to skip when there is no response entity body" do
@@ -137,19 +134,19 @@ class << body; def each; yield("foo"); yield("bar"); end; end
response[0].should.equal(304)
response[1].should.equal({})
- Enumerator.new(response[2]).to_a.should.equal([])
+ response[2].to_enum.to_a.should.equal([])
end
should "handle the lack of an acceptable encoding" do
response1 = build_response(200, "Hello world!", "identity;q=0", "PATH_INFO" => "/")
response1[0].should.equal(406)
response1[1].should.equal({"Content-Type" => "text/plain", "Content-Length" => "71"})
- Enumerator.new(response1[2]).to_a.should.equal(["An acceptable encoding for the requested resource / could not be found."])
+ response1[2].to_enum.to_a.should.equal(["An acceptable encoding for the requested resource / could not be found."])
response2 = build_response(200, "Hello world!", "identity;q=0", "SCRIPT_NAME" => "/foo", "PATH_INFO" => "/bar")
response2[0].should.equal(406)
response2[1].should.equal({"Content-Type" => "text/plain", "Content-Length" => "78"})
- Enumerator.new(response2[2]).to_a.should.equal(["An acceptable encoding for the requested resource /foo/bar could not be found."])
+ response2[2].to_enum.to_a.should.equal(["An acceptable encoding for the requested resource /foo/bar could not be found."])
end
should "handle gzip response with Last-Modified header" do
@@ -182,7 +179,7 @@ class << body; def each; yield("foo"); yield("bar"); end; end
response[0].should.equal(200)
response[1].should.not.include "Content-Encoding"
- Enumerator.new(response[2]).to_a.join.should.equal("Hello World!")
+ response[2].to_enum.to_a.join.should.equal("Hello World!")
end
should "do nothing when Content-Encoding already present" do
@@ -191,7 +188,7 @@ class << body; def each; yield("foo"); yield("bar"); end; end
response = deflater(app).call(request)
response[0].should.equal(200)
- Enumerator.new(response[2]).to_a.join.should.equal("Hello World!")
+ response[2].to_enum.to_a.join.should.equal("Hello World!")
end
should "deflate when Content-Encoding is identity" do
View
11 test/spec_head.rb
@@ -1,4 +1,3 @@
-require 'enumerator'
require 'rack/head'
require 'rack/lint'
require 'rack/mock'
@@ -16,17 +15,13 @@ def test_response(headers = {})
return response, body
end
- def enum
- defined?(Enumerator) ? Enumerator : Enumerable::Enumerator
- end
-
should "pass GET, POST, PUT, DELETE, OPTIONS, TRACE requests" do
%w[GET POST PUT DELETE OPTIONS TRACE].each do |type|
resp, _ = test_response("REQUEST_METHOD" => type)
resp[0].should.equal(200)
resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
- enum.new(resp[2]).to_a.should.equal(["foo"])
+ resp[2].to_enum.to_a.should.equal(["foo"])
end
end
@@ -35,14 +30,14 @@ def enum
resp[0].should.equal(200)
resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
- enum.new(resp[2]).to_a.should.equal([])
+ resp[2].to_enum.to_a.should.equal([])
end
should "close the body when it is removed" do
resp, body = test_response("REQUEST_METHOD" => "HEAD")
resp[0].should.equal(200)
resp[1].should.equal({"Content-type" => "test/plain", "Content-length" => "3"})
- enum.new(resp[2]).to_a.should.equal([])
+ resp[2].to_enum.to_a.should.equal([])
body.should.be.closed
end
end
View
11 test/spec_lock.rb
@@ -1,4 +1,3 @@
-require 'enumerator'
require 'rack/lint'
require 'rack/lock'
require 'rack/mock'
@@ -36,13 +35,11 @@ def lock_app(app, lock = Lock.new)
end
describe Rack::Lock do
- ::Enumerator = ::Enumerable::Enumerator unless Object.const_defined?(:Enumerator)
-
extend LockHelpers
-
+
describe 'Proxy' do
extend LockHelpers
-
+
should 'delegate each' do
env = Rack::MockRequest.env_for("/")
response = Class.new {
@@ -115,11 +112,11 @@ def close; @close_called = true; end
env = Rack::MockRequest.env_for("/")
body = [200, {"Content-Type" => "text/plain"}, %w{ hi mom }]
app = lock_app(lambda { |inner_env| body })
-
+
res = app.call(env)
res[0].should.equal body[0]
res[1].should.equal body[1]
- Enumerator.new(res[2]).to_a.should.equal ["hi", "mom"]
+ res[2].to_enum.to_a.should.equal ["hi", "mom"]
end
should "call synchronize on lock" do
View
9 test/spec_nulllogger.rb
@@ -1,23 +1,20 @@
-require 'enumerator'
require 'rack/lint'
require 'rack/mock'
require 'rack/nulllogger'
describe Rack::NullLogger do
- ::Enumerator = ::Enumerable::Enumerator unless Object.const_defined?(:Enumerator)
-
should "act as a noop logger" do
app = lambda { |env|
env['rack.logger'].warn "b00m"
[200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]]
}
-
+
logger = Rack::Lint.new(Rack::NullLogger.new(app))
-
+
res = logger.call(Rack::MockRequest.env_for)
res[0..1].should.equal [
200, {'Content-Type' => 'text/plain'}
]
- Enumerator.new(res[2]).to_a.should.equal ["Hello, World!"]
+ res[2].to_enum.to_a.should.equal ["Hello, World!"]
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.