From a16bf9abb5785ee7e66304ef3679a55bd8629b8f Mon Sep 17 00:00:00 2001 From: kvokka Date: Fri, 22 Jan 2016 06:55:15 +0100 Subject: [PATCH 1/3] [FIX] Double run with same specs with rubocop --- lib/guard/rspec/runner.rb | 15 +++++++++++++++ lib/guard/rspec/version.rb | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/guard/rspec/runner.rb b/lib/guard/rspec/runner.rb index 6b6ab56d..cff85a10 100644 --- a/lib/guard/rspec/runner.rb +++ b/lib/guard/rspec/runner.rb @@ -5,6 +5,7 @@ require "guard/rspec/notifier" require "guard/rspec/results" require "guard/rspec/rspec_process" +require "digest/md5" module Guard class RSpec < Plugin @@ -24,6 +25,7 @@ def initialize(options = {}) @options = options @inspector = Inspectors::Factory.create(@options) @notifier = Notifier.new(@options) + @last_run_md5 = '' end def run_all @@ -37,6 +39,9 @@ def run_all def run(paths) paths = inspector.paths(paths) return true if paths.empty? + current_specs_md5 = get_last_specs_md5 paths + return true if current_specs_md5 == @last_run_md5 + @last_run_md5 = current_specs_md5 Compat::UI.info("Running: #{paths.join(' ')}", reset: true) _run(paths, options) do |all_green| next false unless all_green @@ -51,6 +56,16 @@ def reload private + def get_last_specs_md5 paths + buffer = [] + paths.each do |f| + next if File.directory? f + buffer << f + buffer << File.readlines(f) + end + Digest::MD5.digest buffer.join("\n") + end + def _run(paths, options, &block) fail NoCmdOptionError unless options[:cmd] command = Command.new(paths, options) diff --git a/lib/guard/rspec/version.rb b/lib/guard/rspec/version.rb index 53d687b9..ecf937a3 100644 --- a/lib/guard/rspec/version.rb +++ b/lib/guard/rspec/version.rb @@ -1,5 +1,5 @@ module Guard module RSpecVersion - VERSION = "4.6.4" + VERSION = "4.6.5" end end From 4b66a5e8f736e5b7b47a6338be5473ca07ac2aea Mon Sep 17 00:00:00 2001 From: kvokka Date: Fri, 22 Jan 2016 22:57:11 +0100 Subject: [PATCH 2/3] added uniq option --- README.md | 1 + lib/guard/rspec/options.rb | 1 + lib/guard/rspec/runner.rb | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1bab531e..c9810b57 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ notification: false # Display notification after the specs are done running, run_all: { cmd: 'custom rspec command', message: 'custom message' } # Custom options to use when running all specs title: 'My project' # Display a custom title for the notification, default: 'RSpec results' chdir: 'directory' # run rspec from within a given subdirectory (useful if project has separate specs for submodules) +uniq: true # run specs only if they are different with previous saved version results_file: 'some/path' # use the given file for storing results (instead of default relative path) ``` diff --git a/lib/guard/rspec/options.rb b/lib/guard/rspec/options.rb index 32206190..ad704170 100644 --- a/lib/guard/rspec/options.rb +++ b/lib/guard/rspec/options.rb @@ -11,6 +11,7 @@ module Options cmd_additional_args: nil, launchy: nil, notification: true, + uniq: false, title: "RSpec results" } diff --git a/lib/guard/rspec/runner.rb b/lib/guard/rspec/runner.rb index cff85a10..d332e34f 100644 --- a/lib/guard/rspec/runner.rb +++ b/lib/guard/rspec/runner.rb @@ -25,7 +25,7 @@ def initialize(options = {}) @options = options @inspector = Inspectors::Factory.create(@options) @notifier = Notifier.new(@options) - @last_run_md5 = '' + @last_run_md5 = "" end def run_all @@ -38,10 +38,7 @@ def run_all def run(paths) paths = inspector.paths(paths) - return true if paths.empty? - current_specs_md5 = get_last_specs_md5 paths - return true if current_specs_md5 == @last_run_md5 - @last_run_md5 = current_specs_md5 + return true if paths.empty? || uniqueness_flag?(paths) Compat::UI.info("Running: #{paths.join(' ')}", reset: true) _run(paths, options) do |all_green| next false unless all_green @@ -56,7 +53,16 @@ def reload private - def get_last_specs_md5 paths + def uniqueness_flag?(paths) + if @options[:uniq] + current_specs_md5 = get_last_specs_md5 paths + return true if current_specs_md5 == @last_run_md5 + @last_run_md5 = current_specs_md5 + end + false + end + + def get_last_specs_md5(paths) buffer = [] paths.each do |f| next if File.directory? f From 3b0663259f48aae82ae562839d33d896bc807529 Mon Sep 17 00:00:00 2001 From: kvokka Date: Sun, 24 Jan 2016 08:24:43 +0100 Subject: [PATCH 3/3] fixup for deleted files error --- lib/guard/rspec/runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/guard/rspec/runner.rb b/lib/guard/rspec/runner.rb index d332e34f..690cbbd0 100644 --- a/lib/guard/rspec/runner.rb +++ b/lib/guard/rspec/runner.rb @@ -65,7 +65,7 @@ def uniqueness_flag?(paths) def get_last_specs_md5(paths) buffer = [] paths.each do |f| - next if File.directory? f + next if File.directory?(f) || !File.exist?(f) buffer << f buffer << File.readlines(f) end