Sha256: 9df9e46d6ae935fb9d5ce30c4c7b55ef74cb5c58c7b60925586e1798e7626739

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require 'opal/rspec'

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

      RUNNER = File.expand_path('../../../../vendor/spec_runner.js', __FILE__)
      PORT = 9999
      URL = "http://localhost:9999/"

      def initialize(name = 'opal:rspec', spec_app = false, &block)
        desc "Run opal specs in phantomjs"
        task name do
          require 'rack'
          require 'webrick'

          apps = []
          apps << app = Opal::Server.new { |s|
            s.main = 'opal/rspec/sprockets_runner'
            s.append_path 'spec'
            s.debug = false

            block.call s if block_given?
          }

          apps << Object.const_get(spec_app.to_s) if spec_app

          server = Thread.new do
            Thread.current.abort_on_exception = true
            Rack::Server.start(
              :app => Rack::Cascade.new([app, spec_app]),
              :Port => PORT,
              :AccessLog => [],
              :Logger => WEBrick::Log.new("/dev/null"),
            )
          end

          if `phantomjs -v`.strip.to_i >= 2
            warn <<-WARN.gsub(/^              /,'')
              Only PhantomJS v1 is currently supported,
              if you're using homebrew on OSX you can switch version with:

                brew switch phantomjs 1.9.8

            WARN
            exit 1
          end

          begin
            system %Q{phantomjs #{RUNNER} "#{URL}"}
            success = $?.success?

            exit 1 unless success
          ensure
            server.kill
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opal-rspec-cj-0.4.4 lib/opal/rspec/rake_task.rb