Class: MSpec::Opal::Runner

Inherits:
Object show all
Defined in:
opal/lib/mspec/opal/rake_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Runner

Returns a new instance of Runner



59
60
61
62
# File 'opal/lib/mspec/opal/rake_task.rb', line 59

def initialize &block
  @app = RackApp.new(&block).to_app
  @port = 9999
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app



64
65
66
# File 'opal/lib/mspec/opal/rake_task.rb', line 64

def app
  @app
end

#portObject

Returns the value of attribute port



65
66
67
# File 'opal/lib/mspec/opal/rake_task.rb', line 65

def port
  @port
end

#server_pidObject (readonly)

Returns the value of attribute server_pid



64
65
66
# File 'opal/lib/mspec/opal/rake_task.rb', line 64

def server_pid
  @server_pid
end

Instance Method Details

#passed?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'opal/lib/mspec/opal/rake_task.rb', line 67

def passed?
  @passed
end

#runObject



71
72
73
74
75
76
77
78
79
80
# File 'opal/lib/mspec/opal/rake_task.rb', line 71

def run
  start_server
  start_phantomjs

  exit 1 unless passed?
rescue => e
  puts e.message
ensure
  stop_server if server_pid
end

#start_phantomjsObject



87
88
89
90
91
92
93
94
# File 'opal/lib/mspec/opal/rake_task.rb', line 87

def start_phantomjs
  require 'shellwords'
  runner  = File.expand_path('../sprockets.js', __FILE__).shellescape
  url     = "http://localhost:#{port}/".shellescape
  command = %Q{phantomjs #{runner} #{url}}

  @passed = system command
end

#start_serverObject



96
97
98
99
100
101
# File 'opal/lib/mspec/opal/rake_task.rb', line 96

def start_server
  @server_pid = fork do
    Rack::Server.start(:app => app, :Port => port, :AccessLog => [],
      :Logger => WEBrick::Log.new("/dev/null"))
  end
end

#stop_serverObject



82
83
84
85
# File 'opal/lib/mspec/opal/rake_task.rb', line 82

def stop_server
  Process.kill(:SIGINT, server_pid)
  Process.wait
end