Class: Jasmine::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/jasmine/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port, config) ⇒ Server

Returns a new instance of Server.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/jasmine/server.rb', line 92

def initialize(port, config)
  @port = port
  @config = config

  require 'thin'
  thin_config = {
    '/__suite__' => Jasmine::FocusedSuite.new(@config),
    '/run.html' => Jasmine::Redirect.new('/'),
    '/' => Jasmine::RunAdapter.new(@config)
  }

  @config.mappings.each do |from, to|
    thin_config[from] = Rack::File.new(to)
  end

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

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

  @thin = Thin::Server.new('0.0.0.0', @port, app)
end

Instance Attribute Details

#thinObject (readonly)

Returns the value of attribute thin.



90
91
92
# File 'lib/jasmine/server.rb', line 90

def thin
  @thin
end

Instance Method Details

#startObject



117
118
119
120
121
122
123
124
# File 'lib/jasmine/server.rb', line 117

def start
  begin
    thin.start
  rescue RuntimeError => e
    raise e unless e.message == 'no acceptor'
    raise RuntimeError.new("A server is already running on port #{@port}")
  end
end

#stopObject



126
127
128
# File 'lib/jasmine/server.rb', line 126

def stop
  thin.stop
end