Class: MSpec::Opal::Runner

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

Defined Under Namespace

Classes: PhantomJS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Runner

Returns a new instance of Runner



39
40
41
42
# File 'opal/lib/mspec/opal/rake_task.rb', line 39

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

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app



44
45
46
# File 'opal/lib/mspec/opal/rake_task.rb', line 44

def app
  @app
end

#portObject

Returns the value of attribute port



45
46
47
# File 'opal/lib/mspec/opal/rake_task.rb', line 45

def port
  @port
end

#serverObject (readonly)

Returns the value of attribute server



44
45
46
# File 'opal/lib/mspec/opal/rake_task.rb', line 44

def server
  @server
end

Instance Method Details

#passed?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'opal/lib/mspec/opal/rake_task.rb', line 47

def passed?
  @passed
end

#runObject



51
52
53
54
55
56
57
58
59
60
# File 'opal/lib/mspec/opal/rake_task.rb', line 51

def run
  start_server
  start_phantomjs

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

#start_phantomjsObject



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

def start_phantomjs
  runner  = File.expand_path('../sprockets.js', __FILE__).shellescape
  url     = "http://localhost:#{port}/".shellescape
  command = PhantomJS.new(runner, url)
  @passed = command.run
end

#start_serverObject



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

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

#stop_serverObject



62
63
64
# File 'opal/lib/mspec/opal/rake_task.rb', line 62

def stop_server
  server.kill
end