Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[FEATURE] uniq option added #358

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all 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
@@ -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)
```

1 change: 1 addition & 0 deletions lib/guard/rspec/options.rb
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ module Options
cmd_additional_args: nil,
launchy: nil,
notification: true,
uniq: false,
title: "RSpec results"
}

23 changes: 22 additions & 1 deletion lib/guard/rspec/runner.rb
Original file line number Diff line number Diff line change
@@ -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)
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