Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Added bundler tests for multi-request
Browse files Browse the repository at this point in the history
  • Loading branch information
bhb committed Jan 6, 2011
1 parent a99582f commit a972627
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
23 changes: 23 additions & 0 deletions test/multiple_request_profiling_test.rb
Expand Up @@ -123,6 +123,29 @@ def profile_requests(profiled_app, requests, options = {})
status, headers, body = profiled_app.call(custom_data_env)
assert_no_match(/method1/, RackResponseBody.new(body).to_s)
end

context "when in bundler mode" do

should "call pprof.rb using 'bundle' command if bundler is set" do
status = stub_everything(:exitstatus => 0)
profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true)
Open4.expects(:popen4).with(regexp_matches(/^bundle exec pprof\.rb/)).returns(status)
profile_requests(profiled_app, :default)
end

should "change directory into the current directory if custom Gemfile dir is not provided" do
profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true, :gemfile_dir => 'bundler')
Dir.expects(:chdir).with('bundler').returns(["","",0])
profile_requests(profiled_app, :default)
end

should "change directory into custom Gemfile dir if provided" do
profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true)
Dir.expects(:chdir).with('.').returns(["","",0])
profile_requests(profiled_app, :default)
end

end

end

Expand Down
23 changes: 0 additions & 23 deletions test/rack-perftools-profiler_test.rb
Expand Up @@ -80,29 +80,6 @@ class RackPerftoolsProfilerTest < Test::Unit::TestCase

end

context "when in bundler mode" do

should "call pprof.rb using 'bundle' command if bundler is set" do
status = stub_everything(:exitstatus => 0)
profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true)
Open4.expects(:popen4).with(regexp_matches(/^bundle exec pprof\.rb/)).returns(status)
profiled_app.call(@profiled_request_env)
end

should "change directory into the current directory if custom Gemfile dir is not provided" do
profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true, :gemfile_dir => 'bundler')
Dir.expects(:chdir).with('bundler').returns(["","",0])
profiled_app.call(@profiled_request_env)
end

should "change directory into custom Gemfile dir if provided" do
profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true)
Dir.expects(:chdir).with('.').returns(["","",0])
profiled_app.call(@profiled_request_env)
end

end

context "when changing mode for single request" do

should "default to configured mode if mode is empty string" do
Expand Down
23 changes: 23 additions & 0 deletions test/single_request_profiling_test.rb
Expand Up @@ -92,6 +92,29 @@ def setup
assert_no_match(/method1/, RackResponseBody.new(body).to_s)
end

context "when in bundler mode" do

should "call pprof.rb using 'bundle' command if bundler is set" do
status = stub_everything(:exitstatus => 0)
profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true)
Open4.expects(:popen4).with(regexp_matches(/^bundle exec pprof\.rb/)).returns(status)
profiled_app.call(@profiled_request_env)
end

should "change directory into the current directory if custom Gemfile dir is not provided" do
profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true, :gemfile_dir => 'bundler')
Dir.expects(:chdir).with('bundler').returns(["","",0])
profiled_app.call(@profiled_request_env)
end

should "change directory into custom Gemfile dir if provided" do
profiled_app = Rack::PerftoolsProfiler.new(@app, :bundler => true)
Dir.expects(:chdir).with('.').returns(["","",0])
profiled_app.call(@profiled_request_env)
end

end

end

context 'when using the text printer' do
Expand Down

0 comments on commit a972627

Please sign in to comment.