Sha256: 29e00d62fb94bd657b7bcd849158cac80e2c42bcede2e9c1d7b8147dc44054ad

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 KB

Contents

require "rubygems"
require "timeout"
require "lsof"
dir = File.dirname(__FILE__)
$LOAD_PATH.unshift "#{dir}/../../lib"
require "screw_unit"
require "nokogiri"

module WaitFor
  extend self
  def wait_for(time=5)
    Timeout.timeout(time) do
      loop do
        value = yield
        return value if value
      end
    end
  end
end

class FunctionalSpecServerStarter
  class << self
    include WaitFor
    def call(threaded=true)
      return if $screw_unit_server_started
      Lsof.kill(8080)
      wait_for do
        !Lsof.running?(8080)
      end
      if threaded
        Thread.start do
          ScrewUnit::Server.run(spec_root_path, implementation_root_path, public_path)
        end
      else
        ScrewUnit::Server.run(spec_root_path, implementation_root_path, public_path)
      end
      wait_for do
        Lsof.running?(8080)
      end
      $screw_unit_server_started = true
    end

    def spec_root_path
      File.expand_path("#{dir}/../example_specs")
    end

    def public_path
      File.expand_path("#{dir}/../example_public")
    end

    def implementation_root_path
      File.expand_path("#{public_path}/javascripts")
    end

    def dir
      dir = File.dirname(__FILE__)
    end
  end
end

if $0 == __FILE__
  FunctionalSpecServerStarter.call(false)
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pivotal-screw-unit-0.4.0 spec/functional/functional_spec_server_starter.rb
pivotal-screw-unit-0.4.1 spec/functional/functional_spec_server_starter.rb
pivotal-screw-unit-0.4.2 spec/functional/functional_spec_server_starter.rb
pivotal-screw-unit-0.4.3 spec/functional/functional_spec_server_starter.rb