Permalink
Browse files

fixing unused variable warnings in 1.9.3

  • Loading branch information...
1 parent d7a3bb2 commit cbcae3a2b64283785cbfddc65bc79f5c86458a4f @tenderlove tenderlove committed with josh Jan 13, 2011
View
@@ -35,7 +35,7 @@ def self.default(options = {})
else
begin
Rack::Handler::Mongrel
- rescue LoadError => e
+ rescue LoadError
Rack::Handler::WEBrick
end
end
@@ -20,9 +20,9 @@ module Handler
class FastCGI
def self.run(app, options={})
if options[:File]
- file = STDIN.reopen(UNIXServer.new(options[:File]))
+ STDIN.reopen(UNIXServer.new(options[:File]))
elsif options[:Port]
- port = STDIN.reopen(TCPServer.new(options[:Host], options[:Port]))
+ STDIN.reopen(TCPServer.new(options[:Host], options[:Port]))
end
FCGI.each { |request|
serve request, app
View
@@ -196,7 +196,7 @@ def POST
# The union of GET and POST data.
def params
self.GET.update(self.POST)
- rescue EOFError => e
+ rescue EOFError
self.GET
end
@@ -54,9 +54,14 @@ def dump_exception(exception)
def pretty(env, exception)
req = Rack::Request.new(env)
- path = (req.script_name + req.path_info).squeeze("/")
- frames = exception.backtrace.map { |line|
+ # This double assignment is to prevent an "unused variable" warning on
+ # Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me.
+ path = path = (req.script_name + req.path_info).squeeze("/")
+
+ # This double assignment is to prevent an "unused variable" warning on
+ # Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me.
+ frames = frames = exception.backtrace.map { |line|
frame = OpenStruct.new
if line =~ /(.*?):(\d+)(:in `(.*)')?/
frame.filename = $1
@@ -23,9 +23,16 @@ def call(env)
# client or server error, or explicit message
if (status.to_i >= 400 && empty) || env["rack.showstatus.detail"]
- req = Rack::Request.new(env)
+ # This double assignment is to prevent an "unused variable" warning on
+ # Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me.
+ req = req = Rack::Request.new(env)
+
message = Rack::Utils::HTTP_STATUS_CODES[status.to_i] || status.to_s
- detail = env["rack.showstatus.detail"] || message
+
+ # This double assignment is to prevent an "unused variable" warning on
+ # Ruby 1.9.3. Yes, it is dumb, but I don't like Ruby yelling at me.
+ detail = detail = env["rack.showstatus.detail"] || message
+
body = @template.result(binding)
size = Rack::Utils.bytesize(body)
[status, headers.merge("Content-Type" => "text/html", "Content-Length" => size.to_s), [body]]
View
@@ -31,7 +31,7 @@ def remap(map)
match = Regexp.new("^#{Regexp.quote(location).gsub('/', '/+')}(.*)", nil, 'n')
[host, location, match, app]
- }.sort_by { |(h, l, m, a)| [h ? -h.size : (-1.0 / 0.0), -l.size] } # Longest path first
+ }.sort_by { |(h, l, _, _)| [h ? -h.size : (-1.0 / 0.0), -l.size] } # Longest path first
end
def call(env)
@@ -52,7 +52,7 @@
[100, 204, 304].each do |status_code|
should "not modify response when status code is #{status_code}" do
app = lambda { |env| [status_code, {}, []] }
- status, headers, body = Rack::Chunked.new(app).call(@env)
+ status, headers, _ = Rack::Chunked.new(app).call(@env)
status.should.equal status_code
headers.should.not.include 'Transfer-Encoding'
end
@@ -27,7 +27,7 @@
should "log to anything with +write+" do
log = StringIO.new
- res = Rack::MockRequest.new(Rack::CommonLogger.new(app, log)).get("/")
+ Rack::MockRequest.new(Rack::CommonLogger.new(app, log)).get("/")
log.string.should =~ /"GET \/ " 200 #{length} /
end
@@ -3,26 +3,26 @@
describe Rack::ContentType do
should "set Content-Type to default text/html if none is set" do
app = lambda { |env| [200, {}, "Hello, World!"] }
- status, headers, body = Rack::ContentType.new(app).call({})
+ headers = Rack::ContentType.new(app).call({})[1]
headers['Content-Type'].should.equal 'text/html'
end
should "set Content-Type to chosen default if none is set" do
app = lambda { |env| [200, {}, "Hello, World!"] }
- status, headers, body =
- Rack::ContentType.new(app, 'application/octet-stream').call({})
+ headers =
+ Rack::ContentType.new(app, 'application/octet-stream').call({})[1]
headers['Content-Type'].should.equal 'application/octet-stream'
end
should "not change Content-Type if it is already set" do
app = lambda { |env| [200, {'Content-Type' => 'foo/bar'}, "Hello, World!"] }
- status, headers, body = Rack::ContentType.new(app).call({})
+ headers = Rack::ContentType.new(app).call({})[1]
headers['Content-Type'].should.equal 'foo/bar'
end
should "detect Content-Type case insensitive" do
app = lambda { |env| [200, {'CONTENT-Type' => 'foo/bar'}, "Hello, World!"] }
- status, headers, body = Rack::ContentType.new(app).call({})
+ headers = Rack::ContentType.new(app).call({})[1]
headers.to_a.select { |k,v| k.downcase == "content-type" }.
should.equal [["CONTENT-Type","foo/bar"]]
end
View
@@ -60,7 +60,7 @@
should "return bodies that respond to #to_path" do
env = Rack::MockRequest.env_for("/cgi/test")
- status, headers, body = Rack::File.new(DOCROOT).call(env)
+ status, _, body = Rack::File.new(DOCROOT).call(env)
path = File.join(DOCROOT, "/cgi/test")
View
@@ -271,9 +271,9 @@ def result.name
should "notice body errors" do
lambda {
- status, header, body = Rack::Lint.new(lambda { |env|
+ body = Rack::Lint.new(lambda { |env|
[200, {"Content-type" => "text/plain","Content-length" => "3"}, [1,2,3]]
- }).call(env({}))
+ }).call(env({}))[2]
body.each { |part| }
}.should.raise(Rack::Lint::LintError).
message.should.match(/yielded non-string/)
View
@@ -179,7 +179,7 @@
should "behave valid according to the Rack spec" do
lambda {
- res = Rack::MockRequest.new(app).
+ Rack::MockRequest.new(app).
get("https://bla.example.org:9292/meh/foo?bar", :lint => true)
}.should.not.raise(Rack::Lint::LintError)
end
@@ -23,7 +23,7 @@
it "can be written to" do
response = Rack::Response.new
- status, header, body = response.finish do
+ _, _, body = response.finish do
response.write "foo"
response.write "bar"
response.write "baz"
@@ -152,15 +152,15 @@
res.status = 404
res.write "foo"
}
- status, header, body = r.finish
+ status, _, body = r.finish
str = ""; body.each { |part| str << part }
str.should.equal "foo"
status.should.equal 404
end
it "doesn't return invalid responses" do
r = Rack::Response.new(["foo", "bar"], 204)
- status, header, body = r.finish
+ _, header, body = r.finish
str = ""; body.each { |part| str << part }
str.should.be.empty
header["Content-Type"].should.equal nil
@@ -113,7 +113,7 @@
req = Rack::MockRequest.new(pool)
res0 = req.get("/")
- session = (cookie = res0["Set-Cookie"])[session_match]
+ cookie = res0["Set-Cookie"][session_match]
res0.body.should.equal '{"counter"=>1}'
res1 = req.get("/", "HTTP_COOKIE" => cookie)
@@ -179,7 +179,6 @@
end
it "updates deep hashes correctly" do
- store = nil
hash_check = proc do |env|
session = env['rack.session']
unless session.include? 'test'
@@ -197,7 +196,7 @@
session_id = (cookie = res0["Set-Cookie"])[session_match, 1]
ses0 = pool.pool.get(session_id, true)
- res1 = req.get("/", "HTTP_COOKIE" => cookie)
+ req.get("/", "HTTP_COOKIE" => cookie)
ses1 = pool.pool.get(session_id, true)
ses1.should.not.equal ses0
@@ -244,13 +243,6 @@
tnum = rand(7).to_i+5
r = Array.new(tnum) do |i|
- delta_time = proc do |env|
- env['rack.session'][i] = Time.now
- Thread.stop
- env['rack.session'] = env['rack.session'].dup
- env['rack.session'][i] -= Time.now
- incrementor.call(env)
- end
app = Rack::Utils::Context.new pool, time_delta
req = Rack::MockRequest.new app
Thread.new(req) do |run|
@@ -64,7 +64,7 @@
req = Rack::MockRequest.new(pool)
res0 = req.get("/")
- session = (cookie = res0["Set-Cookie"])[session_match]
+ cookie = res0["Set-Cookie"][session_match]
res0.body.should.equal '{"counter"=>1}'
pool.pool.size.should.equal 1
@@ -170,9 +170,9 @@
run.get('/', "HTTP_COOKIE" => cookie, 'rack.multithread' => true)
end
end.reverse.map{|t| t.run.join.value }
- r.each do |res|
- res['Set-Cookie'].should.equal cookie
- res.body.should.include '"counter"=>2'
+ r.each do |resp|
+ resp['Set-Cookie'].should.equal cookie
+ resp.body.should.include '"counter"=>2'
end
session = pool.pool[sess_id]
View
@@ -188,7 +188,7 @@
should "figure out which encodings are acceptable" do
helper = lambda do |a, b|
- request = Rack::Request.new(Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => a))
+ Rack::Request.new(Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => a))
Rack::Utils.select_best_encoding(a, b)
end

0 comments on commit cbcae3a

Please sign in to comment.