Class: Opal::RSpec::RakeTask

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/opal/rspec/rake_task.rb

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(name = 'opal:rspec', &block) ⇒ RakeTask

Returns a new instance of RakeTask.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/opal/rspec/rake_task.rb', line 12

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

    server = Thread.new do
      app = Opal::Server.new { |s|
        s.main = 'opal/rspec/sprockets_runner'
        s.append_path 'spec'
        s.debug = false

        block.call s if block
      }

      Rack::Server.start(:app => 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