Sha256: 93aaca1e6bb8e3f93130f22de2db079b8c918cff5088bc7231478b158c6b7f23

Contents?: true

Size: 1.78 KB

Versions: 34

Compression:

Stored size: 1.78 KB

Contents

# encoding: utf-8
require 'spec_helper'

describe Picky::Rack::Harakiri do
  before(:each) do
    @app = stub :app
    Process.stub! :kill # not taking any chances
  end
  context "defaults" do
    before(:each) do
      @ronin = described_class.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
      described_class.after = 100
      @ronin = described_class.new @app
    end
    after(:each) do
      described_class.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

34 entries across 34 versions & 1 rubygems

Version Path
picky-3.5.3 spec/lib/rack/harakiri_spec.rb
picky-3.5.2 spec/lib/rack/harakiri_spec.rb
picky-3.5.1 spec/lib/rack/harakiri_spec.rb
picky-3.5.0 spec/lib/rack/harakiri_spec.rb
picky-3.4.3 spec/lib/rack/harakiri_spec.rb
picky-3.4.2 spec/lib/rack/harakiri_spec.rb
picky-3.4.1 spec/lib/rack/harakiri_spec.rb
picky-3.4.0 spec/lib/rack/harakiri_spec.rb
picky-3.3.3 spec/lib/rack/harakiri_spec.rb
picky-3.3.2 spec/lib/rack/harakiri_spec.rb
picky-3.3.1 spec/lib/rack/harakiri_spec.rb
picky-3.3.0 spec/lib/rack/harakiri_spec.rb
picky-3.2.0 spec/lib/rack/harakiri_spec.rb
picky-3.1.13 spec/lib/rack/harakiri_spec.rb
picky-3.1.12 spec/lib/rack/harakiri_spec.rb
picky-3.1.11 spec/lib/rack/harakiri_spec.rb
picky-3.1.10 spec/lib/rack/harakiri_spec.rb
picky-3.1.9 spec/lib/rack/harakiri_spec.rb
picky-3.1.8 spec/lib/rack/harakiri_spec.rb
picky-3.1.7 spec/lib/rack/harakiri_spec.rb