Skip to content

Commit

Permalink
Merge 518d371 into 7b77566
Browse files Browse the repository at this point in the history
  • Loading branch information
kvokka committed Jan 22, 2016
2 parents 7b77566 + 518d371 commit 454eb81
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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)
```

Expand Down
23 changes: 22 additions & 1 deletion lib/guard/rspec/runner.rb
Expand Up @@ -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
Expand All @@ -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
Expand 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
Expand All @@ -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
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)
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/rspec/version.rb
@@ -1,5 +1,5 @@
module Guard
module RSpecVersion
VERSION = "4.6.4"
VERSION = "4.6.5"
end
end

0 comments on commit 454eb81

Please sign in to comment.