guard-jasmine 1.8.3 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -0
- data/lib/guard/jasmine.rb +3 -1
- data/lib/guard/jasmine/server.rb +52 -26
- data/lib/guard/jasmine/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -361,6 +361,11 @@ The server options configures the server environment that is needed to run Guard
|
|
361
361
|
|
362
362
|
:timeout => 20000 # The time in ms to wait for the spec runner to finish.
|
363
363
|
# default: 10000
|
364
|
+
|
365
|
+
:rackup_config => 'spec/dummy/config.ru' # Path to rackup config file (i.e. for webrick, mongrel, thin, unicorn).
|
366
|
+
# default: ./config.ru
|
367
|
+
# This option is useful when using guard-jasmine in a mountable engine
|
368
|
+
# and the config.ru is within the dummy app
|
364
369
|
```
|
365
370
|
|
366
371
|
If you're setting the `:server` option to `:none`, you can supply the Jasmine runner url manually:
|
data/lib/guard/jasmine.rb
CHANGED
@@ -25,6 +25,7 @@ module Guard
|
|
25
25
|
:server_env => ENV['RAILS_ENV'] || 'development',
|
26
26
|
:server_timeout => 15,
|
27
27
|
:port => 8888,
|
28
|
+
:rackup_config => nil,
|
28
29
|
:jasmine_url => 'http://localhost:8888/jasmine',
|
29
30
|
:timeout => 10000,
|
30
31
|
:spec_dir => 'spec/javascripts',
|
@@ -49,6 +50,7 @@ module Guard
|
|
49
50
|
# @option options [String] :server_env the server environment to use, for example :development, :test
|
50
51
|
# @option options [Integer] :server_timeout the number of seconds to wait for the Jasmine spec server
|
51
52
|
# @option options [String] :port the port for the Jasmine test server
|
53
|
+
# @option options [String] :rackup_config custom rackup config to use
|
52
54
|
# @option options [String] :jasmine_url the url of the Jasmine test runner
|
53
55
|
# @option options [String] :phantomjs_bin the location of the PhantomJS binary
|
54
56
|
# @option options [Integer] :timeout the maximum time in milliseconds to wait for the spec runner to finish
|
@@ -88,7 +90,7 @@ module Guard
|
|
88
90
|
def start
|
89
91
|
if Jasmine.phantomjs_bin_valid?(options[:phantomjs_bin])
|
90
92
|
|
91
|
-
Server.start(options
|
93
|
+
Server.start(options) unless options[:server] == :none
|
92
94
|
|
93
95
|
if Jasmine.runner_available?(options)
|
94
96
|
run_all if options[:all_on_start]
|
data/lib/guard/jasmine/server.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
require 'socket'
|
4
|
+
require 'timeout'
|
3
5
|
require 'childprocess'
|
4
6
|
|
5
7
|
module Guard
|
@@ -15,31 +17,36 @@ module Guard
|
|
15
17
|
|
16
18
|
# Start the internal test server for getting the Jasmine runner.
|
17
19
|
#
|
18
|
-
# @param [
|
19
|
-
# @
|
20
|
-
# @
|
21
|
-
# @
|
20
|
+
# @param [Hash] options the server options
|
21
|
+
# @option options [String] server the server to use
|
22
|
+
# @option options [Number] port the server port
|
23
|
+
# @option options [String] server_env the Rails environment
|
24
|
+
# @option options [String] spec_dir the spec directory
|
25
|
+
# @option options [String] rackup_config custom rackup config to use (i.e. spec/dummy/config.ru for mountable engines)
|
22
26
|
#
|
23
|
-
def start(
|
24
|
-
|
27
|
+
def start(options)
|
28
|
+
server = options[:server]
|
29
|
+
server = detect_server(options[:spec_dir]) if server == :auto
|
30
|
+
port = options[:port]
|
31
|
+
timeout = options[:server_timeout]
|
25
32
|
|
26
|
-
case
|
33
|
+
case server
|
27
34
|
when :webrick, :mongrel, :thin, :unicorn
|
28
|
-
start_rack_server(
|
35
|
+
start_rack_server(options)
|
29
36
|
when :jasmine_gem
|
30
37
|
start_rake_server(port, 'jasmine')
|
31
38
|
else
|
32
|
-
start_rake_server(port,
|
39
|
+
start_rake_server(port, server.to_s) unless server == :none
|
33
40
|
end
|
34
41
|
|
35
|
-
wait_for_server(port) unless
|
42
|
+
wait_for_server(port, timeout) unless server == :none
|
36
43
|
end
|
37
44
|
|
38
45
|
# Stop the server thread.
|
39
46
|
#
|
40
47
|
def stop
|
41
48
|
if self.process
|
42
|
-
::Guard::UI.info
|
49
|
+
::Guard::UI.info 'Guard::Jasmine stops server.'
|
43
50
|
self.process.stop(5)
|
44
51
|
end
|
45
52
|
end
|
@@ -50,14 +57,21 @@ module Guard
|
|
50
57
|
# will simply start a server that uses the `config.ru`
|
51
58
|
# in the current directory.
|
52
59
|
#
|
53
|
-
# @param [
|
54
|
-
# @
|
55
|
-
# @
|
60
|
+
# @param [Hash] options the server options
|
61
|
+
# @option options [Symbol] server the rack server to use
|
62
|
+
# @option options [String] server_env the Rails environment
|
63
|
+
# @option options [Number] port the server port
|
64
|
+
# @option options [String] rackup_config custom rackup config to use (i.e. spec/dummy/config.ru for mountable engines)
|
56
65
|
#
|
57
|
-
def start_rack_server(
|
66
|
+
def start_rack_server(options)
|
67
|
+
server = options[:server]
|
68
|
+
environment = options[:server_env]
|
69
|
+
port = options[:port]
|
70
|
+
rackup_config = options[:rackup_config]
|
71
|
+
|
58
72
|
::Guard::UI.info "Guard::Jasmine starts #{ server } test server on port #{ port } in #{ environment } environment."
|
59
73
|
|
60
|
-
self.process = ChildProcess.build('rackup', '-E', environment.to_s, '-p', port.to_s, '-s', server.to_s)
|
74
|
+
self.process = ChildProcess.build(*['rackup', '-E', environment.to_s, '-p', port.to_s, '-s', server.to_s, rackup_config].compact)
|
61
75
|
self.process.io.inherit! if ::Guard.respond_to?(:options) && ::Guard.options && ::Guard.options[:verbose]
|
62
76
|
self.process.start
|
63
77
|
|
@@ -88,6 +102,14 @@ module Guard
|
|
88
102
|
#
|
89
103
|
def detect_server(spec_dir)
|
90
104
|
if File.exists?('config.ru')
|
105
|
+
%w(unicorn thin mongrel).each do |server|
|
106
|
+
begin
|
107
|
+
require server
|
108
|
+
return server.to_sym
|
109
|
+
rescue LoadError
|
110
|
+
# Ignore missing server and try next
|
111
|
+
end
|
112
|
+
end
|
91
113
|
:webrick
|
92
114
|
elsif File.exists?(File.join(spec_dir, 'support', 'jasmine.yml'))
|
93
115
|
:jasmine_gem
|
@@ -99,19 +121,23 @@ module Guard
|
|
99
121
|
# Wait until the Jasmine test server is running.
|
100
122
|
#
|
101
123
|
# @param [Number] port the server port
|
124
|
+
# @param [Number] timeout the server wait timeout
|
102
125
|
#
|
103
|
-
def wait_for_server(port)
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
126
|
+
def wait_for_server(port, timeout)
|
127
|
+
Timeout::timeout(timeout) do
|
128
|
+
while true
|
129
|
+
begin
|
130
|
+
::TCPSocket.new('127.0.0.1', port).close
|
131
|
+
break
|
132
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
133
|
+
# Ignore, server still not available
|
134
|
+
end
|
135
|
+
sleep 0.1
|
112
136
|
end
|
113
|
-
sleep 0.1
|
114
137
|
end
|
138
|
+
|
139
|
+
rescue Timeout::Error
|
140
|
+
::Guard::UI.warning 'Timeout while waiting for the server startup.'
|
115
141
|
end
|
116
142
|
|
117
143
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-jasmine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: guard
|
@@ -139,7 +139,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
139
|
version: '0'
|
140
140
|
segments:
|
141
141
|
- 0
|
142
|
-
hash:
|
142
|
+
hash: 3448154215617801820
|
143
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
144
|
none: false
|
145
145
|
requirements:
|