Module: Guard::Jasmine::Runner

Extended by:
Util
Defined in:
lib/guard/jasmine/runner.rb

Overview

The Jasmine runner handles the execution of the spec through the PhantomJS binary, evaluates the JSON response from the PhantomJS Script guard_jasmine.coffee, writes the result to the console and triggers optional system notifications.

Constant Summary

THRESHOLDS =

Name of the coverage threshold options

[:statements_threshold, :functions_threshold, :branches_threshold, :lines_threshold]

Class Method Summary (collapse)

Methods included from Util

find_free_server_port, phantomjs_bin_valid?, runner_available?, which

Class Method Details

+ (Boolean) any_coverage_threshold?(options) (private)

Do we should check the coverage?

Returns:

  • (Boolean)

    true if any coverage threshold is set



599
600
601
# File 'lib/guard/jasmine/runner.rb', line 599

def any_coverage_threshold?(options)
  THRESHOLDS.any? { |threshold| options[threshold] != 0 }
end

+ (Object) check_coverage(options) (private)

Uses the Istanbul text reported to output the result of the last coverage run.

Parameters:

  • options (Hash)

    the options for the coverage



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/guard/jasmine/runner.rb', line 302

def check_coverage(options)
  if any_coverage_threshold?(options)
    coverage = `#{ which('istanbul') } check-coverage #{ istanbul_coverage_options(options) } #{ coverage_file } 2>&1`
    coverage = coverage.split("\n").grep(/ERROR/).join.sub('ERROR:', '')
    failed   = $? && $?.exitstatus != 0

    if failed
      Formatter.error coverage
      Formatter.notify(coverage, :title => 'Code coverage failed', :image => :failed, :priority => 2) if options[:notification]
    else
      Formatter.success 'Code coverage succeed'
      Formatter.notify('All code is adequately covered with specs', :title => 'Code coverage succeed') if options[:notification] && !options[:hide_success]
    end
  end
end

+ (Array<Hash>) collect_specs(suites) (private)

Get all specs from the suites and its nested suites.

Parameters:

  • suites (Array<Hash>)

    the suites results

Returns:

  • (Array<Hash>)

    all specs



547
548
549
550
551
552
553
# File 'lib/guard/jasmine/runner.rb', line 547

def collect_specs(suites)
  suites.inject([]) do |specs, suite|
    specs = (specs | suite['specs']) if suite['specs']
    specs = (specs | collect_specs(suite['suites'])) if suite['suites']
    specs
  end
end

+ (Boolean) console_for_spec?(spec, options = { }) (private)

Are console logs shown for this spec?

Parameters:

  • spec (Hash)

    the spec

  • options (Hash) (defaults to: { })

    the options

Returns:

  • (Boolean)


423
424
425
426
# File 'lib/guard/jasmine/runner.rb', line 423

def console_for_spec?(spec, options = { })
  spec['logs'] && ((spec['passed'] && options[:console] == :always) ||
    (!spec['passed'] && options[:console] != :never))
end

+ (Boolean) console_logs_shown?(suite, passed, options = { }) (private)

Are console logs shown for this suite?

Parameters:

  • suite (Hash)

    the suite

  • passed (Boolean)

    the spec status

  • options (Hash) (defaults to: { })

    the options

Returns:

  • (Boolean)


404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/guard/jasmine/runner.rb', line 404

def console_logs_shown?(suite, passed, options = { })
  # Are console messages displayed?
  console_enabled          = options[:console] == :always || (options[:console] == :failure && !passed)

  # Are there any logs to display at all for this suite?
  logs_for_current_options = suite['specs'].select do |spec|
    spec['logs'] && (options[:console] == :always || (options[:console] == :failure && !spec['passed']))
  end

  any_logs_present = !logs_for_current_options.empty?

  console_enabled && any_logs_present
end

+ (Boolean) contains_failed_spec?(suite) (private)

Tests if the given suite has a failing spec underneath.

Parameters:

  • suite (Hash)

    the suite result

Returns:

  • (Boolean)

    the search result



538
539
540
# File 'lib/guard/jasmine/runner.rb', line 538

def contains_failed_spec?(suite)
  collect_specs([suite]).any? { |spec| !spec['passed'] }
end

+ (String) coverage_file (private)

Get the coverage file to save all coverage data. Creates tmp/coverage if not exists.

Returns:

  • (String)

    the filename to use



