guard-jasmine 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +125 -120
- data/lib/guard/jasmine.rb +18 -1
- data/lib/guard/jasmine/cli.rb +25 -2
- data/lib/guard/jasmine/server.rb +111 -0
- data/lib/guard/jasmine/version.rb +1 -1
- metadata +33 -16
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Guard::Jasmine [](http://travis-ci.org/netzpirat/guard-jasmine)
|
2
2
|
|
3
|
-
Guard::Jasmine automatically tests your Jasmine specs when files are modified.
|
3
|
+
Guard::Jasmine automatically tests your Jasmine specs on Rails when files are modified.
|
4
4
|
|
5
5
|
Tested on MRI Ruby 1.8.7, 1.9.2, 1.9.3, REE and the latest versions of JRuby & Rubinius.
|
6
6
|
|
@@ -22,21 +22,6 @@ various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.
|
|
22
22
|
|
23
23
|
* Runs on Mac OS X, Linux and Windows.
|
24
24
|
|
25
|
-
## How it works
|
26
|
-
|
27
|
-

|
28
|
-
|
29
|
-
1. Guard is triggered by a file modification.
|
30
|
-
2. Guard::Jasmine executes the [PhantomJS script][].
|
31
|
-
3. The PhantomJS script requests the Jasmine test runner via HTTP.
|
32
|
-
4. Rails uses the asset pipeline to get the Jasmine runner, the code to be tested and the specs.
|
33
|
-
5. The asset pipeline prepares the assets, compiles the CoffeeScripts if necessary.
|
34
|
-
6. The asset pipeline has finished to prepare the needed assets.
|
35
|
-
7. Rails returns the Jasmine runner HTML.
|
36
|
-
8. PhantomJS requests linked assets and runs the Jasmine tests headless.
|
37
|
-
9. The PhantomJS script extracts the result from the DOM and returns a JSON report.
|
38
|
-
10. Guard::Jasmine reports the results to the console and system notifications.
|
39
|
-
|
40
25
|
## Install
|
41
26
|
|
42
27
|
### Guard and Guard::Jasmine
|
@@ -47,7 +32,7 @@ Please make sure to have [Guard][] installed.
|
|
47
32
|
Add Guard::Jasmine to your `Gemfile`:
|
48
33
|
|
49
34
|
```ruby
|
50
|
-
group :development do
|
35
|
+
group :development, :test do
|
51
36
|
gem 'guard-jasmine'
|
52
37
|
end
|
53
38
|
```
|
@@ -58,10 +43,52 @@ Add the default Guard::Jasmine template to your `Guardfile` by running:
|
|
58
43
|
$ guard init jasmine
|
59
44
|
```
|
60
45
|
|
61
|
-
###
|
46
|
+
### PhantomJS
|
47
|
+
|
48
|
+
You need the PhantomJS browser installed on your system. You can download binaries for Mac OS X and Windows from
|
49
|
+
[the PhantomJS download section][].
|
50
|
+
|
51
|
+
Alternatively you can install [Homebrew][] on Mac OS X and install it with:
|
52
|
+
|
53
|
+
```bash
|
54
|
+
$ brew install phantomjs
|
55
|
+
```
|
56
|
+
|
57
|
+
If you are using Ubuntu 10.10, you can install it with apt:
|
58
|
+
|
59
|
+
```bash
|
60
|
+
$ sudo add-apt-repository ppa:jerome-etienne/neoip
|
61
|
+
$ sudo apt-get update
|
62
|
+
$ sudo apt-get install phantomjs
|
63
|
+
```
|
64
|
+
|
65
|
+
You can also build it from source for several other operating systems, please consult the
|
66
|
+
[PhantomJS build instructions][].
|
67
|
+
|
68
|
+
## Rails 3.1 setup
|
62
69
|
|
63
70
|
With Rails 3.1 you can write your Jasmine specs in addition to JavaScript with CoffeeScript, fully integrated into the
|
64
|
-
Rails 3.1 asset pipeline with Jasminerice.
|
71
|
+
Rails 3.1 asset pipeline with [Jasminerice][]. You have full access to your running Rails app, but it's a good practice
|
72
|
+
to fake the server response. Check out the excellent [Sinon.JS][] documentation to learn more about this topic.
|
73
|
+
|
74
|
+
Guard::Jasmine will start a Rails Rack server to run your specs.
|
75
|
+
|
76
|
+
### How it works
|
77
|
+
|
78
|
+

|
79
|
+
|
80
|
+
1. Guard is triggered by a file modification.
|
81
|
+
2. Guard::Jasmine executes the [PhantomJS script][].
|
82
|
+
3. The PhantomJS script requests the Jasmine test runner via HTTP.
|
83
|
+
4. Rails uses the asset pipeline to get the Jasmine runner, the code to be tested and the specs.
|
84
|
+
5. The asset pipeline prepares the assets, compiles the CoffeeScripts if necessary.
|
85
|
+
6. The asset pipeline has finished to prepare the needed assets.
|
86
|
+
7. Rails returns the Jasmine runner HTML.
|
87
|
+
8. PhantomJS requests linked assets and runs the Jasmine tests headless.
|
88
|
+
9. The PhantomJS script collects the Jasmine runner results and returns a JSON report.
|
89
|
+
10. Guard::Jasmine reports the results to the console and system notifications.
|
90
|
+
|
91
|
+
### Jasminerice
|
65
92
|
|
66
93
|
Please read the detailed installation and configuration instructions at [Jasminerice][].
|
67
94
|
|
@@ -88,27 +115,64 @@ asset pipeline manifest in `spec/javascripts/spec.js.coffee`:
|
|
88
115
|
#=require_tree ./
|
89
116
|
```
|
90
117
|
|
91
|
-
|
118
|
+
## Rails 2 & Rails 3 setup
|
92
119
|
|
93
|
-
|
94
|
-
|
120
|
+
With Rails 2 or Rails 3 you can use [the Jasmine Gem][] to configure your Jasmine specs and server the Jasmine
|
121
|
+
runner. You don't have full access to your running Rails app, but it's anyway a good practice to fake the server
|
122
|
+
response. Check out the excellent [Sinon.JS][] documentation to learn more about this topic.
|
95
123
|
|
96
|
-
|
124
|
+
Guard::Jasmine will start a Jasmine Gem Rack server to run your specs.
|
125
|
+
|
126
|
+
### How it works
|
127
|
+
|
128
|
+

|
129
|
+
|
130
|
+
1. Guard is triggered by a file modification.
|
131
|
+
2. Guard::Jasmine executes the [PhantomJS script][].
|
132
|
+
3. The PhantomJS script requests the Jasmine test runner via HTTP.
|
133
|
+
4. The Jasmine Gem reads your configuration and get the assets.
|
134
|
+
5. The Jasmine Gem serves the the code to be tested and the specs.
|
135
|
+
6. PhantomJS runs the Jasmine tests headless.
|
136
|
+
7. The PhantomJS script collects the Jasmine runner results and returns a JSON report.
|
137
|
+
8. Guard::Jasmine reports the results to the console and system notifications.
|
138
|
+
|
139
|
+
### Jasmine Gem
|
140
|
+
|
141
|
+
Please read the detailed installation and configuration instructions at [the Jasmine Gem][].
|
142
|
+
|
143
|
+
In short, you add it to your `Gemfile`:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
group :development, :test do
|
147
|
+
gem 'jasmine'
|
148
|
+
end
|
149
|
+
```
|
150
|
+
|
151
|
+
and generate the configuration files:
|
152
|
+
|
153
|
+
#### for Rails 3
|
97
154
|
|
98
155
|
```bash
|
99
|
-
$
|
156
|
+
$ rails g jasmine:install
|
100
157
|
```
|
101
158
|
|
102
|
-
|
159
|
+
#### for Rails 2
|
103
160
|
|
104
161
|
```bash
|
105
|
-
$
|
106
|
-
$ sudo apt-get update
|
107
|
-
$ sudo apt-get install phantomjs
|
162
|
+
$ script/generate jasmine
|
108
163
|
```
|
109
164
|
|
110
|
-
|
111
|
-
|
165
|
+
Now you can configure your spec suite in the Jasmine configuration file `specs/javascripts/support/jasmine.yml`.
|
166
|
+
|
167
|
+
#### Writing CoffeeScript specs
|
168
|
+
|
169
|
+
It is also possible to use CoffeeScript in this setup, by using [Guard::CoffeeScript][] to compile your code and even
|
170
|
+
specs. Just add something like this *before* Guard::Jasmine:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
guard 'coffeescript', :input => 'app/coffeescripts', :output => 'public/javascripts'
|
174
|
+
guard 'coffeescript', :input => 'spec/coffeescripts', :output => 'spec/javascripts'
|
175
|
+
```
|
112
176
|
|
113
177
|
## Usage
|
114
178
|
|
@@ -143,8 +207,11 @@ end
|
|
143
207
|
The general options configures the environment that is needed to run Guard::Jasmine:
|
144
208
|
|
145
209
|
```ruby
|
146
|
-
:
|
147
|
-
# default:
|
210
|
+
:server => :jasmine # Jasmine server to use, either :auto, :rack, :jasmine_gem or :none
|
211
|
+
# default: :auto
|
212
|
+
|
213
|
+
:port => 9292 # Jasmine server port to use.
|
214
|
+
# default: 8888
|
148
215
|
|
149
216
|
:phantomjs_bin => '~/bin/phantomjs' # Path to phantomjs.
|
150
217
|
# default: '/usr/local/bin/phantomjs'
|
@@ -153,6 +220,13 @@ The general options configures the environment that is needed to run Guard::Jasm
|
|
153
220
|
# default: 10000
|
154
221
|
```
|
155
222
|
|
223
|
+
If you're setting the `:server` option to `:none`, you can supply the Jasmine runner url manually:
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
:jasmine_url => 'http://192.168.1.5/jasmine' # URL where Jasmine is served.
|
227
|
+
# default: http://127.0.0.1:8888/jasmine
|
228
|
+
```
|
229
|
+
|
156
230
|
### Spec runner options
|
157
231
|
|
158
232
|
The spec runner options configures the behavior driven development (or BDD) cycle:
|
@@ -229,81 +303,6 @@ These options affects what system notifications (growl, libnotify or notifu) are
|
|
229
303
|
# default: 3
|
230
304
|
```
|
231
305
|
|
232
|
-
## A note on Rails 2 and 3
|
233
|
-
|
234
|
-
This readme describes the use of Guard::Jasmine with Jasminerice through the asset pipeline, but it is not really
|
235
|
-
a requirement for Guard::Jasmine. As long as you serve the Jasmine test runner under a certain url,
|
236
|
-
it's freely up to you how you'll prepare the assets and serve the Jasmine runner.
|
237
|
-
|
238
|
-
You can use [the Jasmine Gem][], configure the test suite in `jasmine.yml` and start the Jasmine test runner with
|
239
|
-
the supplied Rake task:
|
240
|
-
|
241
|
-
```bash
|
242
|
-
$ rake jasmine
|
243
|
-
```
|
244
|
-
|
245
|
-
Next follows an example on how to configure your `Guardfile` with the Jasmine gem:
|
246
|
-
|
247
|
-
```ruby
|
248
|
-
guard 'jasmine', :jasmine_url => 'http://127.0.0.1:8888' do
|
249
|
-
watch(%r{public/javascripts/(.+)\.js}) { |m| "spec/javascripts/#{m[1]}_spec.js" }
|
250
|
-
watch(%r{spec/javascripts/(.+)_spec\.js}) { |m| "spec/javascripts/#{m[1]}_spec.js" }
|
251
|
-
watch(%r{spec/javascripts/support/jasmine\.yml}) { "spec/javascripts" }
|
252
|
-
watch(%r{spec/javascripts/support/jasmine_config\.rb}) { "spec/javascripts" }
|
253
|
-
end
|
254
|
-
```
|
255
|
-
|
256
|
-
You can also use [guard-process](https://github.com/socialreferral/guard-process) to start the Jasmine Gem server when
|
257
|
-
Guard starts:
|
258
|
-
|
259
|
-
```ruby
|
260
|
-
guard 'process', :name => 'Jasmine server', :command => 'bundle exec rake jasmine' do
|
261
|
-
watch(%r{spec/javascripts/support/*})
|
262
|
-
end
|
263
|
-
|
264
|
-
JASMINE_HOST = '127.0.0.1'
|
265
|
-
JASMINE_PORT = '8888'
|
266
|
-
JASMINE_URL = "http://#{JASMINE_HOST}:#{JASMINE_PORT}/"
|
267
|
-
|
268
|
-
Thread.new do
|
269
|
-
require 'socket'
|
270
|
-
|
271
|
-
puts "\nWaiting for Jasmine to accept connections on #{JASMINE_URL}..."
|
272
|
-
wait_for_open_connection(JASMINE_HOST, JASMINE_PORT)
|
273
|
-
puts "Jasmine is now ready to accept connections; change a file or press ENTER run your suite."
|
274
|
-
puts "You can also view and run specs by visiting:"
|
275
|
-
puts JASMINE_URL
|
276
|
-
|
277
|
-
guard 'jasmine', :jasmine_url => JASMINE_URL do
|
278
|
-
watch(%r{public/javascripts/(.+)\.js}) { |m| "spec/javascripts/#{m[1]}_spec.js" }
|
279
|
-
watch(%r{spec/javascripts/(.+)_spec\.js}) { |m| "spec/javascripts/#{m[1]}_spec.js" }
|
280
|
-
watch(%r{spec/javascripts/support/jasmine\.yml}) { "spec/javascripts" }
|
281
|
-
watch(%r{spec/javascripts/support/jasmine_config\.rb}) { "spec/javascripts" }
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
def wait_for_open_connection(host, port)
|
286
|
-
while true
|
287
|
-
begin
|
288
|
-
TCPSocket.new(host, port).close
|
289
|
-
return
|
290
|
-
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
291
|
-
end
|
292
|
-
end
|
293
|
-
end
|
294
|
-
```
|
295
|
-
|
296
|
-
This elegant solution is provided by [Jason Morrison](http://twitter.com/#!/jayunit), see his original
|
297
|
-
[Gist](https://gist.github.com/1224382).
|
298
|
-
|
299
|
-
It is also possible to use CoffeeScript in this setup, by using [Guard::CoffeeScript][] to compile your code and even
|
300
|
-
specs. Just add something like this *before* Guard::Jasmine:
|
301
|
-
|
302
|
-
```ruby
|
303
|
-
guard 'coffeescript', :input => 'app/coffeescripts', :output => 'public/javascripts'
|
304
|
-
guard 'coffeescript', :input => 'spec/coffeescripts', :output => 'spec/javascripts'
|
305
|
-
```
|
306
|
-
|
307
306
|
## Guard::Jasmine for your CI server
|
308
307
|
|
309
308
|
Guard::Jasmine includes a little command line utility to run your specs once and output the specdoc to the console.
|
@@ -315,19 +314,24 @@ $ guard-jasmine
|
|
315
314
|
You can get help on the available options with the `help` task:
|
316
315
|
|
317
316
|
```bash
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
317
|
+
Usage:
|
318
|
+
guard-jasmine spec
|
319
|
+
|
320
|
+
Options:
|
321
|
+
-s, [--server=SERVER] # Server to start, either `auto`, `rack`, `jasmine_gem` or `none`
|
322
|
+
# Default: auto
|
323
|
+
-p, [--port=N] # Server port to use
|
324
|
+
# Default: 8888
|
325
|
+
-u, [--url=URL] # The url of the Jasmine test runner
|
326
|
+
# Default: http://127.0.0.1:8888/jasmine
|
327
|
+
-b, [--bin=BIN] # The location of the PhantomJS binary
|
328
|
+
# Default: /usr/local/bin/phantomjs
|
329
|
+
-t, [--timeout=N] # The maximum time in milliseconds to wait for the spec runner to finish
|
330
|
+
# Default: 10000
|
331
|
+
-c, [--console=CONSOLE] # Whether to show console.log statements in the spec runner, either `always`, `never` or `failure`
|
332
|
+
# Default: failure
|
333
|
+
|
334
|
+
Run the Jasmine spec runner
|
331
335
|
```
|
332
336
|
|
333
337
|
By default all specs are run, but you can supply multiple paths to your specs to run only a subset:
|
@@ -466,3 +470,4 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
466
470
|
[Evergreen]: https://github.com/jnicklas/evergreen
|
467
471
|
[PhantomJS script]: https://github.com/netzpirat/guard-jasmine/blob/master/lib/guard/jasmine/phantomjs/run-jasmine.coffee
|
468
472
|
[Guard::CoffeeScript]: https://github.com/guard/guard-coffeescript
|
473
|
+
[Sinon.JS]: http://sinonjs.org
|
data/lib/guard/jasmine.rb
CHANGED
@@ -14,11 +14,14 @@ module Guard
|
|
14
14
|
autoload :Formatter, 'guard/jasmine/formatter'
|
15
15
|
autoload :Inspector, 'guard/jasmine/inspector'
|
16
16
|
autoload :Runner, 'guard/jasmine/runner'
|
17
|
+
autoload :Server, 'guard/jasmine/server'
|
17
18
|
|
18
19
|
attr_accessor :last_run_failed, :last_failed_paths
|
19
20
|
|
20
21
|
DEFAULT_OPTIONS = {
|
21
|
-
:
|
22
|
+
:server => :auto,
|
23
|
+
:port => 8888,
|
24
|
+
:jasmine_url => 'http://localhost:8888/jasmine',
|
22
25
|
:phantomjs_bin => '/usr/local/bin/phantomjs',
|
23
26
|
:timeout => 10000,
|
24
27
|
:notification => true,
|
@@ -36,6 +39,8 @@ module Guard
|
|
36
39
|
#
|
37
40
|
# @param [Array<Guard::Watcher>] watchers the watchers in the Guard block
|
38
41
|
# @param [Hash] options the options for the Guard
|
42
|
+
# @option options [String] :server the server to use, either :rails or :jasmine
|
43
|
+
# @option options [String] :port the port for the Jasmine test server
|
39
44
|
# @option options [String] :jasmine_url the url of the Jasmine test runner
|
40
45
|
# @option options [String] :phantomjs_bin the location of the PhantomJS binary
|
41
46
|
# @option options [Integer] :timeout the maximum time in milliseconds to wait for the spec runner to finish
|
@@ -52,6 +57,7 @@ module Guard
|
|
52
57
|
def initialize(watchers = [], options = { })
|
53
58
|
options = DEFAULT_OPTIONS.merge(options)
|
54
59
|
options[:specdoc] = :failure if ![:always, :never, :failure].include? options[:specdoc]
|
60
|
+
options[:server] = :auto if ![:auto, :none, :rack, :jasmine_gem].include? options[:server]
|
55
61
|
|
56
62
|
super(watchers, options)
|
57
63
|
|
@@ -65,6 +71,9 @@ module Guard
|
|
65
71
|
#
|
66
72
|
def start
|
67
73
|
if phantomjs_bin_valid?(options[:phantomjs_bin])
|
74
|
+
|
75
|
+
Server.start(options[:server], options[:port]) unless options[:server] == :none
|
76
|
+
|
68
77
|
if jasmine_runner_available?(options[:jasmine_url])
|
69
78
|
run_all if options[:all_on_start]
|
70
79
|
end
|
@@ -73,6 +82,14 @@ module Guard
|
|
73
82
|
end
|
74
83
|
end
|
75
84
|
|
85
|
+
# Gets called once when Guard stops.
|
86
|
+
#
|
87
|
+
# @raise [:task_has_failed] when stop has failed
|
88
|
+
#
|
89
|
+
def stop
|
90
|
+
Server.stop
|
91
|
+
end
|
92
|
+
|
76
93
|
# Gets called when the Guard should reload itself.
|
77
94
|
#
|
78
95
|
# @raise [:task_has_failed] when run_on_change has failed
|
data/lib/guard/jasmine/cli.rb
CHANGED
@@ -3,6 +3,7 @@ require 'guard/ui'
|
|
3
3
|
require 'guard/jasmine/version'
|
4
4
|
require 'guard/jasmine/runner'
|
5
5
|
require 'guard/jasmine/formatter'
|
6
|
+
require 'guard/jasmine/server'
|
6
7
|
|
7
8
|
module Guard
|
8
9
|
class Jasmine
|
@@ -19,10 +20,22 @@ module Guard
|
|
19
20
|
|
20
21
|
desc 'spec', 'Run the Jasmine spec runner'
|
21
22
|
|
23
|
+
method_option :server,
|
24
|
+
:type => :string,
|
25
|
+
:aliases => '-s',
|
26
|
+
:default => 'auto',
|
27
|
+
:desc => 'Server to start, either `auto`, `rack`, `jasmine_gem` or `none`'
|
28
|
+
|
29
|
+
method_option :port,
|
30
|
+
:type => :numeric,
|
31
|
+
:aliases => '-p',
|
32
|
+
:default => 8888,
|
33
|
+
:desc => 'Server port to use'
|
34
|
+
|
22
35
|
method_option :url,
|
23
36
|
:type => :string,
|
24
37
|
:aliases => '-u',
|
25
|
-
:default => 'http://127.0.0.1:
|
38
|
+
:default => 'http://127.0.0.1:8888/jasmine',
|
26
39
|
:desc => 'The url of the Jasmine test runner'
|
27
40
|
|
28
41
|
method_option :bin,
|
@@ -55,18 +68,28 @@ module Guard
|
|
55
68
|
runner[:jasmine_url] = options.url
|
56
69
|
runner[:phantomjs_bin] = options.bin
|
57
70
|
runner[:timeout] = options.timeout
|
71
|
+
runner[:port] = options.port
|
58
72
|
runner[:console] = [:always, :never, :failure].include?(options.console.to_sym) ? options.console.to_sym : :failure
|
73
|
+
runner[:server] = [:auto, :rack, :jasmine_gem].include?(options.server.to_sym) ? options.server.to_sym : :auto
|
59
74
|
|
60
75
|
runner[:notification] = false
|
61
76
|
runner[:hide_success] = true
|
62
77
|
runner[:max_error_notify] = 0
|
63
78
|
runner[:specdoc] = :always
|
64
79
|
|
80
|
+
::Guard::Jasmine::Server.start(runner[:server], runner[:port]) unless runner[:server] == :none
|
65
81
|
result = ::Guard::Jasmine::Runner.run(paths, runner)
|
66
|
-
|
82
|
+
|
83
|
+
::Guard::Jasmine::Server.stop
|
84
|
+
|
85
|
+
exit_code = result.first ? 0 : 1
|
86
|
+
Process.exit exit_code
|
67
87
|
|
68
88
|
rescue Exception => e
|
89
|
+
raise e if e.is_a?(SystemExit)
|
90
|
+
|
69
91
|
::Guard::UI.error e.message
|
92
|
+
Process.exit 2
|
70
93
|
end
|
71
94
|
|
72
95
|
desc 'version', 'Show the Guard::Jasmine version'
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Guard
|
4
|
+
class Jasmine
|
5
|
+
|
6
|
+
# Start and stop a Jasmine test server for requesting the specs
|
7
|
+
# from PhantomJS.
|
8
|
+
#
|
9
|
+
module Server
|
10
|
+
class << self
|
11
|
+
|
12
|
+
attr_accessor :thread
|
13
|
+
|
14
|
+
# Start the internal test server for getting the Jasmine runner.
|
15
|
+
#
|
16
|
+
# @param [String] strategy the server strategy to use
|
17
|
+
# @param [Number] port the server port
|
18
|
+
#
|
19
|
+
def start(strategy, port)
|
20
|
+
strategy = detect_server if strategy == :auto
|
21
|
+
|
22
|
+
case strategy
|
23
|
+
when :rack
|
24
|
+
start_rack_server(port)
|
25
|
+
when :jasmine_gem
|
26
|
+
start_jasmine_gem_server(port)
|
27
|
+
end
|
28
|
+
|
29
|
+
wait_for_server(port) unless strategy == :none
|
30
|
+
end
|
31
|
+
|
32
|
+
# Stop the server thread.
|
33
|
+
#
|
34
|
+
def stop
|
35
|
+
self.thread.kill if self.thread && self.thread.alive?
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
# Start the Rack server of the current project. This
|
41
|
+
# will simply start a server that uses the `config.ru`
|
42
|
+
# in the current directory.
|
43
|
+
#
|
44
|
+
# @param [Number] port the server port
|
45
|
+
#
|
46
|
+
def start_rack_server(port)
|
47
|
+
require 'rack'
|
48
|
+
|
49
|
+
::Guard::UI.info "Guard::Jasmine starts Rack test server on port #{ port }."
|
50
|
+
|
51
|
+
self.thread = Thread.new { Rack::Server.start(:config => 'config.ru', :Port => port, :AccessLog => []) }
|
52
|
+
|
53
|
+
rescue Exception => e
|
54
|
+
::Guard::UI.error "Cannot start Rack server: #{ e.message }"
|
55
|
+
end
|
56
|
+
|
57
|
+
# Start the Jasmine gem server of the current project.
|
58
|
+
#
|
59
|
+
# @param [Number] port the server port
|
60
|
+
#
|
61
|
+
def start_jasmine_gem_server(port)
|
62
|
+
require 'jasmine/config'
|
63
|
+
|
64
|
+
jasmine_config_overrides = File.join(::Jasmine::Config.new.project_root, 'spec', 'javascripts' ,'support' ,'jasmine_config.rb')
|
65
|
+
require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
|
66
|
+
|
67
|
+
::Guard::UI.info "Guard::Jasmine starts Jasmine Gem test server on port #{ port }."
|
68
|
+
|
69
|
+
self.thread = Thread.new { ::Jasmine::Config.new.start_server(port) }
|
70
|
+
|
71
|
+
rescue Exception => e
|
72
|
+
::Guard::UI.error "Cannot start Jasmine Gem server: #{ e.message }"
|
73
|
+
end
|
74
|
+
|
75
|
+
# Detect the server to use
|
76
|
+
#
|
77
|
+
# @return [Symbol] the server strategy
|
78
|
+
#
|
79
|
+
def detect_server
|
80
|
+
if File.exists?('config.ru')
|
81
|
+
:rack
|
82
|
+
elsif File.exists?(File.join('spec', 'javascripts', 'support', 'jasmine.yml'))
|
83
|
+
:jasmine_gem
|
84
|
+
else
|
85
|
+
:none
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Wait until the Jasmine test server is running.
|
90
|
+
#
|
91
|
+
# @param [Number] port the server port
|
92
|
+
#
|
93
|
+
def wait_for_server(port)
|
94
|
+
require 'socket'
|
95
|
+
|
96
|
+
while true
|
97
|
+
begin
|
98
|
+
::TCPSocket.new('127.0.0.1', port).close
|
99
|
+
return
|
100
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
101
|
+
# Ignore, server still not available
|
102
|
+
end
|
103
|
+
sleep 0.1
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-jasmine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 61
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
|
-
-
|
10
|
-
version: 0.8.
|
9
|
+
- 1
|
10
|
+
version: 0.8.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Kessler
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-11-01 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: guard
|
@@ -82,9 +82,25 @@ dependencies:
|
|
82
82
|
type: :runtime
|
83
83
|
version_requirements: *id004
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
|
-
name:
|
85
|
+
name: rack
|
86
86
|
prerelease: false
|
87
87
|
requirement: &id005 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ~>
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 17
|
93
|
+
segments:
|
94
|
+
- 1
|
95
|
+
- 3
|
96
|
+
- 5
|
97
|
+
version: 1.3.5
|
98
|
+
type: :runtime
|
99
|
+
version_requirements: *id005
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
name: bundler
|
102
|
+
prerelease: false
|
103
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
88
104
|
none: false
|
89
105
|
requirements:
|
90
106
|
- - ~>
|
@@ -95,11 +111,11 @@ dependencies:
|
|
95
111
|
- 0
|
96
112
|
version: "1.0"
|
97
113
|
type: :development
|
98
|
-
version_requirements: *
|
114
|
+
version_requirements: *id006
|
99
115
|
- !ruby/object:Gem::Dependency
|
100
116
|
name: guard-rspec
|
101
117
|
prerelease: false
|
102
|
-
requirement: &
|
118
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
103
119
|
none: false
|
104
120
|
requirements:
|
105
121
|
- - ~>
|
@@ -110,11 +126,11 @@ dependencies:
|
|
110
126
|
- 5
|
111
127
|
version: "0.5"
|
112
128
|
type: :development
|
113
|
-
version_requirements: *
|
129
|
+
version_requirements: *id007
|
114
130
|
- !ruby/object:Gem::Dependency
|
115
131
|
name: rspec
|
116
132
|
prerelease: false
|
117
|
-
requirement: &
|
133
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
118
134
|
none: false
|
119
135
|
requirements:
|
120
136
|
- - ~>
|
@@ -125,11 +141,11 @@ dependencies:
|
|
125
141
|
- 7
|
126
142
|
version: "2.7"
|
127
143
|
type: :development
|
128
|
-
version_requirements: *
|
144
|
+
version_requirements: *id008
|
129
145
|
- !ruby/object:Gem::Dependency
|
130
146
|
name: yard
|
131
147
|
prerelease: false
|
132
|
-
requirement: &
|
148
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
133
149
|
none: false
|
134
150
|
requirements:
|
135
151
|
- - ~>
|
@@ -141,11 +157,11 @@ dependencies:
|
|
141
157
|
- 3
|
142
158
|
version: 0.7.3
|
143
159
|
type: :development
|
144
|
-
version_requirements: *
|
160
|
+
version_requirements: *id009
|
145
161
|
- !ruby/object:Gem::Dependency
|
146
162
|
name: redcarpet
|
147
163
|
prerelease: false
|
148
|
-
requirement: &
|
164
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
149
165
|
none: false
|
150
166
|
requirements:
|
151
167
|
- - ~>
|
@@ -157,11 +173,11 @@ dependencies:
|
|
157
173
|
- 2
|
158
174
|
version: 1.17.2
|
159
175
|
type: :development
|
160
|
-
version_requirements: *
|
176
|
+
version_requirements: *id010
|
161
177
|
- !ruby/object:Gem::Dependency
|
162
178
|
name: pry
|
163
179
|
prerelease: false
|
164
|
-
requirement: &
|
180
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
165
181
|
none: false
|
166
182
|
requirements:
|
167
183
|
- - ~>
|
@@ -174,7 +190,7 @@ dependencies:
|
|
174
190
|
- 2
|
175
191
|
version: 0.9.6.2
|
176
192
|
type: :development
|
177
|
-
version_requirements: *
|
193
|
+
version_requirements: *id011
|
178
194
|
description: Guard::Jasmine automatically tests your Jasmine specs on PhantomJS
|
179
195
|
email:
|
180
196
|
- michi@netzpiraten.ch
|
@@ -193,6 +209,7 @@ files:
|
|
193
209
|
- lib/guard/jasmine/inspector.rb
|
194
210
|
- lib/guard/jasmine/phantomjs/run-jasmine.coffee
|
195
211
|
- lib/guard/jasmine/runner.rb
|
212
|
+
- lib/guard/jasmine/server.rb
|
196
213
|
- lib/guard/jasmine/templates/Guardfile
|
197
214
|
- lib/guard/jasmine/version.rb
|
198
215
|
- lib/guard/jasmine.rb
|