Sha256: 9714bd2f4093c9ccf14e05ae3c4c40be0ce0fa2cc60291664f85fd8b45944617

Contents?: true

Size: 1.74 KB

Versions: 3

Compression:

Stored size: 1.74 KB

Contents

require "spec_helper"
require "rack/handler/hatetepe"

describe Rack::Handler::Hatetepe do
  let(:app) { stub "app" }
  let(:options) {
    {
      :Host => stub("host"),
      :Port => stub("port")
    }
  }
  let(:server) { stub "server" }
  
  describe ".run(app, options) {|server| ... }" do
    before {
      EM.stub :epoll
      Signal.stub :trap
      Hatetepe::Server.stub :start
    }
    
    it "starts an Hatetepe server" do
      EM.should_receive(:run) {|&block|
        EM.should_receive(:epoll)
        Hatetepe::Server.should_receive(:start) {|opts|
          opts[:host].should equal(options[:Host])
          opts[:port].should equal(options[:Port])
          opts[:app].should equal(app)
        }
        block.call
      }
      Rack::Handler::Hatetepe.run app, options
    end
    
    it "yields the server" do
      Hatetepe::Server.stub :start => server
      
      srvr = nil
      Rack::Handler::Hatetepe.run(app) {|s|
        srvr = s
        EM.stop
      }
      srvr.should equal(server)
    end
    
    it "can be stopped by sending SIGTERM or SIGINT" do
      EM.should_receive(:run) {|&block| block.call }
      
      trapped_signals = []
      Signal.should_receive(:trap).twice {|sig, &block|
        trapped_signals << sig
        EM.should_receive :stop
        block.call
      }
      Rack::Handler::Hatetepe.run app
      
      trapped_signals.should include("TERM")
      trapped_signals.should include("INT")
    end
  end
  
  describe ".run(app) {|server| ... }" do
    it "defaults Host to 0.0.0.0 and Port to 8080" do
      Hatetepe::Server.should_receive(:start) {|opts|
        opts[:host].should == "0.0.0.0"
        opts[:port].should == 8080
      }
      Rack::Handler::Hatetepe.run(app) { EM.stop }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hatetepe-0.2.2 spec/unit/rack_handler_spec.rb
hatetepe-0.2.1 spec/unit/rack_handler_spec.rb
hatetepe-0.2.0 spec/unit/rack_handler_spec.rb