From e381985306ea85bdc5f9823dd5b48d30d417935e Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Mon, 21 Mar 2011 02:11:00 +0800 Subject: Add tests for Rack::Builder.parse_file --- test/builder/anything.rb | 5 +++++ test/builder/end.ru | 3 +++ test/builder/options.ru | 2 ++ test/spec_builder.rb | 23 +++++++++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 test/builder/anything.rb create mode 100644 test/builder/end.ru create mode 100644 test/builder/options.ru diff --git a/test/builder/anything.rb b/test/builder/anything.rb new file mode 100644 index 00000000..c07f82cd --- /dev/null +++ b/test/builder/anything.rb @@ -0,0 +1,5 @@ +class Anything + def self.call(env) + [200, {'Content-Type' => 'text/plain'}, ['OK']] + end +end diff --git a/test/builder/end.ru b/test/builder/end.ru new file mode 100644 index 00000000..8eea56ee --- /dev/null +++ b/test/builder/end.ru @@ -0,0 +1,3 @@ +run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['OK']] } +__END__ +Should not be evaluated diff --git a/test/builder/options.ru b/test/builder/options.ru new file mode 100644 index 00000000..8562da65 --- /dev/null +++ b/test/builder/options.ru @@ -0,0 +1,2 @@ +#\ -d +run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['OK']] } diff --git a/test/spec_builder.rb b/test/spec_builder.rb index 9839eaa5..1e5715c4 100644 --- a/test/spec_builder.rb +++ b/test/spec_builder.rb @@ -120,4 +120,27 @@ describe Rack::Builder do Rack::MockRequest.new(app).get("/").should.be.server_error end + describe "parse_file" do + def config_file(name) + File.join(File.dirname(__FILE__), 'builder', name) + end + + it "parses commented options" do + app, options = Rack::Builder.parse_file config_file('options.ru') + options[:debug].should.be.true + Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'OK' + end + + it "removes __END__ before evaluating app" do + app, options = Rack::Builder.parse_file config_file('end.ru') + Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'OK' + end + + it "requires anything not ending in .ru" do + $: << File.dirname(__FILE__) + app, options = Rack::Builder.parse_file 'builder/anything' + Rack::MockRequest.new(app).get("/").body.to_s.should.equal 'OK' + $:.pop + end + end end -- cgit v1.2.3-24-ge0c7