Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added some tests for Profiler

  • Loading branch information...
commit 15d67e239fa2a6acd278de4ecc36f8834b30fb4a 1 parent 3c7de27
@runeb runeb authored
Showing with 36 additions and 0 deletions.
  1. +36 −0 test/spec_rack_profiler.rb
View
36 test/spec_rack_profiler.rb
@@ -0,0 +1,36 @@
+require 'rack/mock'
+require 'rack/profiler'
+
+context 'Rack::Profiler' do
+
+ specify 'printer defaults to RubyProf::CallTreePrinter' do
+ profiler = Rack::Profiler.new(nil)
+ profiler.instance_variable_get('@printer').should == RubyProf::CallTreePrinter
+ end
+
+ specify 'CallTreePrinter has correct headers' do
+ app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'Oh hai der'] }
+ request = Rack::MockRequest.env_for("/", :input => "profile=process_time")
+ headers = Rack::Profiler.new(app).call(request)[1]
+
+ headers.should == {"Content-Disposition"=>"attachment; filename=\"/.process_time.tree\")", "Content-Type"=>"application/octet-stream"}
+ end
+
+ specify 'FlatPrinter and GraphPrinter has Content-Type text/plain' do
+ app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'Oh hai der'] }
+ request = Rack::MockRequest.env_for("/", :input => "profile=process_time")
+
+ %w(flat graph).each do |printer|
+ headers = Rack::Profiler.new(app, :printer => printer.to_sym).call(request)[1]
+ headers.should == {"Content-Type"=>"text/plain"}
+ end
+ end
+
+ specify 'GraphHtmlPrinter has Content-Type text/html' do
+ app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'Oh hai der'] }
+ request = Rack::MockRequest.env_for("/", :input => "profile=process_time")
+ headers = Rack::Profiler.new(app, :printer => :graphhtml).call(request)[1]
+
+ headers.should == {"Content-Type"=>"text/html"}
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.