Class: Guard::Jasmine
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::Jasmine
- Extended by:
- Util
- Defined in:
- lib/guard/jasmine.rb,
lib/guard/jasmine/cli.rb,
lib/guard/jasmine/util.rb,
lib/guard/jasmine/runner.rb,
lib/guard/jasmine/server.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, Server, Util Classes: CLI, Runner
Constant Summary collapse
- 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, reporters: nil, debug: false }.freeze
Instance Attribute Summary collapse
-
#last_failed_paths ⇒ Object
Returns the value of attribute last_failed_paths.
-
#last_run_failed ⇒ Object
Returns the value of attribute last_run_failed.
-
#run_all_options ⇒ Object
Returns the value of attribute run_all_options.
-
#runner ⇒ Object
Returns the value of attribute runner.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Jasmine
constructor
Initialize Guard::Jasmine.
-
#reload ⇒ Object
Gets called when the Guard should reload itself.
-
#run_all ⇒ Object
Gets called when all specs should be run.
-
#run_on_modifications(paths) ⇒ Object
Gets called when watched paths and files have changes.
-
#start ⇒ Object
Gets called once when Guard starts.
-
#stop ⇒ Object
Gets called once when Guard stops.
Methods included from Util
find_free_server_port, phantomjs_bin_valid?, runner_available?, which
Constructor Details
#initialize(options = {}) ⇒ Jasmine
Initialize Guard::Jasmine.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/guard/jasmine.rb', line 87 def initialize( = {}) [:server_mount] ||= defined?(JasmineRails) ? '/specs' : '/jasmine' = DEFAULT_OPTIONS.merge() [:spec_dir] ||= File.exist?(File.join('spec', 'javascripts')) ? File.join('spec', 'javascripts') : 'spec' [:server] ||= :auto [:server] = ::Guard::Jasmine::Server.detect_server([:spec_dir]) if [:server] == :auto [:port] ||= ::Guard::Jasmine::Server.choose_server_port() [:jasmine_url] = "http://localhost:#{[:port]}#{[:server] == :jasmine_gem ? '/' : [:server_mount]}" unless [:jasmine_url] [:specdoc] = :failure unless [:always, :never, :failure].include? [:specdoc] [:phantomjs_bin] = Jasmine.which('phantomjs') unless [:phantomjs_bin] self. = .delete(:run_all) || {} super() self.last_run_failed = false self.last_failed_paths = [] ::Jasmine.configure do |config| config.server_port = [:port] if [:port] end @runner = Runner.new(.merge()) end |
Instance Attribute Details
#last_failed_paths ⇒ Object
Returns the value of attribute last_failed_paths.
19 20 21 |
# File 'lib/guard/jasmine.rb', line 19 def last_failed_paths @last_failed_paths end |
#last_run_failed ⇒ Object
Returns the value of attribute last_run_failed.
19 20 21 |
# File 'lib/guard/jasmine.rb', line 19 def last_run_failed @last_run_failed end |
#run_all_options ⇒ Object
Returns the value of attribute run_all_options.
19 20 21 |
# File 'lib/guard/jasmine.rb', line 19 def @run_all_options end |
#runner ⇒ Object
Returns the value of attribute runner.
19 20 21 |
# File 'lib/guard/jasmine.rb', line 19 def runner @runner end |
Instance Method Details
#reload ⇒ Object
Gets called when the Guard should reload itself.
139 140 141 142 |
# File 'lib/guard/jasmine.rb', line 139 def reload self.last_run_failed = false self.last_failed_paths = [] end |
#run_all ⇒ Object
Gets called when all specs should be run.
148 149 150 151 152 153 154 155 |
# File 'lib/guard/jasmine.rb', line 148 def run_all results = runner.run([[:spec_dir]]) self.last_failed_paths = results.keys self.last_run_failed = !results.empty? throw :task_has_failed if last_run_failed end |
#run_on_modifications(paths) ⇒ Object
Gets called when watched paths and files have changes.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/guard/jasmine.rb', line 162 def run_on_modifications(paths) specs = [:keep_failed] ? paths + last_failed_paths : paths specs = Inspector.clean(specs, ) if [:clean] return false if specs.empty? results = runner.run(specs) if results.empty? self.last_failed_paths = last_failed_paths - paths run_all if last_run_failed && [:all_after_pass] else self.last_failed_paths = last_failed_paths + results.keys end self.last_run_failed = !results.empty? throw :task_has_failed if last_run_failed end |
#start ⇒ Object
Gets called once when Guard starts.
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/guard/jasmine.rb', line 116 def start if Jasmine.phantomjs_bin_valid?([:phantomjs_bin]) Server.start() unless [:server] == :none run_all if Jasmine.runner_available?() && [:all_on_start] else throw :task_has_failed end end |