diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-14 06:10:08 +0800 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2011-01-14 07:55:47 +0800 |
commit | cbcae3a2b64283785cbfddc65bc79f5c86458a4f (patch) | |
tree | a6d2b7cf28242964dc6cdb12040c8922b22665eb | |
parent | d7a3bb21684557b55920cc48d6011be528279421 (diff) | |
download | rack-cbcae3a2b64283785cbfddc65bc79f5c86458a4f.tar.gz |
fixing unused variable warnings in 1.9.3
-rw-r--r-- | lib/rack/handler.rb | 2 | ||||
-rw-r--r-- | lib/rack/handler/fastcgi.rb | 4 | ||||
-rw-r--r-- | lib/rack/request.rb | 2 | ||||
-rw-r--r-- | lib/rack/showexceptions.rb | 9 | ||||
-rw-r--r-- | lib/rack/showstatus.rb | 11 | ||||
-rw-r--r-- | lib/rack/urlmap.rb | 2 | ||||
-rw-r--r-- | test/spec_chunked.rb | 2 | ||||
-rw-r--r-- | test/spec_commonlogger.rb | 2 | ||||
-rw-r--r-- | test/spec_content_type.rb | 10 | ||||
-rw-r--r-- | test/spec_file.rb | 2 | ||||
-rw-r--r-- | test/spec_lint.rb | 4 | ||||
-rw-r--r-- | test/spec_mock.rb | 2 | ||||
-rw-r--r-- | test/spec_response.rb | 6 | ||||
-rw-r--r-- | test/spec_session_memcache.rb | 12 | ||||
-rw-r--r-- | test/spec_session_pool.rb | 8 | ||||
-rw-r--r-- | test/spec_utils.rb | 2 |
16 files changed, 42 insertions, 38 deletions
diff --git a/lib/rack/handler.rb b/lib/rack/handler.rb index 3c09883e..8223f4ff 100644 --- a/lib/rack/handler.rb +++ b/lib/rack/handler.rb @@ -35,7 +35,7 @@ module Rack else begin Rack::Handler::Mongrel - rescue LoadError => e + rescue LoadError Rack::Handler::WEBrick end end diff --git a/lib/rack/handler/fastcgi.rb b/lib/rack/handler/fastcgi.rb index 29281e85..807f01e3 100644 --- a/lib/rack/handler/fastcgi.rb +++ b/lib/rack/handler/fastcgi.rb @@ -20,9 +20,9 @@ module Rack 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 diff --git a/lib/rack/request.rb b/lib/rack/request.rb index 49240f17..816640ed 100644 --- a/lib/rack/request.rb +++ b/lib/rack/request.rb @@ -196,7 +196,7 @@ module Rack # The union of GET and POST data. def params self.GET.update(self.POST) - rescue EOFError => e + rescue EOFError self.GET end diff --git a/lib/rack/showexceptions.rb b/lib/rack/showexceptions.rb index c85f5223..00ddf45e 100644 --- a/lib/rack/showexceptions.rb +++ b/lib/rack/showexceptions.rb @@ -54,9 +54,14 @@ module Rack 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 diff --git a/lib/rack/showstatus.rb b/lib/rack/showstatus.rb index 28258c7c..e1fff995 100644 --- a/lib/rack/showstatus.rb +++ b/lib/rack/showstatus.rb @@ -23,9 +23,16 @@ module Rack # 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]] diff --git a/lib/rack/urlmap.rb b/lib/rack/urlmap.rb index 73508533..d777a330 100644 --- a/lib/rack/urlmap.rb +++ b/lib/rack/urlmap.rb @@ -31,7 +31,7 @@ module Rack 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) diff --git a/test/spec_chunked.rb b/test/spec_chunked.rb index ac53c4a4..04c22fd6 100644 --- a/test/spec_chunked.rb +++ b/test/spec_chunked.rb @@ -52,7 +52,7 @@ describe Rack::Chunked do [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 diff --git a/test/spec_commonlogger.rb b/test/spec_commonlogger.rb index 446e70e1..9172750c 100644 --- a/test/spec_commonlogger.rb +++ b/test/spec_commonlogger.rb @@ -27,7 +27,7 @@ describe Rack::CommonLogger do 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 diff --git a/test/spec_content_type.rb b/test/spec_content_type.rb index 8eb9f150..44b0ed1c 100644 --- a/test/spec_content_type.rb +++ b/test/spec_content_type.rb @@ -3,26 +3,26 @@ require 'rack/content_type' 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 diff --git a/test/spec_file.rb b/test/spec_file.rb index f2e2506b..ce83a2e2 100644 --- a/test/spec_file.rb +++ b/test/spec_file.rb @@ -60,7 +60,7 @@ describe Rack::File do 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") diff --git a/test/spec_lint.rb b/test/spec_lint.rb index 792670b0..eda0dfc9 100644 --- a/test/spec_lint.rb +++ b/test/spec_lint.rb @@ -271,9 +271,9 @@ describe Rack::Lint do 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/) diff --git a/test/spec_mock.rb b/test/spec_mock.rb index e008dac9..303ca11b 100644 --- a/test/spec_mock.rb +++ b/test/spec_mock.rb @@ -179,7 +179,7 @@ describe Rack::MockRequest do 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 diff --git a/test/spec_response.rb b/test/spec_response.rb index c08a62e7..314aab0f 100644 --- a/test/spec_response.rb +++ b/test/spec_response.rb @@ -23,7 +23,7 @@ describe Rack::Response do 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,7 +152,7 @@ describe Rack::Response do 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 @@ -160,7 +160,7 @@ describe Rack::Response do 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 diff --git a/test/spec_session_memcache.rb b/test/spec_session_memcache.rb index 149cae63..7c81b9ad 100644 --- a/test/spec_session_memcache.rb +++ b/test/spec_session_memcache.rb @@ -113,7 +113,7 @@ begin 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 @@ begin 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 @@ begin 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 @@ begin 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| diff --git a/test/spec_session_pool.rb b/test/spec_session_pool.rb index 15bb46df..b4988065 100644 --- a/test/spec_session_pool.rb +++ b/test/spec_session_pool.rb @@ -64,7 +64,7 @@ describe Rack::Session::Pool do 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 @@ describe Rack::Session::Pool do 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] diff --git a/test/spec_utils.rb b/test/spec_utils.rb index 34b62443..622b7850 100644 --- a/test/spec_utils.rb +++ b/test/spec_utils.rb @@ -188,7 +188,7 @@ describe Rack::Utils do 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 |