Module: Guard::Jasmine::Server
- Defined in:
- lib/guard/jasmine/server.rb
Overview
Start and stop a Jasmine test server for requesting the specs from PhantomJS.
Class Attribute Summary (collapse)
-
+ (Object) process
Returns the value of attribute process.
Class Method Summary (collapse)
-
+ (Symbol) detect_server(spec_dir)
Detect the server to use.
-
+ (Object) start(options)
Start the internal test server for getting the Jasmine runner.
-
+ (Object) start_rack_server(server, port, options)
private
Start the Rack server of the current project.
-
+ (Object) start_rake_server(port, task, options)
private
Start the Jasmine gem server of the current project.
-
+ (Object) start_unicorn_server(port, options)
private
Start the Rack server of the current project.
-
+ (Object) stop
Stop the server thread.
-
+ (Object) wait_for_server(port, timeout)
private
Wait until the Jasmine test server is running.
Class Attribute Details
+ (Object) process
Returns the value of attribute process
16 17 18 |
# File 'lib/guard/jasmine/server.rb', line 16 def process @process end |
Class Method Details
+ (Symbol) detect_server(spec_dir)
Detect the server to use
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/guard/jasmine/server.rb', line 61 def detect_server(spec_dir) if File.exists?('config.ru') %w(unicorn thin mongrel puma).each do |server| begin require server return server.to_sym rescue LoadError # Ignore missing server and try next end end :webrick elsif spec_dir && File.exists?(File.join(spec_dir, 'support', 'jasmine.yml')) :jasmine_gem else :none end end |
+ (Object) start(options)
Start the internal test server for getting the Jasmine runner.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/guard/jasmine/server.rb', line 28 def start() server = [:server] port = [:port] timeout = [:server_timeout] case server when :webrick, :mongrel, :thin, :puma start_rack_server(server, port, ) when :unicorn start_unicorn_server(port, ) when :jasmine_gem start_rake_server(port, 'jasmine', ) else start_rake_server(port, server.to_s, ) unless server == :none end wait_for_server(port, timeout) unless server == :none end |
+ (Object) start_rack_server(server, port, options) (private)
Start the Rack server of the current project. This
will simply start a server that uses the config.ru
in the current directory.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/guard/jasmine/server.rb', line 92 def start_rack_server(server, port, ) environment = [:server_env] rackup_config = [:rackup_config] coverage = [:coverage] ? 'on' : 'off' ::Guard::UI.info "Guard::Jasmine starts #{ server } spec server on port #{ port } in #{ environment } environment (coverage #{ coverage })." self.process = ChildProcess.build(*['rackup', '-E', environment.to_s, '-p', port.to_s, '-s', server.to_s, rackup_config].compact) self.process.environment['COVERAGE'] = [:coverage].to_s self.process.io.inherit! if [:verbose] self.process.start rescue => e ::Guard::UI.error "Cannot start Rack server: #{ e. }" end |
+ (Object) start_rake_server(port, task, options) (private)
Start the Jasmine gem server of the current project.
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/guard/jasmine/server.rb', line 137 def start_rake_server(port, task, ) ::Guard::UI.info "Guard::Jasmine starts Jasmine Gem test server on port #{ port }." self.process = ChildProcess.build('ruby', '-S', 'rake', task, "JASMINE_PORT=#{ port }") self.process.io.inherit! if [:verbose] self.process.start rescue => e ::Guard::UI.error "Cannot start Rake task server: #{ e. }" end |
+ (Object) start_unicorn_server(port, options) (private)
Start the Rack server of the current project. This
will simply start a server that uses the config.ru
in the current directory.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/guard/jasmine/server.rb', line 116 def start_unicorn_server(port, ) environment = [:server_env] coverage = [:coverage] ? 'on' : 'off' ::Guard::UI.info "Guard::Jasmine starts Unicorn spec server on port #{ port } in #{ environment } environment (coverage #{ coverage })." self.process = ChildProcess.build('unicorn_rails', '-E', environment.to_s, '-p', port.to_s) self.process.environment['COVERAGE'] = [:coverage].to_s self.process.io.inherit! if [:verbose] self.process.start rescue => e ::Guard::UI.error "Cannot start Unicorn server: #{ e. }" end |
+ (Object) stop
Stop the server thread.
49 50 51 52 53 54 |
# File 'lib/guard/jasmine/server.rb', line 49 def stop if self.process ::Guard::UI.info 'Guard::Jasmine stops server.' self.process.stop(5) end end |
+ (Object) wait_for_server(port, timeout) (private)
Wait until the Jasmine test server is running.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/guard/jasmine/server.rb', line 153 def wait_for_server(port, timeout) Timeout::timeout(timeout) do while true begin ::TCPSocket.new('127.0.0.1', port).close break rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH # Ignore, server still not available end sleep 0.1 end end rescue Timeout::Error ::Guard::UI.warning 'Timeout while waiting for the server startup. You may need to increase the `:server_timeout` option.' throw :task_has_failed end |