guard-jasmine 1.11.0 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2012 Michael Kessler
1
+ Copyright (c) 2011-2013 Michael Kessler
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -747,7 +747,7 @@ for it!
747
747
 
748
748
  (The MIT License)
749
749
 
750
- Copyright (c) 2011-2012 Michael Kessler
750
+ Copyright (c) 2011-2013 Michael Kessler
751
751
 
752
752
  Permission is hereby granted, free of charge, to any person obtaining
753
753
  a copy of this software and associated documentation files (the
@@ -21,25 +21,25 @@ module Guard
21
21
  attr_accessor :last_run_failed, :last_failed_paths, :run_all_options
22
22
 
23
23
  DEFAULT_OPTIONS = {
24
- :server => :auto,
25
- :server_env => ENV['RAILS_ENV'] || 'development',
26
- :server_timeout => 15,
27
- :port => nil,
28
- :rackup_config => nil,
29
- :jasmine_url => nil,
30
- :timeout => 10,
31
- :spec_dir => 'spec/javascripts',
32
- :notification => true,
33
- :hide_success => false,
34
- :all_on_start => true,
35
- :keep_failed => true,
36
- :clean => true,
37
- :all_after_pass => true,
38
- :max_error_notify => 3,
39
- :specdoc => :failure,
40
- :console => :failure,
41
- :errors => :failure,
42
- :focus => true
24
+ :server => :auto,
25
+ :server_env => ENV['RAILS_ENV'] || 'development',
26
+ :server_timeout => 15,
27
+ :port => nil,
28
+ :rackup_config => nil,
29
+ :jasmine_url => nil,
30
+ :timeout => 10,
31
+ :spec_dir => 'spec/javascripts',
32
+ :notification => true,
33
+ :hide_success => false,
34
+ :all_on_start => true,
35
+ :keep_failed => true,
36
+ :clean => true,
37
+ :all_after_pass => true,
38
+ :max_error_notify => 3,
39
+ :specdoc => :failure,
40
+ :console => :failure,
41
+ :errors => :failure,
42
+ :focus => true
43
43
  }
44
44
 
45
45
  # Initialize Guard::Jasmine.
@@ -76,7 +76,7 @@ module Guard
76
76
  options[:server] ||= :auto
77
77
  options[:phantomjs_bin] = Jasmine.which('phantomjs') unless options[:phantomjs_bin]
78
78
 
79
- self.run_all_options = options.delete(:run_all) || {}
79
+ self.run_all_options = options.delete(:run_all) || { }
80
80
 
81
81
  super(watchers, options)
82
82
 
@@ -23,74 +23,74 @@ module Guard
23
23
  desc 'spec', 'Run the Jasmine spec runner_options'
24
24
 
25
25
  method_option :server,
26
- :type => :string,
26
+ :type => :string,
27
27
  :aliases => '-s',
28
28
  :default => 'auto',
29
- :desc => 'Server to start, either `auto`, `webrick`, `mongrel`, `thin`, `unicorn`, `jasmine_gem` or `none`'
29
+ :desc => 'Server to start, either `auto`, `webrick`, `mongrel`, `thin`, `unicorn`, `jasmine_gem` or `none`'
30
30
 
31
31
  method_option :port,
32
- :type => :numeric,
32
+ :type => :numeric,
33
33
  :aliases => '-p',
34
- :desc => 'Server port to use'
34
+ :desc => 'Server port to use'
35
35
 
36
36
  method_option :server_env,
37
- :type => :string,
37
+ :type => :string,
38
38
  :aliases => '-e',
39
39
  :default => ENV['RAILS_ENV'] || 'test',
40
- :desc => 'The server environment to use, for example `development`, `test` etc.'
40
+ :desc => 'The server environment to use, for example `development`, `test` etc.'
41
41
 
42
42
  method_option :server_timeout,
43
- :type => :numeric,
43
+ :type => :numeric,
44
44
  :default => 15,
45
- :desc => 'The number of seconds to wait for the Jasmine spec server'
45
+ :desc => 'The number of seconds to wait for the Jasmine spec server'
46
46
 
47
47
  method_option :rackup_config,
48
- :type => :string,
48
+ :type => :string,
49
49
  :aliases => '-c',
50
- :desc => 'The rackup config to use (jasminerice only)'
50
+ :desc => 'The rackup config to use (jasminerice only)'
51
51
 
52
52
  method_option :bin,
53
- :type => :string,
53
+ :type => :string,
54
54
  :aliases => '-b',
55
- :desc => 'The location of the PhantomJS binary'
55
+ :desc => 'The location of the PhantomJS binary'
56
56
 
57
57
  method_option :spec_dir,
58
- :type => :string,
58
+ :type => :string,
59
59
  :aliases => '-d',
60
60
  :default => 'spec/javascripts',
61
- :desc => 'The directory with the Jasmine specs'
61
+ :desc => 'The directory with the Jasmine specs'
62
62
 
63
63
  method_option :url,
64
- :type => :string,
64
+ :type => :string,
65
65
  :aliases => '-u',
66
- :desc => 'The url of the Jasmine test runner'
66
+ :desc => 'The url of the Jasmine test runner'
67
67
 
68
68
  method_option :timeout,
69
- :type => :numeric,
69
+ :type => :numeric,
70
70
  :aliases => '-t',
71
71
  :default => 10,
72
- :desc => 'The maximum time in seconds to wait for the spec runner to finish'
72
+ :desc => 'The maximum time in seconds to wait for the spec runner to finish'
73
73
 
74
74
  method_option :console,
75
- :type => :string,
75
+ :type => :string,
76
76
  :default => 'failure',
77
- :desc => 'Whether to show console.log statements in the spec runner, either `always`, `never` or `failure`'
77
+ :desc => 'Whether to show console.log statements in the spec runner, either `always`, `never` or `failure`'
78
78
 
79
79
  method_option :errors,
80
- :type => :string,
80
+ :type => :string,
81
81
  :default => 'failure',
82
- :desc => 'Whether to show errors in the spec runner, either `always`, `never` or `failure`'
82
+ :desc => 'Whether to show errors in the spec runner, either `always`, `never` or `failure`'
83
83
 
84
84
  method_option :focus,
85
- :type => :boolean,
85
+ :type => :boolean,
86
86
  :aliases => '-f',
87
87
  :default => true,
88
88
  :desc => 'Specdoc focus to hide successful tests when at least one test fails'
89
89
 
90
90
  method_option :specdoc,
91
- :type => :string,
91
+ :type => :string,
92
92
  :default => :always,
93
- :desc => 'Whether to show successes in the spec runner, either `always`, `never` or `failure`'
93
+ :desc => 'Whether to show successes in the spec runner, either `always`, `never` or `failure`'
94
94
 
95
95
  # Run the Guard::Jasmine::Runner with options from
96
96
  # the command line.
@@ -100,19 +100,20 @@ module Guard
100
100
  def spec(*paths)
101
101
  paths = [options.spec_dir] if paths.empty?
102
102
 
103
- runner_options = {}
104
- runner_options[:port] = options.port || CLI.find_free_server_port
105
- runner_options[:jasmine_url] = options.url || "http://localhost:#{ runner_options[:port] }/jasmine"
106
- runner_options[:phantomjs_bin] = options.bin || CLI.which('phantomjs')
107
- runner_options[:timeout] = options.timeout
108
- runner_options[:server_env] = options.server_env
103
+ runner_options = { }
104
+ runner_options[:port] = options.port || CLI.find_free_server_port
105
+ runner_options[:jasmine_url] = options.url || "http://localhost:#{ runner_options[:port] }/jasmine"
106
+ runner_options[:phantomjs_bin] = options.bin || CLI.which('phantomjs')
107
+ runner_options[:timeout] = options.timeout
108
+ runner_options[:server] = options.server.to_sym
109
+ runner_options[:server_env] = options.server_env
109
110
  runner_options[:server_timeout] = options.server_timeout
110
- runner_options[:spec_dir] = options.spec_dir
111
- runner_options[:console] = [:always, :never, :failure].include?(options.console.to_sym) ? options.console.to_sym : :failure
112
- runner_options[:errors] = [:always, :never, :failure].include?(options.errors.to_sym) ? options.errors.to_sym : :failure
113
- runner_options[:specdoc] = [:always, :never, :failure].include?(options.specdoc.to_sym) ? options.specdoc.to_sym : :always
114
- runner_options[:server] = options.server.to_sym
115
- runner_options[:focus] = options.focus
111
+ runner_options[:rackup_config] = options.rackup_config
112
+ runner_options[:spec_dir] = options.spec_dir
113
+ runner_options[:console] = [:always, :never, :failure].include?(options.console.to_sym) ? options.console.to_sym : :failure
114
+ runner_options[:errors] = [:always, :never, :failure].include?(options.errors.to_sym) ? options.errors.to_sym : :failure
115
+ runner_options[:specdoc] = [:always, :never, :failure].include?(options.specdoc.to_sym) ? options.specdoc.to_sym : :always
116
+ runner_options[:focus] = options.focus
116
117
 
117
118
 
118
119
  runner_options[:notification] = false
@@ -54,7 +54,7 @@ module Guard
54
54
  # @param [Hash] options the output options
55
55
  #
56
56
  def spec_failed(message, options = { })
57
- ::Guard::UI.info(color(message, ';31'), options)
57
+ ::Guard::UI.info(color(message, ';31'), options)
58
58
  end
59
59
 
60
60
  # Print a red spec failed message to the console.
@@ -63,7 +63,7 @@ module Guard
63
63
  # @param [Hash] options the output options
64
64
  #
65
65
  def suite_name(message, options = { })
66
- ::Guard::UI.info(color(message, ';33'), options)
66
+ ::Guard::UI.info(color(message, ';33'), options)
67
67
  end
68
68
 
69
69
  # Outputs a system notification.
@@ -81,7 +81,7 @@ module Guard
81
81
 
82
82
  # Print a info message to the console.
83
83
  #
84
- # @param [String] test the text to colorize
84
+ # @param [String] text the text to colorize
85
85
  # @param [String] color_code the color code
86
86
  #
87
87
  def color(text, color_code)
@@ -34,7 +34,7 @@ module Guard
34
34
 
35
35
  # Tests if the file is valid.
36
36
  #
37
- # @param [String] file the file
37
+ # @param [String] path the file
38
38
  # @return [Boolean] when the file valid
39
39
  #
40
40
  def jasmine_spec?(path)
@@ -80,7 +80,7 @@ module Guard
80
80
 
81
81
  # Run the Jasmine spec by executing the PhantomJS script.
82
82
  #
83
- # @param [String] path the path of the spec
83
+ # @param [String] file the path of the spec
84
84
  # @param [Hash] options the options for the execution
85
85
  # @option options [Integer] :timeout the maximum time in seconds to wait for the spec runner to finish
86
86
  #
@@ -157,6 +157,7 @@ module Guard
157
157
  #
158
158
  def evaluate_response(output, file, options)
159
159
  json = output.read
160
+ json = json.encode('UTF-8') if json.respond_to?(:encode)
160
161
 
161
162
  begin
162
163
  result = MultiJson.decode(json, { :max_nesting => false })
@@ -185,7 +186,7 @@ module Guard
185
186
  # Notification when a system error happens that
186
187
  # prohibits the execution of the Jasmine spec.
187
188
  #
188
- # @param [Hash] the suite result
189
+ # @param [Hash] result the suite result
189
190
  # @param [Hash] options the options for the execution
190
191
  # @option options [Boolean] :notification show notifications
191
192
  #
@@ -207,7 +208,7 @@ module Guard
207
208
  specs = result['stats']['specs']
208
209
  failures = result['stats']['failures']
209
210
  time = result['stats']['time']
210
- specs_plural = specs == 1 ? '' : 's'
211
+ specs_plural = specs == 1 ? '' : 's'
211
212
  failures_plural = failures == 1 ? '' : 's'
212
213
 
213
214
  Formatter.info("\nFinished in #{ time } seconds")
@@ -254,7 +255,7 @@ module Guard
254
255
  #
255
256
  def report_specdoc_suite(suite, passed, options, level = 0)
256
257
  # Print the suite description when the specdoc is shown or there are logs to display
257
- if (specdoc_shown?(passed, options) || console_logs_shown?(suite, passed, options) || error_logs_shown?(suite, passed, options))
258
+ if specdoc_shown?(passed, options) || console_logs_shown?(suite, passed, options) || error_logs_shown?(suite, passed, options)
258
259
  Formatter.suite_name((' ' * level) + suite['description']) if passed || options[:focus] && contains_failed_spec?(suite)
259
260
  end
260
261
 
@@ -275,56 +276,87 @@ module Guard
275
276
  end
276
277
  end
277
278
 
278
- suite['suites'].each { |suite| report_specdoc_suite(suite, passed, options, level + 2) } if suite['suites']
279
+ suite['suites'].each { |s| report_specdoc_suite(s, passed, options, level + 2) } if suite['suites']
279
280
  end
280
281
 
281
282
  # Is the specdoc shown for this suite?
282
- def specdoc_shown?(passed, options = {})
283
- (options[:specdoc] == :always || (options[:specdoc] == :failure && !passed))
283
+ #
284
+ # @param [Boolean] passed the spec status
285
+ # @param [Hash] options the options
286
+ #
287
+ def specdoc_shown?(passed, options = { })
288
+ options[:specdoc] == :always || (options[:specdoc] == :failure && !passed)
284
289
  end
285
290
 
286
291
  # Are console logs shown for this suite?
287
- def console_logs_shown?(suite, passed, options = {})
292
+ #
293
+ # @param [Hash] suite the suite
294
+ # @param [Boolean] passed the spec status
295
+ # @param [Hash] options the options
296
+ #
297
+ def console_logs_shown?(suite, passed, options = { })
288
298
  # Are console messages displayed?
289
- console_enabled = (options[:console] == :always || (options[:console] == :failure && !passed))
299
+ console_enabled = options[:console] == :always || (options[:console] == :failure && !passed)
300
+
290
301
  # Are there any logs to display at all for this suite?
291
302
  logs_for_current_options = suite['specs'].select do |spec|
292
303
  spec['logs'] && (options[:console] == :always || (options[:console] == :failure && !spec['passed']))
293
304
  end
294
- any_logs_present = (!logs_for_current_options.empty?)
295
- (console_enabled && any_logs_present)
305
+
306
+ any_logs_present = !logs_for_current_options.empty?
307
+
308
+ console_enabled && any_logs_present
296
309
  end
297
310
 
298
311
  # Are console logs shown for this spec?
299
- def console_for_spec?(spec, options = {})
300
- console = (spec['logs'] && ((spec['passed'] && options[:console] == :always) ||
301
- (!spec['passed'] && options[:console] != :never)))
312
+ #
313
+ # @param [Hash] spec the spec
314
+ # @param [Hash] options the options
315
+ #
316
+ def console_for_spec?(spec, options = { })
317
+ spec['logs'] && ((spec['passed'] && options[:console] == :always) ||
318
+ (!spec['passed'] && options[:console] != :never))
302
319
  end
303
320
 
304
321
  # Are error logs shown for this suite?
305
- def error_logs_shown?(suite, passed, options = {})
322
+ #
323
+ # @param [Hash] suite the suite
324
+ # @param [Boolean] passed the spec status
325
+ # @param [Hash] options the options
326
+ #
327
+ def error_logs_shown?(suite, passed, options = { })
306
328
  # Are error messages displayed?
307
- errors_enabled = (options[:errors] == :always || (options[:errors] == :failure && !passed))
329
+ errors_enabled = options[:errors] == :always || (options[:errors] == :failure && !passed)
330
+
308
331
  # Are there any errors to display at all for this suite?
309
332
  errors_for_current_options = suite['specs'].select do |spec|
310
333
  spec['errors'] && (options[:errors] == :always || (options[:errors] == :failure && !spec['passed']))
311
334
  end
312
- any_errors_present = (!errors_for_current_options.empty?)
313
- (errors_enabled && any_errors_present)
335
+
336
+ any_errors_present= !errors_for_current_options.empty?
337
+
338
+ errors_enabled && any_errors_present
314
339
  end
315
340
 
316
341
  # Are errors shown for this spec?
317
- def errors_for_spec?(spec, options = {})
318
- errors = (spec['errors'] && ((spec['passed'] && options[:errors] == :always) ||
319
- (!spec['passed'] && options[:errors] != :never)))
342
+ #
343
+ # @param [Hash] spec the spec
344
+ # @param [Hash] options the options
345
+ def errors_for_spec?(spec, options = { })
346
+ spec['errors'] && ((spec['passed'] && options[:errors] == :always) ||
347
+ (!spec['passed'] && options[:errors] != :never))
320
348
  end
321
349
 
322
350
  # Is the description shown for this spec?
323
- def description_shown?(passed, spec, options = {})
324
- (specdoc_shown?(passed, options) || console_for_spec?(spec, options) || errors_for_spec?(spec, options))
351
+ #
352
+ # @param [Boolean] passed the spec status
353
+ # @param [Hash] spec the spec
354
+ # @param [Hash] options the options
355
+ #
356
+ def description_shown?(passed, spec, options = { })
357
+ specdoc_shown?(passed, options) || console_for_spec?(spec, options) || errors_for_spec?(spec, options)
325
358
  end
326
359
 
327
-
328
360
  # Shows the logs for a given spec.
329
361
  #
330
362
  # @param [Hash] spec the spec result
@@ -403,7 +435,7 @@ module Guard
403
435
  # Get all specs from the suites and its nested suites.
404
436
  #
405
437
  # @param suites [Array<Hash>] the suites results
406
- # @param [Array<Hash>] all specs
438
+ # @return [Array<Hash>] all specs
407
439
  #
408
440
  def collect_specs(suites)
409
441
  suites.inject([]) do |specs, suite|
@@ -21,7 +21,7 @@ module Guard
21
21
  # @option options [String] server the server to use
22
22
  # @option options [Number] port the server port
23
23
  # @option options [String] server_env the Rails environment
24
- # @option options [Number] server_timeoout the server start timeout
24
+ # @option options [Number] server_timeout the server start timeout
25
25
  # @option options [String] spec_dir the spec directory
26
26
  # @option options [String] rackup_config custom rackup config to use (i.e. spec/dummy/config.ru for mountable engines)
27
27
  #
@@ -32,14 +32,14 @@ module Guard
32
32
  timeout = options[:server_timeout]
33
33
 
34
34
  case server
35
- when :webrick, :mongrel, :thin, :puma
36
- start_rack_server(server, port, options)
37
- when :unicorn
38
- start_unicorn_server(port, options)
39
- when :jasmine_gem
40
- start_rake_server(port, 'jasmine')
41
- else
42
- start_rake_server(port, server.to_s) unless server == :none
35
+ when :webrick, :mongrel, :thin, :puma
36
+ start_rack_server(server, port, options)
37
+ when :unicorn
38
+ start_unicorn_server(port, options)
39
+ when :jasmine_gem
40
+ start_rake_server(port, 'jasmine')
41
+ else
42
+ start_rake_server(port, server.to_s) unless server == :none
43
43
  end
44
44
 
45
45
  wait_for_server(port, timeout) unless server == :none
@@ -90,7 +90,7 @@ module Guard
90
90
  # @option options [Number] port the server port
91
91
  #
92
92
  def start_unicorn_server(port, options)
93
- environment = options[:server_env]
93
+ environment = options[:server_env]
94
94
 
95
95
  ::Guard::UI.info "Guard::Jasmine starts Unicorn test server on port #{ port } in #{ environment } environment."
96
96
 
@@ -25,7 +25,7 @@ module Guard
25
25
  # @yield [JasmineTask] the task
26
26
  #
27
27
  def initialize(name = :jasmine, options = '')
28
- @name = name
28
+ @name = name
29
29
  @options = options
30
30
 
31
31
  yield self if block_given?
@@ -26,11 +26,12 @@ module Guard
26
26
 
27
27
  Timeout::timeout(options[:server_timeout]) do
28
28
  Net::HTTP.start(url.host, url.port) do |http|
29
- response = http.request(Net::HTTP::Head.new(url.path))
29
+ response = http.request(Net::HTTP::Get.new(url.path))
30
30
  available = response.code.to_i == 200
31
31
 
32
32
  unless available
33
33
  ::Guard::Jasmine::Formatter.error "Jasmine test runner fails with response code #{ response.code }"
34
+ ::Guard::Jasmine::Formatter.error(response.body) if response.body
34
35
  end
35
36
 
36
37
  available
@@ -38,7 +39,7 @@ module Guard
38
39
  end
39
40
 
40
41
  rescue Timeout::Error => e
41
- ::Guard::Jasmine::Formatter.error "Timeout waiting for the Jasmine test runner."
42
+ ::Guard::Jasmine::Formatter.error 'Timeout waiting for the Jasmine test runner.'
42
43
  false
43
44
 
44
45
  rescue => e
@@ -74,7 +75,7 @@ module Guard
74
75
  ::Guard::Jasmine::Formatter.error "PhantomJS executable doesn't exist at #{ bin }"
75
76
  end
76
77
  else
77
- ::Guard::Jasmine::Formatter.error "PhantomJS executable couldn't be auto detected."
78
+ ::Guard::Jasmine::Formatter.error 'PhantomJS executable couldn\'t be auto detected.'
78
79
  end
79
80
  end
80
81
 
@@ -84,7 +85,7 @@ module Guard
84
85
  #
85
86
  def find_free_server_port
86
87
  server = TCPServer.new('127.0.0.1', 0)
87
- port = server.addr[1]
88
+ port = server.addr[1]
88
89
  server.close
89
90
 
90
91
  port
@@ -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.11.0'
4
+ VERSION = '1.11.1'
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.11.0
4
+ version: 1.11.1
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-17 00:00:00.000000000 Z
12
+ date: 2013-01-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  version: 1.3.6
146
146
  requirements: []
147
147
  rubyforge_project: guard-jasmine
148
- rubygems_version: 1.8.24
148
+ rubygems_version: 1.8.23
149
149
  signing_key:
150
150
  specification_version: 3
151
151
  summary: Guard gem for headless testing with Jasmine