620
621
622
# File 'lib/guard/jasmine/runner.rb', line 620

def coverage_file
  File.join(coverage_root, 'coverage.json')
end

+ (String) coverage_root (private)

Create and returns the coverage root directory.

Returns:

  • (String)

    the coverage root



628
629
630
# File 'lib/guard/jasmine/runner.rb', line 628

def coverage_root
  File.expand_path(File.join('tmp', 'coverage'))
end

+ (Boolean) description_shown?(passed, spec, options = { }) (private)

Is the description shown for this spec?

Parameters:

  • passed (Boolean)

    the spec status

  • spec (Hash)

    the spec

  • options (Hash) (defaults to: { })

    the options

Returns:

  • (Boolean)


463
464
465
# File 'lib/guard/jasmine/runner.rb', line 463

def description_shown?(passed, spec, options = { })
  specdoc_shown?(passed, options) || console_for_spec?(spec, options) || errors_for_spec?(spec, options)
end

+ (Boolean) error_logs_shown?(suite, passed, options = { }) (private)

Are error logs shown for this suite?

Parameters:

  • suite (Hash)

    the suite

  • passed (Boolean)

    the spec status

  • options (Hash) (defaults to: { })

    the options

Returns:

  • (Boolean)


434
435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/guard/jasmine/runner.rb', line 434

def error_logs_shown?(suite, passed, options = { })
  # Are error messages displayed?
  errors_enabled             = options[:errors] == :always || (options[:errors] == :failure && !passed)

  # Are there any errors to display at all for this suite?
  errors_for_current_options = suite['specs'].select do |spec|
    spec['errors'] && (options[:errors] == :always || (options[:errors] == :failure && !spec['passed']))
  end

  any_errors_present= !errors_for_current_options.empty?

  errors_enabled && any_errors_present
end

+ (Boolean) errors_for_spec?(spec, options = { }) (private)

Are errors shown for this spec?

Parameters:

  • spec (Hash)

    the spec

  • options (Hash) (defaults to: { })

    the options

Returns:

  • (Boolean)


452
453
454
455
# File 'lib/guard/jasmine/runner.rb', line 452

def errors_for_spec?(spec, options = { })
  spec['errors'] && ((spec['passed'] && options[:errors] == :always) ||
    (!spec['passed'] && options[:errors] != :never))
end

+ (Hash) evaluate_response(output, file, options) (private)

Evaluates the JSON response that the PhantomJS script writes to stdout. The results triggers further notification actions.

Parameters:

  • output (String)

    the JSON output the spec run

  • file (String)

    the file name of the spec

  • options (Hash)

    the options for the execution

Returns:

  • (Hash)

    the suite result



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/guard/jasmine/runner.rb', line 165

def evaluate_response(output, file, options)
  json = output.read
  json = json.encode('UTF-8') if json.respond_to?(:encode)

  begin
    result = MultiJson.decode(json, { :max_nesting => false })

    if result['error']
      notify_runtime_error(result, options)
    else
      result['file'] = file
      notify_spec_result(result, options)
    end

    if result['coverage'] && options[:coverage]
      notify_coverage_result(result['coverage'], file, options)
    end

    result

  rescue MultiJson::DecodeError => e
    if e.data == ''
      Formatter.error('No response from the Jasmine runner!')
    else
      Formatter.error("Cannot decode JSON from PhantomJS runner: #{ e.message }")
      Formatter.error("JSON response: #{ e.data }")
    end
  ensure
    output.close
  end
end

+ (Array<String>) failed_paths_from(results) (private)

Returns the failed spec file names.

Parameters:

  • results (Array<Object>)

    the spec runner results

Returns:

  • (Array<String>)

    the list of failed spec files



75
76
77
# File 'lib/guard/jasmine/runner.rb', line 75

def failed_paths_from(results)
  results.map { |r| !r['passed'] ? r['file'] : nil }.compact
end

+ (String) format_message(message, short) (private)

Formats a message.

Parameters:

  • message (String)

    the error message

  • short (Boolean)

    show a short version of the message

Returns:

  • (String)

    the cleaned error message



561
562
563
564
565
566
567
# File 'lib/guard/jasmine/runner.rb', line 561

