guard-jasmine 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,37 +7,6 @@ Tested on MRI Ruby 1.8.7, 1.9.2, 1.9.3, REE and the latest versions of JRuby and
7
7
  If you have any questions please join us on our [Google group](http://groups.google.com/group/guard-dev) or on `#guard`
8
8
  (irc.freenode.net).
9
9
 
10
- ## Contents
11
-
12
- * [Highlights](#highlights)
13
- * [Installation](#installation)
14
- * [Guard and Guard::Jasmine](#guard-guard-jasmine)
15
- * [PhantomJS](#phantomjs)
16
- * [Rails with the asset pipeline](#asset-pipeline)
17
- * [How it works](#asset-pipeline-works)
18
- * [Jasminerice](#asset-pipeline-jasminerice)
19
- * [Jasmine Stories](#asset-pipeline-jasmine-stories)
20
- * [Rails without the asset pipeline and plain Ruby projects](#without-asset-pipeline)
21
- * [How it works](#without-asset-pipeline-works)
22
- * [Jasmine Gem](#without-asset-pipeline-jasmine-gem)
23
- * [Usage](#usage)
24
- * [Guardfile](#guardfile)
25
- * [Options](#options)
26
- * [Server options](#server-options)
27
- * [Use a custom server](#server-options-custom)
28
- * [Spec runner options](#spec-runner-options)
29
- * [Specdoc options](#specdoc-options)
30
- * [Console logs](#console-logs)
31
- * [System notifications options](#system-notifications-options)
32
- * [Mapping file changes to the spec filter](#file-mapping)
33
- * [Guard::Jasmine outside of Guard](#outside-guard)
34
- * [Thor command line utility](#thor)
35
- * [Rake task integration](#rake)
36
- * [Travis CI integration](#travis-ci)
37
- * [How to file an issue](#issues)
38
- * [Development information](#development-information)
39
-
40
- <a name="highlights" />
41
10
  ## Highlights
42
11
 
43
12
  * Continuous testing based on file modifications by [Guard][], manifold configuration by writing rules with RegExp and
@@ -56,10 +25,8 @@ various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.
56
25
 
57
26
  * Runs on Mac OS X, Linux and Windows.
58
27
 
59
- <a name="installation" />
60
28
  ## Installation
61
29
 
62
- <a name="guard-guard-jasmine" />
63
30
  ### Guard and Guard::Jasmine
64
31
 
65
32
  The simplest way to install Guard is to use [Bundler](http://gembundler.com/).
@@ -82,7 +49,6 @@ $ guard init jasmine
82
49
  Please have a look at the [CHANGELOG](https://github.com/netzpirat/guard-jasmine/blob/master/CHANGELOG.md) when
83
50
  upgrading to a newer Guard::Jasmine version.
84
51
 
85
- <a name="phantomjs" />
86
52
  ### PhantomJS
87
53
 
88
54
  You need the PhantomJS browser installed on your system. You can download binaries for Mac OS X and Windows from
@@ -105,7 +71,6 @@ $ sudo apt-get install phantomjs
105
71
  You can also build it from source for several other operating systems, please consult the
106
72
  [PhantomJS build instructions][].
107
73
 
108
- <a name="asset-pipeline" />
109
74
  ## Rails with the asset pipeline setup
110
75
 
111
76
  With Rails 3.1 and later you can write your Jasmine specs in addition to JavaScript with CoffeeScript, fully integrated
@@ -114,7 +79,6 @@ practice to fake the server response. Check out the excellent [Sinon.JS][] docum
114
79
 
115
80
  Guard::Jasmine will start a Rails Rack server to run your specs.
116
81
 
117
- <a name="asset-pipeline-works" />
118
82
  ### How it works
119
83
 
120
84
  ![Guard Jasmine](https://github.com/netzpirat/guard-jasmine/raw/master/resources/guard-jasmine-with-asset-pipeline.jpg)
@@ -130,7 +94,6 @@ Guard::Jasmine will start a Rails Rack server to run your specs.
130
94
  9. The PhantomJS script collects the Jasmine runner results and returns a JSON report.
131
95
  10. Guard::Jasmine reports the results to the console and system notifications.
132
96
 
133
- <a name="asset-pipeline-jasminerice" />
134
97
  ### Jasminerice
135
98
 
136
99
  Please read the detailed installation and configuration instructions at [Jasminerice][].
@@ -163,7 +126,6 @@ It also creates an empty `spec/javascripts/spec.css` file as it is always reques
163
126
 
164
127
  Now you can access `/jasmine` when you start your Rails server normally.
165
128
 
166
- <a name="asset-pipeline-jasmine-stories" />
167
129
  ### Jasmine Stories acceptance tests
168
130
 
169
131
  [Jasmine Stories](https://github.com/DominikGuzei/jasmine-stories) is a Jasminerice clone and that serves
@@ -196,7 +158,6 @@ guard :jasmine, :jasmine_url => 'http://127.0.0.1:8888/jasmine-stories' do
196
158
  end
197
159
  ```
198
160
 
199
- <a name="without-asset-pipeline" />
200
161
  ## Rails without the asset pipeline and plain Ruby projects
201
162
 
202
163
  With Rails without the asset pipeline or a plain Ruby project, you can use [the Jasmine Gem][] to configure your Jasmine
@@ -205,7 +166,6 @@ practice to fake the server response. Check out the excellent [Sinon.JS][] docum
205
166
 
206
167
  Guard::Jasmine will start a Jasmine Gem Rack server to run your specs.
207
168
 
208
- <a name="without-asset-pipeline-works" />
209
169
  ### How it works
210
170
 
211
171
  ![Guard Jasmine](https://github.com/netzpirat/guard-jasmine/raw/master/resources/guard-jasmine-without-asset-pipeline.jpg)
@@ -219,7 +179,6 @@ Guard::Jasmine will start a Jasmine Gem Rack server to run your specs.
219
179
  7. The PhantomJS script collects the Jasmine runner results and returns a JSON report.
220
180
  8. Guard::Jasmine reports the results to the console and system notifications.
221
181
 
222
- <a name="without-asset-pipeline-jasmine-gem" />
223
182
  ### Jasmine Gem
224
183
 
225
184
  Please read the detailed installation and configuration instructions at [the Jasmine Gem][].
@@ -248,9 +207,9 @@ Install the Jasmine gem in your Rails 3 app with:
248
207
  $ rails g jasmine:install
249
208
  ```
250
209
 
251
- #### Rails 2 and plain Ruby project
210
+ #### Rails 2
252
211
 
253
- Install the Jasmine gem in your Rails 2 app or a plain Ruby project with:
212
+ Install the Jasmine gem in your Rails 2 app with:
254
213
 
255
214
  ```bash
256
215
  $ script/generate jasmine
@@ -268,12 +227,77 @@ guard 'coffeescript', :input => 'app/coffeescripts', :output => 'public/javascr
268
227
  guard 'coffeescript', :input => 'spec/coffeescripts', :output => 'spec/javascripts'
269
228
  ```
270
229
 
271
- <a name="usage" />
230
+ ## Ruby projects
231
+
232
+ If you like to use Guard::Jasmine with a plain Ruby project, you can create a Rack configuration file
233
+ that starts a Rails instance with the asset pipeline and Jasminerice, having the full Rails testing
234
+ comfort for non-Rails projects. Please have a look at the Rails with the asset pipeline section above
235
+ to see how the setup works.
236
+
237
+ First you have the add the needed Gems to your `Gemfile`:
238
+
239
+ ```Ruby
240
+ group :assets do
241
+ gem 'coffee-script'
242
+ end
243
+
244
+ group :development, :test do
245
+ gem 'actionpack', '~> 3.2'
246
+ gem 'railties', '~> 3.2'
247
+ gem 'tzinfo'
248
+
249
+ gem 'thin'
250
+
251
+ gem 'jasminerice'
252
+ gem 'jquery-rails'
253
+ gem 'guard-jasmine'
254
+ end
255
+ ```
256
+
257
+ We add support for CoffeeScript specs, using Thin as spec server and adding Jasminerice and jQuery
258
+ (which is needed by Jasminerice) to the Gems. After installing the gems with `bundle`, we can
259
+ create a Rack configuration to spin up a mini-Rails app for testing:
260
+
261
+ ```Ruby
262
+ require 'rails'
263
+ require 'rails/all'
264
+ require 'jasminerice'
265
+ require 'sprockets/railtie'
266
+ require 'jquery-rails'
267
+
268
+ class JasmineTest < Rails::Application
269
+ routes.append do
270
+ mount Jasminerice::Engine => '/jasmine'
271
+ end
272
+
273
+ config.cache_classes = true
274
+ config.active_support.deprecation = :log
275
+ config.assets.enabled = true
276
+ config.assets.version = '1.0'
277
+ config.secret_token = '9696be98e32a5f213730cb7ed6161c79'
278
+ end
279
+
280
+ JasmineTest.initialize!
281
+ run JasmineTest
282
+ ```
283
+
284
+ The mini Rails app is now ready to start and serve the Jasmine specs. You only have to create
285
+ `spec/javascripts/spec.js.coffee`, the Jasminerice asset pipeline manifest, and configure the
286
+ assets:
287
+
288
+ ```CoffeeScript
289
+ #= require jquery
290
+ #= require_tree .
291
+ ```
292
+
293
+ Start the test server manually with `bundle exec rackup -p 3000` and visit `http://localhost:3000/jasmine`
294
+ to verify it works. If everything is fine, you can continue with adding Guard::Jasmine to your `Guardfile`
295
+ and have your non-Rails app comfortably tested in a headless environment.
296
+
272
297
  ## Usage
273
298
 
274
299
  Please read the [Guard usage documentation](https://github.com/guard/guard#readme).
275
300
 
276
- <a name="guardfile" />
277
301
  ## Guardfile
278
302
 
279
303
  Guard::Jasmine can be adapted to all kind of projects. Please read the
@@ -287,7 +311,6 @@ guard 'jasmine' do
287
311
  end
288
312
  ```
289
313
 
290
- <a name="options" />
291
314
  ## Options
292
315
 
293
316
  There are many options that can customize Guard::Jasmine to your needs. Options are simply supplied as hash when
@@ -299,7 +322,6 @@ guard 'jasmine', :all_on_start => false, :specdoc => :always do
299
322
  end
300
323
  ```
301
324
 
302
- <a name="server-options" />
303
325
  ### Server options
304
326
 
305
327
  The server options configures the server environment that is needed to run Guard::Jasmine:
@@ -337,7 +359,6 @@ The reason why the Server environment is set to `development` by default is that
337
359
  the asset pipeline doesn't concatenate the JavaScripts and you'll see the line number in the real file,
338
360
  instead of a ridiculous high line number in a single, very large JavaScript.
339
361
 
340
- <a name="server-options-custom" />
341
362
  #### Use a custom server
342
363
 
343
364
  If you supply an unknown server name as the `:server` option, then Guard::Jasmine will execute
@@ -346,7 +367,6 @@ a `rake` task with the given server name as task in a child process. For example
346
367
  you have to make sure the server starts on the port that you can get from the `JASMINE_PORT`
347
368
  environment variable.
348
369
 
349
- <a name="spec-runner-options" />
350
370
  ### Spec runner options
351
371
 
352
372
  The spec runner options configures the behavior driven development (or BDD) cycle:
@@ -377,7 +397,6 @@ In general you want to leave the `:clean` flag on, which ensures that only Jasmi
377
397
  `_spec.coffee` and `_spec.js.coffee` inside your project are passed to the runner. If you have a custom project
378
398
  structure or spec naming convention, you can set `:clean` to false to skip that file filter.
379
399
 
380
- <a name="specdoc-options" />
381
400
  ### Specdoc options
382
401
 
383
402
  Guard::Jasmine can generate an RSpec like specdoc in the console after running the specs and you can set when it will
@@ -411,7 +430,6 @@ The `:errors` option is partially working when using at least PhantomJS version
411
430
  [Issue #166](http://code.google.com/p/phantomjs/issues/detail?id=166) for the actual status of retreiving the JavaScript
412
431
  stack trace.
413
432
 
414
- <a name="console-logs" />
415
433
  #### Console logs
416
434
 
417
435
  The `:console` options adds captured console logs from the spec runner and adds them to the specdoc. Guard:Jasmine
@@ -439,7 +457,6 @@ You can further customize the log output by implement one of these methods:
439
457
  In addition, the console can log jQuery collections and outputs the HTML representation of the element by using the
440
458
  jQuery `html()` method.
441
459
 
442
- <a name="system-notifications-options" />
443
460
  ### System notifications options
444
461
 
445
462
  These options affects what system notifications (growl, libnotify or notifu) are shown after a spec run:
@@ -455,7 +472,6 @@ These options affects what system notifications (growl, libnotify or notifu) are
455
472
  # default: 3
456
473
  ```
457
474
 
458
- <a name="file-mapping" />
459
475
  ## Mapping file changes to the spec filter
460
476
 
461
477
  Jasmine doesn't know anything about your test files, it only knows the name of your specs that you specify in the
@@ -470,10 +486,8 @@ So if you want to have a precise spec detection, you should:
470
486
  To get a feeling how your naming strategy works, play with the web based Jasmine runner and modify the `spec` query
471
487
  parameter.
472
488
 
473
- <a name="outside-guard" />
474
489
  ## Guard::Jasmine outside of Guard
475
490
 
476
- <a name="thor" />
477
491
  ### Thor command line utility
478
492
 
479
493
  Guard::Jasmine includes a little command line utility to run your specs once and output the specdoc to the console.
@@ -521,7 +535,6 @@ By default all specs are run, but you can supply multiple paths to your specs to
521
535
  $ guard-jasmine spec/javascripts/a_spec.js.coffee spec/javascripts/another_spec.js.coffee
522
536
  ```
523
537
 
524
- <a name="rake" />
525
538
  ### Rake task integration
526
539
 
527
540
  Guard::Jasmine provides a Rake task wrapper around the Thor command line utility. Simply create a JasmineTask within
@@ -559,7 +572,6 @@ the task:
559
572
  $ rake guard:jasmine
560
573
  ```
561
574
 
562
- <a name="travis-ci" />
563
575
  ### Travis CI integration
564
576
 
565
577
  With the given `guard-jasmine` script you're able to configure [Travis CI](http://travis-ci.org/) to run Guard::Jasmine.
@@ -584,6 +596,25 @@ before_script:
584
596
  - "sh -e /etc/init.d/xvfb start"
585
597
  ```
586
598
 
599
+ ## How to test a Rails engine with Jasmine Gem
600
+
601
+ When building an engine, your code lives at the root but the dummy Rails app is in another folder (like `test/dummy` or `spec/dummy`).
602
+
603
+ So you have to import the Jasmine task in your `Rakefile`:
604
+
605
+ ```bash
606
+ $ echo "import 'lib/tasks/jasmine.rake'" > Rakefile
607
+ $ bundle exec rake -T jasmine
608
+ rake jasmine # Run specs via server
609
+ rake jasmine:ci # Run continuous integration tests
610
+ ```
611
+
612
+ Given your configuration, you could also need to set:
613
+
614
+ * `jasmine_url` in your `Guardfile` as explained above
615
+
616
+ * the server url in the command line: `bundle exec guard-jasmine -u http://localhost:8888/`
617
+
587
618
  ## Alternatives
588
619
 
589
620
  There are many ways to get your Jasmine specs run within a headless environment. If Guard::Jasmine isn't for you,
@@ -601,7 +632,6 @@ I recommend to check out these other brilliant Jasmine runners:
601
632
  * [Jezebel][] a Node.js REPL and continuous test runner for [Jessie][], a Node runner for Jasmine, but has no full
602
633
  featured browser environment.
603
634
 
604
- <a name="issues" />
605
635
  ## How to file an issue
606
636
 
607
637
  You can report issues and feature requests to [GitHub Issues](https://github.com/netzpirat/guard-jasmine/issues). Try to figure out
@@ -617,7 +647,6 @@ When you file an issue, please try to follow to these simple rules if applicable
617
647
  * Add your `Guardfile` and `Gemfile` to the issue.
618
648
  * Make sure that the issue is reproducible with your description.
619
649
 
620
- <a name="development-information" />
621
650
  ## Development information
622
651
 
623
652
  - Documentation hosted at [RubyDoc](http://rubydoc.info/github/guard/guard-jasmine/master/frames).
@@ -726,3 +755,4 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
726
755
  [Sinon.JS]: http://sinonjs.org
727
756
  [guard-jasmine-node]: https://github.com/guard/guard-jasmine-node
728
757
  [guard-jessie]: https://github.com/guard/guard-jessie
758
+ [Rails asset pipeline]: http://guides.rubyonrails.org/asset_pipeline.html
@@ -218,11 +218,11 @@ module Guard
218
218
  passed = failures == 0
219
219
 
220
220
  if passed
221
- report_specdoc(result, passed, options) if options[:specdoc] == :always
221
+ report_specdoc(result, passed, options)
222
222
  Formatter.success(message)
223
223
  Formatter.notify(full_message, :title => 'Jasmine suite passed') if options[:notification] && !options[:hide_success]
224
224
  else
225
- report_specdoc(result, passed, options) if options[:specdoc] != :never
225
+ report_specdoc(result, passed, options)
226
226
  Formatter.error(message)
227
227
  notify_errors(result, options)
228
228
  Formatter.notify(full_message, :title => 'Jasmine suite failed', :image => :failed, :priority => 2) if options[:notification]
@@ -254,18 +254,22 @@ module Guard
254
254
  # @param [Number] level the indention level
255
255
  #
256
256
  def report_specdoc_suite(suite, passed, options, level = 0)
257
- Formatter.suite_name((' ' * level) + suite['description']) if passed || options[:focus] && contains_failed_spec?(suite)
257
+ # Print the suite description when the specdoc is shown or there are logs to display
258
+ if (specdoc_shown?(passed, options) || console_logs_shown?(suite, passed, options) || error_logs_shown?(suite, passed, options))
259
+ Formatter.suite_name((' ' * level) + suite['description']) if passed || options[:focus] && contains_failed_spec?(suite)
260
+ end
258
261
 
259
262
  suite['specs'].each do |spec|
260
263
  if spec['passed']
261
- if passed || !options[:focus]
262
- Formatter.success(indent(" ✔ #{ spec['description'] }", level))
264
+ if passed || !options[:focus] || console_for_spec?(spec, options) || errors_for_spec?(spec, options)
265
+ Formatter.success(indent(" ✔ #{ spec['description'] }", level)) if description_shown?(passed, spec, options)
266
+ report_specdoc_errors(spec, options, level)
263
267
  report_specdoc_logs(spec, options, level)
264
268
  end
265
269
  else
266
- Formatter.spec_failed(indent(" ✘ #{ spec['description'] }", level))
270
+ Formatter.spec_failed(indent(" ✘ #{ spec['description'] }", level)) if description_shown?(passed, spec, options)
267
271
  spec['messages'].each do |message|
268
- Formatter.spec_failed(indent(" ➤ #{ format_message(message, false) }", level))
272
+ Formatter.spec_failed(indent(" ➤ #{ format_message(message, false) }", level)) if specdoc_shown?(passed, options)
269
273
  end
270
274
  report_specdoc_errors(spec, options, level)
271
275
  report_specdoc_logs(spec, options, level)
@@ -275,6 +279,53 @@ module Guard
275
279
  suite['suites'].each { |suite| report_specdoc_suite(suite, passed, options, level + 2) } if suite['suites']
276
280
  end
277
281
 
282
+ # Is the specdoc shown for this suite?
283
+ def specdoc_shown?(passed, options = {})
284
+ (options[:specdoc] == :always || (options[:specdoc] == :failure && !passed))
285
+ end
286
+
287
+ # Are console logs shown for this suite?
288
+ def console_logs_shown?(suite, passed, options = {})
289
+ # Are console messages displayed?
290
+ console_enabled = (options[:console] == :always || (options[:console] == :failure && !passed))
291
+ # Are there any logs to display at all for this suite?
292
+ logs_for_current_options = suite['specs'].select do |spec|
293
+ spec['logs'] && (options[:console] == :always || (options[:console] == :failure && !spec['passed']))
294
+ end
295
+ any_logs_present = (!logs_for_current_options.empty?)
296
+ (console_enabled && any_logs_present)
297
+ end
298
+
299
+ # Are console logs shown for this spec?
300
+ def console_for_spec?(spec, options = {})
301
+ console = (spec['logs'] && ((spec['passed'] && options[:console] == :always) ||
302
+ (!spec['passed'] && options[:console] != :never)))
303
+ end
304
+
305
+ # Are error logs shown for this suite?
306
+ def error_logs_shown?(suite, passed, options = {})
307
+ # Are error messages displayed?
308
+ errors_enabled = (options[:errors] == :always || (options[:errors] == :failure && !passed))
309
+ # Are there any errors to display at all for this suite?
310
+ errors_for_current_options = suite['specs'].select do |spec|
311
+ spec['errors'] && (options[:errors] == :always || (options[:errors] == :failure && !spec['passed']))
312
+ end
313
+ any_errors_present = (!errors_for_current_options.empty?)
314
+ (errors_enabled && any_errors_present)
315
+ end
316
+
317
+ # Are errors shown for this spec?
318
+ def errors_for_spec?(spec, options = {})
319
+ errors = (spec['errors'] && ((spec['passed'] && options[:errors] == :always) ||
320
+ (!spec['passed'] && options[:errors] != :never)))
321
+ end
322
+
323
+ # Is the description shown for this spec?
324
+ def description_shown?(passed, spec, options = {})
325
+ (specdoc_shown?(passed, options) || console_for_spec?(spec, options) || errors_for_spec?(spec, options))
326
+ end
327
+
328
+
278
329
  # Shows the logs for a given spec.
279
330
  #
280
331
  # @param [Hash] spec the spec result
@@ -1,6 +1,6 @@
1
1
  module Guard
2
2
  module JasmineVersion
3
3
  # Guard::Jasmine version that is used for the Gem specification
4
- VERSION = '1.1.4'
4
+ VERSION = '1.2.0'
5
5
  end
6
6
  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.1.4
4
+ version: 1.2.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-05-18 00:00:00.000000000 Z
12
+ date: 2012-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard
@@ -266,7 +266,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
266
266
  version: '0'
267
267
  segments:
268
268
  - 0
269
- hash: 979009543372736949
269
+ hash: -454211367523524578
270
270
  required_rubygems_version: !ruby/object:Gem::Requirement
271
271
  none: false
272
272
  requirements: