Class: Guard::Jasmine::Runner

Inherits:
Object
  • Object
show all
Includes:
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 collapse

THRESHOLDS =

Name of the coverage threshold options

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#find_free_server_port, #phantomjs_bin_valid?, #runner_available?, #which

Constructor Details

#initialize(options) ⇒ Runner

Run the supplied specs.

Parameters:

  • 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

  • :query_params (Hash)

    Parameters to pass along with the request

  • :debug (Boolean)

    display raw JSON output from the runner



40
41
42
# File 'lib/guard/jasmine/runner.rb', line 40

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



19
20
21
# File 'lib/guard/jasmine/runner.rb', line 19

def options
  @options
end

Instance Method Details

#run(paths, per_run_options = {}) ⇒ Hash<String,Array>

Returns keys for the spec_file, value is array of failure messages. Only specs with failures will be returned. Therefore an empty? return hash indicates success.

Parameters:

  • the spec files or directories

Returns:

  • keys for the spec_file, value is array of failure messages. Only specs with failures will be returned. Therefore an empty? return hash indicates success.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/guard/jasmine/runner.rb', line 47

def run(paths, per_run_options = {})
  previous_options = @options
  @options.merge!(per_run_options)

  return {} if paths.empty?

  notify_start_message(paths)

  run_results = paths.each_with_object({}) do |file, results|
    if File.exist?(file_and_line_number_parts(file)[0])
      results[file] = evaluate_response(run_jasmine_spec(file), file)
    end
  end
  # return the errors
  return run_results.each_with_object({}) do |spec_run, hash|
    file, r = spec_run
    errors = collect_spec_errors(r['suites'] || [])
    errors.push(r['error']) if r.key? 'error'
    hash[file] = errors unless errors.empty?
  end
ensure
  @options = previous_options
end