Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions lib/guard/rspec/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Options
cmd_additional_args: nil,
launchy: nil,
notification: true,
uniq: false,
title: "RSpec results"
}

Expand Down
23 changes: 22 additions & 1 deletion lib/guard/rspec/runner.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Guard
module RSpecVersion
VERSION = "4.6.4"
VERSION = "4.6.5"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Freeze mutable objects assigned to constants.

end
end