Sha256: 3e900cba1970d5ab00af40207e25a8f8abef0603a3eb3adc48abe9f3ab2795da

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 KB

Contents

module DockTest
  module DSL

    attr_reader :url
    # sets the test url
    # also creates a new webrick server process
    def url=(value)
      @url = value

      if localhost? && @server_thread.nil?
        require "rack"
        require 'webrick'

        ARGV.clear # clear ARGV as it is used by Rack to configure server

        server = WEBrick::HTTPServer.new(:Port => port).tap do |server|
          server.mount '/', Rack::Handler::WEBrick, Rack::Server.new.app
        end
        @server_thread = Thread.new { server.start }
        trap('INT') do
          server.shutdown
          exit
        end
      end
    end

    # oauth settings
    attr_accessor :oauth_consumer_key, :oauth_consumer_secret

    # if the current dock_test environment requires oauth
    def oauth?
      oauth_consumer_key && oauth_consumer_secret
    end

    def port
      URI.parse(@url).port
    end

    def localhost?
      @url && ['127.0.0.1', 'localhost'].include?(URI.parse(@url).host)
    end

    def skippy=(skippy)
      @skippy = skippy
    end

    def skippy?
      @skippy || false
    end

    def configure(&block)
      block.call(DockTest)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dock_test-0.3.4 lib/dock_test/dsl.rb
dock_test-0.3.3 lib/dock_test/dsl.rb
dock_test-0.3.2 lib/dock_test/dsl.rb
dock_test-0.3.1 lib/dock_test/dsl.rb
dock_test-0.3.0 lib/dock_test/dsl.rb
dock_test-0.2.1 lib/dock_test/dsl.rb
dock_test-0.2.0 lib/dock_test/dsl.rb
dock_test-0.1.7 lib/dock_test/dsl.rb