Sha256: c6de70de06045621ddd13df8509edf394a3b304cc340af7958b127e8b6799fc2

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'
require 'guard/webrick/server'

describe Guard::WEBrick::Server do

  describe "initialize" do

    it "should create a WEBrick::HTTPServer instance" do
      ::WEBrick::HTTPServer.should_receive(:new).with(
        :BindAddress  => '0.0.0.0',
        :Port         => 3000,
        :DocumentRoot => Dir::pwd
      )
      new_server
    end

    it "should expand the docroot path" do
      ::WEBrick::HTTPServer.should_receive(:new).with(
        :BindAddress  => '0.0.0.0',
        :Port         => 3000,
        :DocumentRoot => File.expand_path(File.join(Dir::pwd, 'public'))
      )
      new_server(:docroot => 'public')
    end

    it "should create an ssl server" do
      ::WEBrick::HTTPServer.should_receive(:new).with(
        :BindAddress  => '0.0.0.0',
        :Port         => 3000,
        :DocumentRoot => Dir::pwd,
        :SSLEnable    => true,
        :SSLCertName  => [%w[CN localhost]]
      )
      new_server(:ssl => true)
    end
  end

  describe "start" do

    subject { new_server }

    it "should start the WEBrick::HTTPServer instance" do
      ::WEBrick::HTTPServer.stub(:new).and_return(mock_http_server)
      subject.server.should_receive(:start)
      subject.start
    end
  end
end

def new_server(options = {})
  Guard::WEBrick::Server.new({
    :host     => '0.0.0.0',
    :port     => 3000,
    :docroot  => Dir::pwd
  }.update(options))
end

def mock_http_server
  @mock_http_server ||= mock(::WEBrick::HTTPServer).as_null_object
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
guard-webrick-0.1.4 spec/guard/webrick/server_spec.rb
guard-webrick-0.1.3 spec/guard/webrick/server_spec.rb
guard-webrick-0.1.2 spec/guard/webrick/server_spec.rb