spec/rackamole/mole_spec.rb in rackamole-0.2.5 vs spec/rackamole/mole_spec.rb in rackamole-0.2.6
- old
+ new
@@ -159,19 +159,52 @@
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:45:in `error_app'" )
fault.should_not be_nil
fault.count.should == 1
end
end
+
+ # ---------------------------------------------------------------------------
+ describe "exclusions" do
+ before( :each) do
+ opts = @opts.clone
+ opts[:mole_excludes] = [:headers, :body, :browser, :ip, :url]
+ app( opts )
+ end
+
+ it "should exclude some mole attributes correctly" do
+ get "/fred/blee", nil, @test_env
+ @test_store.mole_result[:app_name].should == "Test App"
+ @test_store.mole_result[:environment].should == :test
+ @test_store.mole_result[:user_id].should be_nil
+ @test_store.mole_result[:user_name].should == 'fernand'
+ @test_store.mole_result[:method].should == 'GET'
+ @test_store.mole_result[:path].should == '/fred/blee'
+ @test_store.mole_result[:type].should == Rackamole.feature
+ @test_store.mole_result[:params].should be_nil
+ @test_store.mole_result[:session].should_not be_nil
+ @test_store.mole_result[:session].keys.should have(2).items
+ @test_store.mole_result[:status].should == 200
+
+ # Excluded
+ @test_store.mole_result[:headers].should be_nil
+ @test_store.mole_result[:body].should be_nil
+ @test_store.mole_result[:browser].should be_nil
+ @test_store.mole_result[:ip].should be_nil
+ @test_store.mole_result[:url].should be_nil
+ end
+ end
+
# ---------------------------------------------------------------------------
describe 'moling a request' do
before :each do
app( @opts )
end
it "should set the mole meta correctly" do
get "/fred/blee", nil, @test_env
+
@test_store.mole_result[:app_name].should == "Test App"
@test_store.mole_result[:environment].should == :test
@test_store.mole_result[:user_id].should be_nil
@test_store.mole_result[:user_name].should == 'fernand'
@test_store.mole_result[:ip].should == '1.1.1.1'
@@ -181,10 +214,13 @@
@test_store.mole_result[:path].should == '/fred/blee'
@test_store.mole_result[:type].should == Rackamole.feature
@test_store.mole_result[:params].should be_nil
@test_store.mole_result[:session].should_not be_nil
@test_store.mole_result[:session].keys.should have(2).items
+ @test_store.mole_result[:status].should == 200
+ @test_store.mole_result[:headers].should == { "Content-Type" => "text/plain" }
+ @test_store.mole_result[:body].should be_nil
end
it "mole an exception correctly" do
begin
raise 'Oh snap!'
@@ -193,11 +229,11 @@
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:190" )
+ fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:226" )
fault.should_not be_nil
fault.count.should == 1
end
end
@@ -232,11 +268,11 @@
describe "rails env" do
it "should find route info correctly" do
RAILS_ENV = true
ActionController::Routing::Routes.stub!( :recognize_path ).and_return( { :controller => 'fred', :action => 'blee' } )
- rack = Rack::Mole.new( nil )
+ 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'
@@ -286,16 +322,17 @@
# ---------------------------------------------------------------------------
describe '#alertable?' do
before( :each ) do
@rack = Rack::Mole.new( nil,
- :twitter => {
+ :app_name => "test app",
+ :twitter => {
:username => 'fred',
:password => 'blee',
:alert_on => [Rackamole.perf, Rackamole.fault]
},
- :email => {
+ :email => {
:from => 'fred',
:to => ['blee'],
:alert_on => [Rackamole.perf, Rackamole.fault, Rackamole.feature]
} )
end
@@ -319,10 +356,11 @@
# ---------------------------------------------------------------------------
describe '#configured?' do
before( :each ) do
options = {
+ :app_name => "test app",
:blee => [1,2,3],
:twitter => { :username => 'Fernand', :password => "Blee", :alert_on => [Rackamole.perf, Rackamole.fault] },
}
@rack = Rack::Mole.new( nil, options )
end
@@ -352,11 +390,11 @@
end
# ---------------------------------------------------------------------------
describe '#id_browser' do
before :all do
- @rack = Rack::Mole.new( nil )
+ @rack = Rack::Mole.new( nil, :app_name => "test app" )
end
it "should detect a browser type correctly" do
browser = @rack.send( :id_browser, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; InfoPath.2; MS-RTC LM 8; SPC 3.1 P1 Ta)")
browser.should == 'MSIE 7.0'
@@ -440,6 +478,15 @@
session.has_key?( :bobo ).should == false
end
end
+ # ---------------------------------------------------------------------------
+ describe 'required params' do
+ it "should crap out if a required param is omitted" do
+ lambda {
+ Rack::Mole.new( app )
+ }.should raise_error( /app_name/ )
+ end
+ end
+
end