Class: Guard::Jasmine

Inherits:
Plugin
  • Object
show all
Extended by:
Util
Defined in:
lib/guard/jasmine.rb,
lib/guard/jasmine/cli.rb,
lib/guard/jasmine/util.rb,
lib/guard/jasmine/server.rb,
lib/guard/jasmine/runner.rb,
lib/guard/jasmine/formatter.rb,
lib/guard/jasmine/inspector.rb

Overview

The Jasmine guard that gets notifications about the following Guard events: start, stop, reload, run_all and run_on_modifications.

Defined Under Namespace

Modules: Formatter, Inspector, Runner, Server, Util Classes: CLI

Constant Summary

DEFAULT_OPTIONS =
{
  server:                   :auto,
  server_env:               ENV['RAILS_ENV'] || 'development',
  server_timeout:           60,
  server_mount:             '/jasmine',  # set here for documentation purposes; actually determiend at runtime by presence (or lack thereof) of the JasmineRails constant
  port:                     nil,
  rackup_config:            nil,
  jasmine_url:              nil,
  timeout:                  60,
  spec_dir:                 nil,
  notification:             true,
  hide_success:             false,
  all_on_start:             true,
  keep_failed:              true,
  clean:                    true,
  all_after_pass:           true,
  max_error_notify:         3,
  specdoc:                  :failure,
  console:                  :failure,
  errors:                   :failure,
  focus:                    true,
  coverage:                 false,
  coverage_html:            false,
  coverage_html_dir:        "./coverage",
  coverage_summary:         false,
  statements_threshold:     0,
  functions_threshold:      0,
  branches_threshold:       0,
  lines_threshold:          0,
  junit:                    false,
  junit_consolidate:        true,
  junit_save_path:          ''
}

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Util

find_free_server_port, phantomjs_bin_valid?, runner_available?, which

Constructor Details

- (Jasmine) initialize(options = { })

Initialize Guard::Jasmine.

Options Hash (options):

  • :server (String)

    the server to use, either :auto, :none, :webrick, :mongrel, :thin, :jasmine_gem, or a custom rake task

  • :server_env (String)

    the server environment to use, for example :development, :test

  • :server_timeout (Integer)

    the number of seconds to wait for the Jasmine spec server

  • :port (String)

    the port for the Jasmine test server

  • :rackup_config (String)

    custom rackup config to use

  • :server_mount (String)

    custom mount point to use; defaults to '/specs' if JasmineRails is on the load path, otherwise '/jasmine'

  • :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

  • :spec_dir (String)

    the directory with the Jasmine specs

  • :notification (Boolean)

    show notifications

  • :hide_success (Boolean)

    hide success message notification

  • :max_error_notify (Integer)

    maximum error notifications to show

  • :all_on_start (Boolean)

    run all suites on start

  • :keep_failed (Boolean)

    keep failed suites and add them to the next run again

  • :clean (Boolean)

    clean the specs according to rails naming conventions

  • :all_after_pass (Boolean)

    run all suites after a suite has passed again after failing

  • :specdoc (Symbol)

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

  • :console (Symbol)

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

  • :errors (Symbol)

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

  • :focus (Symbol)

    options for focus on failures in the specdoc

  • :coverage (Symbol)

    options for enable coverage support

  • :coverage_html (Symbol)

    options for enable coverage html support

  • :coverage_summary (Symbol)

    options for enable coverage summary support

  • :statements_threshold (Symbol)

    options for the statement coverage threshold

  • :functions_threshold (Symbol)

    options for the statement function threshold

  • :branches_threshold (Symbol)

    options for the statement branch threshold

  • :lines_threshold (Symbol)

    options for the statement lines threshold

  • :run_all (Hash)

    options overwrite options when run all specs



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/guard/jasmine.rb', line 90

def initialize(options = { })
  options[:server_mount] ||= defined?(JasmineRails) ? '/specs' : '/jasmine'

  options = DEFAULT_OPTIONS.merge(options)

  options[:spec_dir]    ||= File.exists?(File.join('spec', 'javascripts')) ? File.join('spec', 'javascripts') : 'spec'
  options[:port]        ||= Jasmine.find_free_server_port
  options[:server]      ||= :auto
  options[:server]        = ::Guard::Jasmine::Server.detect_server(options[:spec_dir]) if options[:server] == :auto
  options[:jasmine_url]   = "http://localhost:#{ options[:port] }#{ options[:server] == :jasmine_gem ? '/' : options[:server_mount] }" unless options[:jasmine_url]
  options[:specdoc]       = :failure if ![:always, :never, :failure].include? options[:specdoc]
  options[:phantomjs_bin] = Jasmine.which('phantomjs') unless options[:phantomjs_bin]

  self.run_all_options = options.delete(:run_all) || { }

  super(options)

  self.last_run_failed   = false
  self.last_failed_paths = []
end

Instance Attribute Details

- (Object) last_failed_paths

Returns the value of attribute last_failed_paths



21
22
23
# File 'lib/guard/jasmine.rb', line 21

def last_failed_paths
  @last_failed_paths
end

- (Object) last_run_failed

Returns the value of attribute last_run_failed



21
22
23
# File 'lib/guard/jasmine.rb', line 21

def last_run_failed
  @last_run_failed
end

- (Object) run_all_options

Returns the value of attribute run_all_options



21
22
23
# File 'lib/guard/jasmine.rb', line 21

def run_all_options
  @run_all_options
end

Instance Method Details

- (Object) reload

Gets called when the Guard should reload itself.

Raises:

  • (:task_has_failed)

    when reload has failed



140
141
142
143
# File 'lib/guard/jasmine.rb', line 140

def reload
  self.last_run_failed   = false
  self.last_failed_paths = []
end

- (Object) run_all

Gets called when all specs should be run.

Raises:

  • (:task_has_failed)

    when run_all has failed



149
150
151
152
153
154
155
156
# File 'lib/guard/jasmine.rb', line 149

def run_all
  passed, failed_specs = Runner.run([options[:spec_dir]], options.merge(self.run_all_options))

  self.last_failed_paths = failed_specs
  self.last_run_failed   = !passed

  throw :task_has_failed unless passed
end

- (Object) run_on_modifications(paths)

Gets called when watched paths and files have changes.

Raises:

  • (:task_has_failed)

    when run_on_modifications has failed



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/guard/jasmine.rb', line 163

def run_on_modifications(paths)
  specs = options[:keep_failed] ? paths + self.last_failed_paths : paths
  specs = Inspector.clean(specs, options) if options[:clean]
  return false if specs.empty?

  passed, failed_specs = Runner.run(specs, options)

  if passed
    self.last_failed_paths = self.last_failed_paths - paths
    run_all if self.last_run_failed && options[:all_after_pass]
  else
    self.last_failed_paths = self.last_failed_paths + failed_specs
  end

  self.last_run_failed = !passed

  throw :task_has_failed unless passed
end

- (Object) start

Gets called once when Guard starts.

Raises:

  • (:task_has_failed)

    when start has failed



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/guard/jasmine.rb', line 115

def start
  if Jasmine.phantomjs_bin_valid?(options[:phantomjs_bin])

    Server.start(options) unless options[:server] == :none

    if Jasmine.runner_available?(options)
      run_all if options[:all_on_start]
    end
  else
    throw :task_has_failed
  end
end

- (Object) stop

Gets called once when Guard stops.

Raises:

  • (:task_has_failed)

    when stop has failed



132
133
134
# File 'lib/guard/jasmine.rb', line 132

def stop
  Server.stop unless options[:server] == :none
end