Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Make it possible to override the file name "rerun.txt" #21

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ Former `:color`, `:drb`, `:port` and `:profile` options are thus deprecated and
# default: true

:keep_failed => false # Keep failed features until they pass
# This uses the temporary file `rerun.txt`;
# set `GUARD_CUCUMBER_RERUN_FILE` to override
# default: true

:run_all => { :cli => "-p" } # Override any option when running all specs
Expand Down
2 changes: 1 addition & 1 deletion guard-cucumber.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = ">= 1.3.6"

s.add_dependency "guard-compat", "~> 1.0"
s.add_dependency "cucumber", ">= 1.3.0"
s.add_dependency "cucumber", "~> 1.3"
s.add_dependency "nenv", "~> 0.1"

s.add_development_dependency "bundler", "~> 1.6"
Expand Down
14 changes: 11 additions & 3 deletions lib/guard/cucumber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,22 @@ def run_on_modifications(paths)
def read_failed_features
failed = []

if File.exist?("rerun.txt")
failed = File.open("rerun.txt") { |file| file.read.split(" ") }
File.delete("rerun.txt")
if File.exist?(rerun_file)
failed = File.open(rerun_file) { |file| file.read.split(" ") }
File.delete(rerun_file)
end

failed
end

def rerun_file
Guard::Cucumber.rerun_file
end

def self.rerun_file
ENV["GUARD_CUCUMBER_RERUN_FILE"] || "rerun.txt"
end

# Change the `--format` cli option.
#
# @param [String] format the new format
Expand Down
6 changes: 5 additions & 1 deletion lib/guard/cucumber/notification_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,15 @@ def notify_summary
# Writes the `rerun.txt` file containing all failed features.
#
def write_rerun_features
File.open("rerun.txt", "w") do |f|
File.open(rerun_file, "w") do |f|
f.puts @file_names.join(" ")
end
end

def rerun_file
Guard::Cucumber.rerun_file
end

# Gives the icon name to use for the status.
#
# @param [Symbol] status the cucumber status
Expand Down
17 changes: 17 additions & 0 deletions spec/guard/cucumber/notification_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

context "after all features" do
let(:step) { double("step") }
let(:step_match) { double("step_match") }
let(:feature_element) { double("feature_element") }
let(:file) { double("file") }

before do
allow(mother).to receive(:steps).with(:passed).and_return([step])
Expand All @@ -22,6 +25,20 @@

subject.after_features(nil)
end

before { ENV["GUARD_CUCUMBER_RERUN_FILE"] = "foo/bar.txt" }
after { ENV.delete "GUARD_CUCUMBER_RERUN_FILE" }

it "writes to the rerun file" do
allow(Guard::Compat::UI).to receive(:notify)
allow(step_match).to receive(:format_args)
subject.step_name(nil, step_match, :failed, nil, nil, nil)
expect(file).to receive(:puts).with("features/foo")
expect(File).to receive(:open).with("foo/bar.txt", "w").and_yield(file)
allow(feature_element).to receive(:location).and_return("features/foo")
subject.after_feature_element(feature_element)
subject.after_features(nil)
end
end

describe "#step_name" do
Expand Down
11 changes: 11 additions & 0 deletions spec/guard/cucumber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@
subject.run_on_modifications(["features/bar"])
end

context "when GUARD_CUCUMBER_RERUN_FILE is set" do
before { ENV["GUARD_CUCUMBER_RERUN_FILE"] = "foo/bar.txt" }
after { ENV.delete "GUARD_CUCUMBER_RERUN_FILE" }

it "reads that file instead of rerun.txt" do
expect(runner).to receive(:run).and_return(false)
expect(File).to receive(:exist?).with("foo/bar.txt").and_return(false)
expect { subject.run_all }.to throw_symbol :task_has_failed
end
end

context "with the :feature_sets option" do
non_standard_feature_set = ["a_non_standard_feature_set"]
let(:options) { { feature_sets: non_standard_feature_set } }
Expand Down