lib/guard/jasmine.rb in guard-jasmine-2.0.0 vs lib/guard/jasmine.rb in guard-jasmine-2.0.1

- old
+ new

@@ -1,17 +1,15 @@ require 'net/http' -require 'guard' -require 'guard/plugin' +# Don't require "guard/plugin" here or in any other plugin's files +require 'guard/compat/plugin' module Guard - # The Jasmine guard that gets notifications about the following # Guard events: `start`, `stop`, `reload`, `run_all` and `run_on_modifications`. # class Jasmine < Plugin - require 'guard/jasmine/coverage' require 'guard/jasmine/inspector' require 'guard/jasmine/runner' require 'guard/jasmine/server' require 'guard/jasmine/util' @@ -41,11 +39,11 @@ console: :failure, errors: :failure, focus: true, coverage: false, coverage_html: false, - coverage_html_dir: "./coverage", + coverage_html_dir: './coverage', coverage_summary: false, statements_threshold: 0, functions_threshold: 0, branches_threshold: 0, lines_threshold: 0, @@ -86,30 +84,30 @@ # @option options [Symbol] :functions_threshold options for the statement function threshold # @option options [Symbol] :branches_threshold options for the statement branch threshold # @option options [Symbol] :lines_threshold options for the statement lines threshold # @option options [Hash] :run_all options overwrite options when run all specs # - def initialize(options = { }) + 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[:spec_dir] ||= File.exist?(File.join('spec', 'javascripts')) ? File.join('spec', 'javascripts') : 'spec' options[:server] ||= :auto options[:server] = ::Guard::Jasmine::Server.detect_server(options[:spec_dir]) if options[:server] == :auto options[:port] ||= ::Guard::Jasmine::Server.choose_server_port(options) 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[:specdoc] = :failure unless [: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 = [] - @runner = Runner.new( options.merge(self.run_all_options) ) + @runner = Runner.new(options.merge(run_all_options)) end # Gets called once when Guard starts. # # @raise [:task_has_failed] when start has failed @@ -117,13 +115,11 @@ 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 + run_all if Jasmine.runner_available?(options) && options[:all_on_start] else throw :task_has_failed end end @@ -152,36 +148,33 @@ results = runner.run([options[:spec_dir]]) self.last_failed_paths = results.keys self.last_run_failed = !results.empty? - throw :task_has_failed if self.last_run_failed + throw :task_has_failed if last_run_failed end # Gets called when watched paths and files have changes. # # @param [Array<String>] paths the changed paths and files # @raise [:task_has_failed] when run_on_modifications has failed # def run_on_modifications(paths) - - specs = options[:keep_failed] ? paths + self.last_failed_paths : paths + specs = options[:keep_failed] ? paths + last_failed_paths : paths specs = Inspector.clean(specs, options) if options[:clean] return false if specs.empty? results = runner.run(specs) if results.empty? - self.last_failed_paths = self.last_failed_paths - paths - run_all if self.last_run_failed && options[:all_after_pass] + self.last_failed_paths = last_failed_paths - paths + run_all if last_run_failed && options[:all_after_pass] else - self.last_failed_paths = self.last_failed_paths + results.keys + self.last_failed_paths = last_failed_paths + results.keys end self.last_run_failed = !results.empty? - throw :task_has_failed if self.last_run_failed + throw :task_has_failed if last_run_failed end - end end -