guard-jasmine 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -100,21 +100,26 @@ group :development, :test do
100
100
  end
101
101
  ```
102
102
 
103
- and add a route for the Jasmine Test Runner to `config/routes.rb`:
103
+ And run following from the Terminal:
104
104
 
105
- ```ruby
106
- if ["development", "test"].include? Rails.env
107
- mount Jasminerice::Engine => "/jasmine"
108
- end
105
+ ```bash
106
+ mkdir -p spec/javascripts
107
+ echo -e "#=require application\n#=require_tree ./" > spec/javascripts/spec.js.coffee
108
+ echo -e "/*\n * add css using =require application\n */" > spec/javascripts/spec.css
109
109
  ```
110
110
 
111
- Next you create the directory `spec/javascripts` where your CoffeeScript tests go into. You define the Rails 3.1
111
+ This creates the directory `spec/javascripts` where your CoffeeScript tests go into. You define the Rails 3.1
112
112
  asset pipeline manifest in `spec/javascripts/spec.js.coffee`:
113
113
 
114
114
  ```coffeescript
115
+ #=require application
115
116
  #=require_tree ./
116
117
  ```
117
118
 
119
+ It also creates an empty `spec/javascripts/spec.css` file as it is always requested when running specs.
120
+
121
+ Now you can access `/jasmine` url when you start rails server normally.
122
+
118
123
  ## Rails 2 & Rails 3 setup
119
124
 
120
125
  With Rails 2 or Rails 3 you can use [the Jasmine Gem][] to configure your Jasmine specs and server the Jasmine
@@ -207,14 +212,14 @@ end
207
212
  The general options configures the environment that is needed to run Guard::Jasmine:
208
213
 
209
214
  ```ruby
210
- :server => :jasmine # Jasmine server to use, either :auto, :rack, :jasmine_gem or :none
215
+ :server => :jasmine_gem # Jasmine server to use, either :auto, :rack, :jasmine_gem or :none
211
216
  # default: :auto
212
217
 
213
218
  :port => 9292 # Jasmine server port to use.
214
219
  # default: 8888
215
220
 
216
221
  :phantomjs_bin => '~/bin/phantomjs' # Path to phantomjs.
217
- # default: '/usr/local/bin/phantomjs'
222
+ # default: auto-detect 'phantomjs'
218
223
 
219
224
  :timeout => 20000 # The time in ms to wait for the spec runner to finish.
220
225
  # default: 10000
@@ -357,9 +362,18 @@ after_script: 'bundle exec guard-jasmine'
357
362
 
358
363
  ## Alternatives
359
364
 
365
+ There are many ways to get your Jasmine specs run within a headless environment. If Guard::Jasmine isn't for you,
366
+ I recommend to check out these other brilliant Jasmine runners:
367
+
368
+ ### Guards
369
+
360
370
  * [guard-jasmine-headless-webkit][], a Guard for [jasmine-headless-webkit][], but doesn't run on JRuby.
361
- * [Evergreen][], runs CoffeeScript specs headless, but has no
362
- continuous testing support.
371
+ * [guard-jasmine-node][] automatically & intelligently executes Jasmine Node.js specs when files are modified.
372
+ * [guard-jessie][] allows to automatically run you Jasmine specs under Node.js using Jessie runner.
373
+
374
+ ### Standalone
375
+
376
+ * [Evergreen][], runs CoffeeScript specs headless, but has no continuous testing support.
363
377
  * [Jezebel][] a Node.js REPL and continuous test runner for [Jessie][], a Node runner for Jasmine, but has no full
364
378
  featured browser environment.
365
379
 
@@ -410,6 +424,9 @@ The only argument that the script takes is the URL to the Jasmine runner, which
410
424
  ```bash
411
425
  $ guard-jasmine-debug http://127.0.0.1:3000/Jasmine?spec=YourSpec
412
426
  ```
427
+ ## Contributors
428
+
429
+ * [Dmytrii Nagirniak](https://github.com/dnagir)
413
430
 
414
431
  ## Acknowledgment
415
432
 
@@ -471,3 +488,5 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
471
488
  [PhantomJS script]: https://github.com/netzpirat/guard-jasmine/blob/master/lib/guard/jasmine/phantomjs/run-jasmine.coffee
472
489
  [Guard::CoffeeScript]: https://github.com/guard/guard-coffeescript
473
490
  [Sinon.JS]: http://sinonjs.org
491
+ [guard-jasmine-node]: https://github.com/guard/guard-jasmine-node
492
+ [guard-jessie]: https://github.com/guard/guard-jessie
@@ -22,7 +22,6 @@ module Guard
22
22
  :server => :auto,
23
23
  :port => 8888,
24
24
  :jasmine_url => 'http://localhost:8888/jasmine',
25
- :phantomjs_bin => '/usr/local/bin/phantomjs',
26
25
  :timeout => 10000,
27
26
  :notification => true,
28
27
  :hide_success => false,
@@ -55,9 +54,11 @@ module Guard
55
54
  # @option options [Symbol] :focus options for focus on failures in the specdoc
56
55
  #
57
56
  def initialize(watchers = [], options = { })
57
+ options[:jasmine_url] = "http://localhost:#{ options[:port] }/jasmine" if options[:port] && !options[:jasmine_url]
58
58
  options = DEFAULT_OPTIONS.merge(options)
59
59
  options[:specdoc] = :failure if ![:always, :never, :failure].include? options[:specdoc]
60
60
  options[:server] = :auto if ![:auto, :none, :rack, :jasmine_gem].include? options[:server]
61
+ options[:phantomjs_bin] = Jasmine.which('phantomjs') unless options[:phantomjs_bin]
61
62
 
62
63
  super(watchers, options)
63
64
 
@@ -174,14 +175,18 @@ module Guard
174
175
  # @return [Boolean] when the runner is available
175
176
  #
176
177
  def phantomjs_bin_valid?(bin)
177
- version = `#{ bin } --version`
178
-
179
- if !version
180
- notify_failure('PhantomJS binary missing', "PhantomJS binary doesn't exist at #{ bin }")
181
- elsif version.to_version < '1.3.0'.to_version
182
- notify_failure('Wrong PhantomJS version', "PhantomJS binary at #{ bin } must be at least version 1.3.0")
178
+ if bin && !bin.empty?
179
+ version = `#{ bin } --version`
180
+
181
+ if !version
182
+ notify_failure('PhantomJS executable missing', "PhantomJS executable doesn't exist at #{ bin }")
183
+ elsif version.to_version < '1.3.0'.to_version
184
+ notify_failure('Wrong PhantomJS version', "PhantomJS executable at #{ bin } must be at least version 1.3.0")
185
+ else
186
+ true
187
+ end
183
188
  else
