Skip to content

Commit

Permalink
Added some tests for Profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
runeb committed Dec 10, 2008
1 parent 3c7de27 commit 15d67e2
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/spec_rack_profiler.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 15d67e2

Please sign in to comment.