Permalink
Browse files

Set __LINE__ correctly for rackup files.

Before this change the line numbers were off by one, which broke
debugging tools like Pry in addition to causing a smidgen of user
confusion.

Reported-At: pry/pry#571
  • Loading branch information...
ConradIrwin committed Jun 4, 2012
1 parent edc8b92 commit 2fbf04b0f8282a2df0d2d4b06a2a1f4f9462c8d4
Showing with 8 additions and 1 deletion.
  1. +1 −1 lib/rack/builder.rb
  2. +1 −0 test/builder/line.ru
  3. +6 −0 test/spec_builder.rb
View
@@ -38,7 +38,7 @@ def self.parse_file(config, opts = Server::Options.new)
end
cfgfile.sub!(/^__END__\n.*\Z/m, '')
app = eval "Rack::Builder.new {\n" + cfgfile + "\n}.to_app",
- TOPLEVEL_BINDING, config
+ TOPLEVEL_BINDING, config, 0
else
require config
app = Object.const_get(::File.basename(config, '.rb').capitalize)
View
@@ -0,0 +1 @@
+run lambda{ |env| [200, {'Content-Type' => 'text/plain'}, [__LINE__.to_s]] }
View
@@ -197,5 +197,11 @@ def config_file(name)
Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'OK'
$:.pop
end
+
+ it "sets __LINE__ correctly" do
+ app, options = Rack::Builder.parse_file config_file('line.ru')
+ options = nil # ignored, prevents warning
+ Rack::MockRequest.new(app).get("/").body.to_s.should.equal '1'
+ end
end
end

0 comments on commit 2fbf04b

Please sign in to comment.