Sha256: ef52569454096265092d4591974218f5c8e09c4a51fbd0ade5e4c02a4d8c75bb

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

# encoding: utf-8
require 'spec_helper'

describe Rack::Harakiri do
  before(:each) do
    @app = stub :app
  end
  context "defaults" do
    before(:each) do
      @ronin = Rack::Harakiri.new @app
    end
    it "should quit after a default amount of requests" do
      @ronin.instance_variable_get(:@quit_after_requests).should == 50
    end
    describe 'harakiri?' do
      it "should be true after 50 harakiri calls" do
        50.times { @ronin.harakiri }
        
        @ronin.harakiri?.should == true
      end
      it "should not be true after just 49 harakiri calls" do
        49.times { @ronin.harakiri }
        
        @ronin.harakiri?.should == false
      end
    end
    describe "harakiri" do
      it "should kill the process after 50 harakiri calls" do
        Process.should_receive(:kill).once
        
        50.times { @ronin.harakiri }
      end
      it "should not kill the process after 49 harakiri calls" do
        Process.should_receive(:kill).never
        
        49.times { @ronin.harakiri }
      end
    end
    describe "call" do
      before(:each) do
        @app.stub! :call
        @app.stub! :harakiri
      end
      it "calls harakiri" do
        @ronin.should_receive(:harakiri).once.with
        
        @ronin.call :env
      end
      it "calls the app" do
        @app.should_receive(:call).once.with :env
        
        @ronin.call :env
      end
    end
  end
  context "with harakiri set" do
    before(:each) do
      Rack::Harakiri.after = 100
      @ronin = Rack::Harakiri.new @app
    end
    after(:each) do
      Rack::Harakiri.after = nil
    end
    it "should quit after an amount of requests" do
      @ronin.instance_variable_get(:@quit_after_requests).should == 100
    end
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
picky-1.0.0 spec/lib/rack/harakiri_spec.rb