def format_message(message, short)
  if message =~ /(.*?) in http.+?assets\/(.*)\?body=\d+\s\((line\s\d+)/
    short ? $1 : "#{ $1 } in #{ $2 } on #{ $3 }"
  else
    message
  end
end

+ (Object) generate_html_report (private)

Uses the Istanbul text reported to output the result of the last coverage run.



321
322
323
324
# File 'lib/guard/jasmine/runner.rb', line 321

def generate_html_report
  `#{ which('istanbul') } report --root #{ coverage_root } html #{ coverage_file }`
  Formatter.info "Updated HTML report available at: #{ File.join('coverage', 'index.html') }"
end

+ (Object) generate_summary_report (private)

Uses the Istanbul text-summary reporter to output the summary of all the coverage runs combined.



329
330
331
332
333
334
335
336
337
338
339
# File 'lib/guard/jasmine/runner.rb', line 329

def generate_summary_report
  Formatter.info 'Spec coverage summary:'

  puts ''

  `#{ which('istanbul') } report --root #{ coverage_root } text-summary #{ coverage_file }`.each_line do |line|
    puts line.sub(/\n$/, '') if line =~ /\)$/
  end

  puts ''
end

+ (Object) generate_text_report(file, options) (private)

Uses the Istanbul text reported to output the result of the last coverage run.

Parameters:

  • file (String)

    the file name of the spec

  • options (Hash)

    the options for the execution



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/guard/jasmine/runner.rb', line 278

