Sha256: 676dbe39e3d45794ed00e9ea07e68aa95acfdde4cbe2e74ab1018a4bf813a428

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'opal/spec'

module Opal
  module Spec
    class RakeTask
      include Rake::DSL if defined? Rake::DSL

      attr_accessor :name
      attr_writer :runner_path, :url_path, :port

      def initialize(name = 'opal:spec')
        @name = name
        yield self if block_given?

        define_tasks
      end

      def define_tasks
        desc "Run opal specs in phantomjs"
        task @name do
          require 'rack'
          require 'webrick'

          server = fork do
            Rack::Server.start(:config => 'config.ru', :Port => port,
              :Logger => WEBrick::Log.new("/dev/null"), :AccessLog => [])
          end

          system "phantomjs #{runner_path} \"#{url_path}\""
          success = $?.success?

          Process.kill(:SIGINT, server)
          Process.wait

          exit 1 unless success
        end
      end

      def runner_path
        @runner_path || File.join(File.dirname(__FILE__), '..', '..', '..', 'vendor', 'runner.js')
      end

      def url_path
        @url_path || "http://localhost:9999/"
      end

      def port
        @port || 9999
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opal-spec-0.2.8 lib/opal/spec/rake_task.rb