Class: Jasmine::SimpleServer

Inherits:
Object
  • Object
show all
Defined in:
lib/jasmine-ruby/jasmine_runner.rb

Class Method Summary collapse

Class Method Details

.start(port, root_path, spec_files_or_proc, options = {}) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/jasmine-ruby/jasmine_runner.rb', line 151

def self.start(port, root_path, spec_files_or_proc, options = {})
  require 'thin'
  config = {
    '/__suite__' => Jasmine::FocusedSuite.new(spec_files_or_proc, options),
    '/run.html' => Jasmine::Redirect.new('/'),
    '/' => Jasmine::RunAdapter.new(spec_files_or_proc, options)
  }
  if (options[:mappings])
    options[:mappings].each do |from, to|
      config[from] = Rack::File.new(to)
    end
  end

  config["/__JASMINE_ROOT__"] = Rack::File.new(Jasmine.root)

  file_serve_config = {
    '/' => Rack::File.new(root_path)
  }

  app = Rack::Cascade.new([
    Rack::URLMap.new(file_serve_config),
    Rack::URLMap.new(config),
    JsAlert.new
  ])

  begin
    Thin::Server.start('0.0.0.0', port, app)
  rescue RuntimeError => e
    raise e unless e.message == 'no acceptor'
    raise RuntimeError.new("A server is already running on port #{port}")
  end
end