def generate_text_report(file, options)
  Formatter.info 'Spec coverage details:'

  if file == options[:spec_dir]
    matcher = /[|+]$/
  else
    impl    = file.sub('_spec', '').sub(options[:spec_dir], '')
    matcher = /(-+|All files|% Lines|#{ Regexp.escape(File.basename(impl)) }|#{ File.dirname(impl).sub(/^\//, '') }\/[^\/])/
  end

  puts ''

  `#{ which('istanbul') } report --root #{ coverage_root } text #{ coverage_file }`.each_line do |line|
    puts line.sub(/\n$/, '') if line =~ matcher
  end

  puts ''
end

+ (Object) indent(message, level) (private)

Indent a message.

Parameters:

  • message (String)

    the message

  • level (Number)

    the indention level



510
511
512
# File 'lib/guard/jasmine/runner.rb', line 510

def indent(message, level)
  (' ' * level) + message
end

+ (String) istanbul_coverage_options(options) (private)

Converts the options to Istanbul recognized options

Parameters:

  • options (Hash)

    the options for the coverage

Returns:

  • (String)

    the command line options



608
609
610
611
612
613
# File 'lib/guard/jasmine/runner.rb', line 608

def istanbul_coverage_options(options)
  THRESHOLDS.inject([]) do |coverage, name|
    threshold = options[name]
    coverage << (threshold != 0 ? "--#{ name.to_s.sub('_threshold', '') } #{ threshold }" : '')
  end.reject(&:empty?).join(' ')
end

+ (String) jasmine_suite(file, options) (private)

Get the Jasmine test runner URL with the appended suite name that acts as the spec filter.

Parameters:

  • file (String)

    the spec file

  • options (Hash)

    the options for the execution

Options Hash (options):

  • :jasmine_url (String)

    the url of the Jasmine test runner

Returns:

  • (String)

    the Jasmine url



118
119
120
# File 'lib/guard/jasmine/runner.rb', line 118

def jasmine_suite(file, options)
  options[:jasmine_url] + query_string_for_suite(file, options)
end

+ (Object) notify_coverage_result(coverage, file, options) (private)

Notification about the coverage of a spec run, success or failure, and some stats.

Parameters:

  • coverage (Hash)

    the coverage hash from the JSON

  • file (String)

    the file name of the spec

  • options (Hash)

    the options for the execution

Options Hash (options):

  • :notification (Boolean)

    show notifications

  • :hide_success (Boolean)

    hide success message notification



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/guard/jasmine/runner.rb', line 254

def notify_coverage_result(coverage, file, options)
  FileUtils.mkdir_p(coverage_root) unless File.exist?(coverage_root)

  update_coverage(coverage, file, options)

  if options[:coverage_summary]
    generate_summary_report
  else
    generate_text_report(file, options)
  end

  check_coverage(options)

  if options[:coverage_html]
    generate_html_report
  end
end

+ (Object) notify_errors(result, options) (private)

Show system notifications about the occurred errors.

Parameters:

  • result (Hash)

    the suite result

  • options (Hash)

    the options

Options Hash (options):

  • :max_error_notify (Integer)

    maximum error notifications to show

  • :notification (Boolean)

    show notifications



521
522
523
524
525
526
527
528
529
530
531
# File 'lib/guard/jasmine/runner.rb', line 521

def notify_errors(result, options)
  collect_specs(result['suites']).each_with_index do |spec, index|
    if !spec['passed'] && options[:max_error_notify] > index
      msg = spec['messages'].map { |message| format_message(message, true) }.join(', ')
      Formatter.notify("#{ spec['description'] }: #{ msg }",
                       :title    => 'Jasmine spec failed',
                       :image    => :failed,
                       :priority => 2) if options[:notification]
    end
  end
end

+ (Object) notify_runtime_error(result, options) (private)

Notification when a system error happens that prohibits the execution of the Jasmine spec.

Parameters:

  • result (Hash)

    the suite result

  • options (Hash)

    the options for the execution

Options Hash (options):

  • :notification (Boolean)

    show notifications



204
205
206
207
208
# File 'lib/guard/jasmine/runner.rb', line 204

def notify_runtime_error(result, options)
  message = "An error occurred: #{ result['error'] }"
  Formatter.error(message)
  Formatter.notify(message, :title => 'Jasmine error', :image => :failed, :priority => 2) if options[:notification]
end

+ (Object) notify_spec_result(result, options) (private)

Notification about a spec run, success or failure, and some stats.

Parameters:

  • result (Hash)

    the suite result

  • options (Hash)

    the options for the execution

Options Hash (options):

  • :notification (Boolean)

    show notifications

  • :hide_success (Boolean)

    hide success message notification



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/guard/jasmine/runner.rb', line 218

def notify_spec_result(result, options)
  specs           = result['stats']['specs']
  failures        = result['stats']['failures']
  time            = result['stats']['time']
  specs_plural    = specs == 1 ? '' : 's'
  failures_plural = failures == 1 ? '' : 's'

  Formatter.info("\nFinished in #{ time } seconds")

  message      = "#{ specs } spec#{ specs_plural }, #{ failures } failure#{ failures_plural }"
  full_message = "#{ message }\nin #{ time } seconds"
  passed       = failures == 0

  if passed
    report_specdoc(result, passed, options)
    Formatter.success(message)
    Formatter.notify(full_message, :title => 'Jasmine suite passed') if options[:notification] && !options[:hide_success]
  else
    report_specdoc(result, passed, options)
    Formatter.error(message)
    notify_errors(result, options)
    Formatter.notify(full_message, :title => 'Jasmine suite failed', :image => :failed, :priority => 2) if options[:notification]
  end

  Formatter.info("Done.\n")
end

+ (Object) notify_start_message(paths, options) (private)

Shows a notification in the console that the runner starts.

Parameters:

  • paths (Array<String>)

    the spec files or directories

  • options (Hash)

    the options for the execution

Options Hash (options):

  • :spec_dir (String)

    the directory with the Jasmine specs



60
61
62
63
64
65
66
67
68
# File 'lib/guard/jasmine/runner.rb', line 60

def notify_start_message(paths, options)
  message = if paths == [options[:spec_dir]]
              'Run all Jasmine suites'
            else
              "Run Jasmine suite#{ paths.size == 1 ? '' : 's' } #{ paths.join(' ') }"
            end

  Formatter.info(message, :reset => true)
end

+ (String) phantomjs_command(options) (private)

Get the PhantomJS binary and script to execute.

Parameters:

  • options (Hash)

    the options for the execution

Options Hash (options):

  • :phantomjs_bin (String)

    the location of the PhantomJS binary

Returns:

  • (String)

    the command



106
107
108
# File 'lib/guard/jasmine/runner.rb', line 106

def phantomjs_command(options)
  options[:phantomjs_bin] + ' ' + phantomjs_script
end

+ (String) phantomjs_script (private)

Get the PhantomJS script that executes the spec and extracts the result from the headless DOM.

Returns:

  • (String)

    the path to the PhantomJS script



127
128
129
# File 'lib/guard/jasmine/runner.rb', line 127

def phantomjs_script
  File.expand_path(File.join(File.dirname(__FILE__), 'phantomjs', 'guard-jasmine.js'))
end

+ (String) query_string_for_suite(file, options) (private)

The suite name must be extracted from the spec that will be run. This is done by parsing from the head of the spec file until the first describe function is found.

Parameters:

  • file (String)

    the spec file

  • options (Hash)

    the options for the execution

Options Hash (options):

  • :spec_dir (String)

    the directory with the Jasmine specs

Returns:

  • (String)

    the suite name



141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/guard/jasmine/runner.rb', line 141

def query_string_for_suite(file, options)
  return '' if file == options[:spec_dir]

  query_string = ''

  File.foreach(file) do |line|
    if line =~ /describe\s*[("']+(.*?)["')]+/
      query_string = "?spec=#{ $1 }"
      break
    end
  end

  URI.encode(query_string)
end

+ (Object) report_specdoc(result, passed, options) (private)

Specdoc like formatting of the result.

Parameters:

  • result (Hash)

    the suite result

  • passed (Boolean)

    status

  • options (Hash)

    the options

Options Hash (options):

  • :console (Symbol)

    options for the console.log output, either :always, :never or :failure



348
349
350
351
352
# File 'lib/guard/jasmine/runner.rb', line 348

def report_specdoc(result, passed, options)
  result['suites'].each do |suite|
    report_specdoc_suite(suite, passed, options)
  end
end

+ (Object) report_specdoc_errors(spec, options, level) (private)

Shows the errors for a given spec.

Parameters:

  • spec (Hash)

    the spec result

  • options (Hash)

    the options

  • level (Number)

    the indention level

Options Hash (options):

  • :errors (Symbol)

    options for the errors output, either :always, :never or :failure



491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/guard/jasmine/runner.rb', line 491

def report_specdoc_errors(spec, options, level)
  if spec['errors'] && (options[:errors] == :always || (options[:errors] == :failure && !spec['passed']))
    spec['errors'].each do |error|
      if error['trace']
        error['trace'].each do |trace|
          Formatter.spec_failed(indent("    ➜ Exception: #{ error['msg']  } in #{ trace['file'] } on line #{ trace['line'] }", level))
        end
      else
        Formatter.spec_failed(indent("    ➜ Exception: #{ error['msg']  }", level))
      end
    end
  end
end

+ (Object) report_specdoc_logs(spec, options, level) (private)

Shows the logs for a given spec.

Parameters:

  • spec (Hash)

    the spec result

  • options (Hash)

    the options

  • level (Number)

    the indention level

Options Hash (options):

  • :console (Symbol)

    options for the console.log output, either :always, :never or :failure



474
475
476
477
478
479
480
481
482
# File 'lib/guard/jasmine/runner.rb', line 474

def report_specdoc_logs(spec, options, level)
  if spec['logs'] && (options[:console] == :always || (options[:console] == :failure && !spec['passed']))
    spec['logs'].each do |log|
      log.split("\n").each_with_index do |message, index|
        Formatter.info(indent("    #{ index == 0 ? '' : ' ' } #{ message }", level))
      end
    end
  end
end

+ (Object) report_specdoc_suite(suite, passed, options, level = 0) (private)

Show the suite result.

Parameters:

  • suite (Hash)

    the suite

  • passed (Boolean)

    status

  • options (Hash)

    the options

  • level (Number) (defaults to: 0)

    the indention level

Options Hash (options):

  • :console (Symbol)

    options for the console.log output, either :always, :never or :failure

  • :focus (Symbol)

    options for focus on failures in the specdoc



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/guard/jasmine/runner.rb', line 363

def report_specdoc_suite(suite, passed, options, level = 0)
  # Print the suite description when the specdoc is shown or there are logs to display
  if specdoc_shown?(passed, options) || console_logs_shown?(suite, passed, options) || error_logs_shown?(suite, passed, options)
    Formatter.suite_name((' ' * level) + suite['description']) if passed || options[:focus] && contains_failed_spec?(suite)
  end

  suite['specs'].each do |spec|
    if spec['passed']
      if passed || !options[:focus] || console_for_spec?(spec, options) || errors_for_spec?(spec, options)
        Formatter.success(indent("#{ spec['description'] }", level)) if description_shown?(passed, spec, options)
        report_specdoc_errors(spec, options, level)
        report_specdoc_logs(spec, options, level)
      end
    else
      Formatter.spec_failed(indent("#{ spec['description'] }", level)) if description_shown?(passed, spec, options)
      spec['messages'].each do |message|
        Formatter.spec_failed(indent("#{ format_message(message, false) }", level)) if specdoc_shown?(passed, options)
      end
      report_specdoc_errors(spec, options, level)
      report_specdoc_logs(spec, options, level)
    end
  end

  suite['suites'].each { |s| report_specdoc_suite(s, passed, options, level + 2) } if suite['suites']
end

+ (Boolean) response_status_for(results) (private)

Returns the response status for the given result set.

Parameters:

  • results (Array<Object>)

    the spec runner results

Returns:

  • (Boolean)

    whether it has passed or not



84
85
86
# File 'lib/guard/jasmine/runner.rb', line 84

def response_status_for(results)
  results.none? { |r| r.has_key?('error') || !r['passed'] }
end

+ (Boolean, Array<String>) run(paths, options = { })

Run the supplied specs.

Parameters:

  • paths (Array<String>)

    the spec files or directories

  • options (Hash) (defaults to: { })

    the options for the execution

Options Hash (options):

  • :jasmine_url (String)

    the url of the Jasmine test runner

  • :phantomjs_bin (String)

    the location of the PhantomJS binary

  • :timeout (Integer)

    the maximum time in seconds to wait for the spec runner to finish

  • :rackup_config (String)

    custom rackup config to use

  • :notification (Boolean)

    show notifications

  • :hide_success (Boolean)

    hide success message notification

  • :max_error_notify (Integer)

    maximum error notifications to show

  • :specdoc (Symbol)

    options for the specdoc output, either :always, :never

  • :console (Symbol)

    options for the console.log output, either :always, :never or :failure

  • :spec_dir (String)

    the directory with the Jasmine specs

Returns:

  • (Boolean, Array<String>)

    the status of the run and the failed files



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/guard/jasmine/runner.rb', line 38

def run(paths, options = { })
  return [false, []] if paths.empty?

  notify_start_message(paths, options)

  results = paths.inject([]) do |results, file|
    results << evaluate_response(run_jasmine_spec(file, options), file, options) if File.exist?(file)

    results
  end.compact

  [response_status_for(results), failed_paths_from(results)]
end

+ (Object) run_jasmine_spec(file, options) (private)

Run the Jasmine spec by executing the PhantomJS script.

Parameters:

  • file (String)

    the path of the spec

  • options (Hash)

    the options for the execution

Options Hash (options):

  • :timeout (Integer)

    the maximum time in seconds to wait for the spec runner to finish



94
95
96
97
98
# File 'lib/guard/jasmine/runner.rb', line 94

def run_jasmine_spec(file, options)
  suite = jasmine_suite(file, options)
  Formatter.info("Run Jasmine suite at #{ suite }")
  IO.popen("#{ phantomjs_command(options) } \"#{ suite }\" #{ options[:timeout] * 1000 } #{ options[:specdoc] } #{ options[:focus] } #{ options[:console] } #{ options[:errors] }", 'r:UTF-8')
end

+ (Boolean) specdoc_shown?(passed, options = { }) (private)

Is the specdoc shown for this suite?

Parameters:

  • passed (Boolean)

    the spec status

  • options (Hash) (defaults to: { })

    the options

Returns:

  • (Boolean)


394
395
396
# File 'lib/guard/jasmine/runner.rb', line 394

def specdoc_shown?(passed, options = { })
  options[:specdoc] == :always || (options[:specdoc] == :failure && !passed)
end

+ (Object) update_coverage(coverage, file, options) (private)

Updates the coverage data with new data for the implementation file. It replaces the coverage data if the file is the spec dir.

Parameters:

  • coverage (Hash)

    the last run coverage data

  • file (String)

    the file name of the spec

  • options (Hash)

    the options for the execution



576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'lib/guard/jasmine/runner.rb', line 576

def update_coverage(coverage, file, options)
  if file == options[:spec_dir]
    File.write(coverage_file, MultiJson.encode(coverage, { :max_nesting => false }))
  else
    if File.exist?(coverage_file)
      impl     = file.sub('_spec', '').sub(options[:spec_dir], '')
      coverage = MultiJson.decode(File.read(coverage_file), { :max_nesting => false })

      coverage.each do |coverage_file, data|
        coverage[coverage_file] = data if coverage_file == impl
      end

      File.write(coverage_file, MultiJson.encode(coverage, { :max_nesting => false }))
    else
      File.write(coverage_file, MultiJson.encode({ }))
    end
  end
end