Sha256: 40f65b9eee0d619d0df315ef130d8a949e2e3e00804f6ae435f417b4a35ac802

Contents?: true

Size: 1.83 KB

Versions: 30

Compression:

Stored size: 1.83 KB

Contents

# encoding: utf-8
require 'spec_helper'

# If you want to use Rack::Harakiri, you
# need to explicitly require it.
#
require 'picky/rack/harakiri'

describe Rack::Harakiri do
  before(:each) do
    @app = double :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 no_args

        @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

30 entries across 30 versions & 1 rubygems

Version Path
picky-4.31.3 spec/lib/rack/harakiri_spec.rb
picky-4.31.2 spec/lib/rack/harakiri_spec.rb
picky-4.31.1 spec/lib/rack/harakiri_spec.rb
picky-4.31.0 spec/lib/rack/harakiri_spec.rb
picky-4.30.0 spec/lib/rack/harakiri_spec.rb
picky-4.29.0 spec/lib/rack/harakiri_spec.rb
picky-4.28.1 spec/lib/rack/harakiri_spec.rb
picky-4.27.1 spec/lib/rack/harakiri_spec.rb
picky-4.27.0 spec/lib/rack/harakiri_spec.rb
picky-4.26.2 spec/lib/rack/harakiri_spec.rb
picky-4.26.1 spec/lib/rack/harakiri_spec.rb
picky-4.26.0 spec/lib/rack/harakiri_spec.rb
picky-4.25.3 spec/lib/rack/harakiri_spec.rb
picky-4.25.2 spec/lib/rack/harakiri_spec.rb
picky-4.25.1 spec/lib/rack/harakiri_spec.rb
picky-4.25.0 spec/lib/rack/harakiri_spec.rb
picky-4.24.0 spec/lib/rack/harakiri_spec.rb
picky-4.23.2 spec/lib/rack/harakiri_spec.rb
picky-4.23.1 spec/lib/rack/harakiri_spec.rb
picky-4.23.0 spec/lib/rack/harakiri_spec.rb