184
- true
189
+ notify_failure('PhantomJS executable missing', "PhantomJS executable couldn't be auto detected.")
185
190
  end
186
191
  end
187
192
 
@@ -199,5 +204,27 @@ module Guard
199
204
  false
200
205
  end
201
206
 
207
+ # Cross-platform way of finding an executable in the $PATH.
208
+ # http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
209
+ #
210
+ # @example
211
+ # which('ruby') #=> /usr/bin/ruby
212
+ #
213
+ # @param cmd [String] the executable to find
214
+ # @return [String, nil] the path to the executable
215
+ #
216
+ def self.which(cmd)
217
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
218
+
219
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
220
+ exts.each do |ext|
221
+ exe = "#{ path }/#{ cmd }#{ ext }"
222
+ return exe if File.executable?(exe)
223
+ end
224
+ end
225
+
226
+ nil
227
+ end
228
+
202
229
  end
203
230
  end
@@ -70,7 +70,7 @@ module Guard
70
70
  runner[:timeout] = options.timeout
71
71
  runner[:port] = options.port
72
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
73
+ runner[:server] = [:auto, :rack, :jasmine_gem, :none].include?(options.server.to_sym) ? options.server.to_sym : :auto
74
74
 
75
75
  runner[:notification] = false
76
76
  runner[:hide_success] = true
@@ -2,8 +2,8 @@ module Guard
2
2
  class Jasmine
3
3
 
4
4
  # The inspector verifies if the changed paths are valid
5
- # for Guard::Jasmine. Please note that request to {#clean}
6
- # paths keeps the current valid files cached until {#clear} is
5
+ # for Guard::Jasmine. Please note that request to {.clean}
6
+ # paths keeps the current valid files cached until {.clear} is
7
7
  # called.
8
8
  #
9
9
  module Inspector
@@ -49,11 +49,11 @@ module Guard
49
49
  # JavaScript and CoffeeScript files in the `spec`
50
50
  # directory.
51
51
  #
52
- # @see #clear
52
+ # @see .clear
53
53
  # @return [Array<String>] the valid files
54
54
  #
55
55
  def jasmine_specs
56
- @jasmine_specs ||= Dir.glob('spec/**/*_spec.{js,js.coffee}')
56
+ @jasmine_specs ||= Dir.glob('spec/**/*_spec.{js,coffee,js.coffee}')
57
57
  end
58
58
 
59
59
  end
@@ -16,7 +16,18 @@ waitFor = (test, ready, timeout = 5000) ->
16
16
  condition = test()
17
17
  else
18
18
  if not condition
19
- console.log JSON.stringify({ error: 'Timeout requesting Jasmine test runner!' })
19
+ text = page.evaluate -> document.getElementsByTagName('body')[0]?.innerText
20
+
21
+ if text
22
+ error = """
23
+ Timeout waiting for the Jasmine test results!
24
+
25
+ #{ text }
26
+ """
27
+ console.log JSON.stringify({ error: error })
28
+ else
29
+ console.log JSON.stringify({ error: 'Timeout waiting for the Jasmine test results!' })
30
+
20
31
  phantom.exit(1)
21
32
  else
22
33
  ready()
@@ -324,10 +324,6 @@ module Guard
324
324
 
325
325
  # Formats a message.
326
326
  #
327
- # Known message styles:
328
- #
329
- # - {message} in http.*assets/{spec}?body=\d ({line})
330
- #
331
327
  # @param [String] message the error message
332
328
  # @param [Boolean] short show a short version of the message
333
329
  # @return [String] the cleaned error message
@@ -1,5 +1,5 @@
1
1
  guard 'jasmine' do
2
- watch(%r{app/assets/javascripts/(.+)\.(js\.coffee|js)}) { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
3
- watch(%r{spec/javascripts/(.+)_spec\.(js\.coffee|js)}) { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
4
- watch(%r{spec/javascripts/spec\.(js\.coffee|js)}) { "spec/javascripts" }
2
+ watch(%r{app/assets/javascripts/(.+)\.(js\.coffee|js|coffee)$}) { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
3
+ watch(%r{spec/javascripts/(.+)_spec\.(js\.coffee|js|coffee)$}) { |m| puts m.inspect; "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
4
+ watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { "spec/javascripts" }
5
5
  end
@@ -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 = '0.8.1'
4
+ VERSION = '0.8.2'
5
5
  end
6
6
  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: 61
4
+ hash: 59
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 1
10
- version: 0.8.1
9
+ - 2
10
+ version: 0.8.2
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-11-01 00:00:00 Z
18
+ date: 2011-11-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: guard