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 6b6ab56d..690cbbd0 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 @@ -36,7 +38,7 @@ def run_all def run(paths) paths = inspector.paths(paths) - return true if paths.empty? + 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 @@ -51,6 +53,25 @@ def reload private + 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) || !File.exist?(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