spec/rackamole/mole_spec.rb in rackamole-0.3.1 vs spec/rackamole/mole_spec.rb in rackamole-0.3.2

- old
+ new

@@ -13,11 +13,10 @@ 'HTTP_USER_AGENT' => "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.0.12) Gecko/20080326 CentOS/1.5.0.12-14.el5.centos Firefox/1.5.0.12" } @opts = { :app_name => "Test App", :environment => :test, - :excluded_paths => ['/should_bail'], :perf_threshold => 0.1, :user_key => :username, :store => @test_store } end @@ -64,11 +63,11 @@ it "should mole a fault issue correctly" do begin get "/", nil, @test_env rescue last_request.env['mole.stash'].should_not be_nil - fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:45:in `error_app'" ) + fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:44:in `error_app'" ) fault.should_not be_nil fault.count.should == 1 end end @@ -77,11 +76,11 @@ 2.times do |i| begin get "/", nil, env rescue last_request.env['mole.stash'].should_not be_nil - fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:45:in `error_app'" ) + fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:44:in `error_app'" ) fault.should_not be_nil fault.count.should == i+1 env = last_request.env end end @@ -93,19 +92,57 @@ begin env['PATH_INFO'] = "/#{i}" get "/#{i}", nil, env rescue => boom last_request.env['mole.stash'].should_not be_nil - fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:45:in `error_app'" ) + fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:44:in `error_app'" ) fault.should_not be_nil fault.count.should == i+1 env = last_request.env end end end end + + # --------------------------------------------------------------------------- + describe "perfomance exemptions" do + it "should exempt a string path correctly" do + rack = Rack::Mole.new( nil, :app_name => "test app", :perf_excludes => [ {:context => "/fred/blee" } ] ) + rack.send( :perf_exempt?, "/fred/blee", 10 ).should == true + rack.send( :perf_exempt?, "/fred/blee1", 10 ).should == false + end + it "should exempt a regex path correctly" do + rack = Rack::Mole.new( nil, :app_name => "test app", :perf_excludes => [ {:context => /^\/fred\/?.*/ } ] ) + rack.send( :perf_exempt?, "/fred/blee", 10 ).should == true + rack.send( :perf_exempt?, "/fred", 10 ).should == true + rack.send( :perf_exempt?, "/fred/blee/bubba", 10 ).should == true + rack.send( :perf_exempt?, "/freud", 10 ).should == false + end + + it "should exempt path with threshold correctly" do + rack = Rack::Mole.new( nil, :app_name => "test app", :perf_excludes => [ {:context => /^\/fred\/?.*/, :threshold => 15 } ] ) + rack.send( :perf_exempt?, "/fred/blee", 10 ).should == true + rack.send( :perf_exempt?, "/fred/blee", 16 ).should == false + end + + it "should exempt an array of path correctly" do + excludes = [ + { :context => "/duh/1" , :threshold => 5 }, + { :context => /^\/fred\/?.*/, :threshold => 15 }, + ] + rack = Rack::Mole.new( nil, :app_name => "test app", :perf_excludes => excludes ) + rack.send( :perf_exempt?, "/fred/blee", 10 ).should == true + rack.send( :perf_exempt?, "/crap/10/fred", 10 ).should == false + rack.send( :perf_exempt?, "/fred/blee", 16 ).should == false + + rack.send( :perf_exempt?, "/duh/1", 5 ).should == true + rack.send( :perf_exempt?, "/duh/1", 6 ).should == false + rack.send( :perf_exempt?, "/duh/2", 6 ).should == false + end + end + # --------------------------------------------------------------------------- describe "performance duplicate" do before( :each ) do @test_store = TestStore.new slow_app( @opts ) @@ -154,11 +191,11 @@ begin get "/", nil, @test_env rescue @test_store.mole_result[:stack].should have(4).items last_request.env['mole.stash'].should_not be_nil - fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:45:in `error_app'" ) + fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:44:in `error_app'" ) fault.should_not be_nil fault.count.should == 1 end end @@ -234,22 +271,30 @@ get "/crap/out", nil, @test_env @test_store.mole_result[:type].should == Rackamole.fault @test_store.mole_result[:stack].should have(4).items @test_store.mole_result[:fault].should == 'Oh snap!' last_request.env['mole.stash'].should_not be_nil - fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:231" ) + fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:268" ) fault.should_not be_nil fault.count.should == 1 end end it "should capture request parameters correctly" do get "/", { :blee => 'duh' }, @test_env @test_store.mole_result[:params].should == { :blee => "duh".to_json } end + + it "should not mole a standard exclusion" do + %w(/stylesheets/style.css /javascripts/blee.js /images/fred.png).each do |path| + get path, nil, @test_env + @test_store.mole_result.should be_nil + end + end - it "should not mole an exclusion" do + it "should not mole a custom exclusion" do + @opts[:excluded_paths] = [/\/should_bail/] get '/should_bail', nil, @test_env @test_store.mole_result.should be_nil end end @@ -272,18 +317,18 @@ end describe "rails env" do it "should find route info correctly" do pending do - RAILS_ENV = true - ActionController::Routing::Routes.stub!( :recognize_path ).and_return( { :controller => 'fred', :action => 'blee' } ) - rack = Rack::Mole.new( nil, :app_name => "test app" ) + RAILS_ENV = true + ActionController::Routing::Routes.stub!( :recognize_path ).and_return( { :controller => 'fred', :action => 'blee' } ) + rack = Rack::Mole.new( nil, :app_name => "test app" ) - # routes.should_receive( 'recognize_path' ).with( 'fred', { :method => 'blee' } ).and_return( ) - res = rack.send( :get_route, OpenStruct.new( :path => "/", :request_method => "GET") ) - res.should_not be_nil - res[:controller].should == 'fred' - res[:action].should == 'blee' + # routes.should_receive( 'recognize_path' ).with( 'fred', { :method => 'blee' } ).and_return( ) + res = rack.send( :get_route, OpenStruct.new( :path => "/", :request_method => "GET") ) + res.should_not be_nil + res[:controller].should == 'fred' + res[:action].should == 'blee' end end it "should extract request parameters correctly" do rack = Rack::Mole.new( nil, :app_name => "test app" )