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

rework Zeus env workaround [fix #326] #336

Merged
merged 1 commit into from
Jul 10, 2015
Merged
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
4 changes: 3 additions & 1 deletion lib/guard/rspec/runner.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "guard/rspec_defaults"

require "guard/rspec/inspectors/factory"
require "guard/rspec/command"
require "guard/rspec/notifier"
Expand Down Expand Up @@ -80,7 +82,7 @@ def _open_launchy
end

def _results_file(results_file, chdir)
results_file ||= TEMPORARY_FILE_PATH
results_file ||= RSpecDefaults::TEMPORARY_FILE_PATH
return results_file unless Pathname(results_file).relative?
chdir ? File.join(chdir, results_file) : results_file
end
Expand Down
5 changes: 5 additions & 0 deletions lib/guard/rspec_defaults.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Guard
class RSpecDefaults
TEMPORARY_FILE_PATH = "tmp/rspec_guard_result"
end
end
15 changes: 14 additions & 1 deletion lib/guard/rspec_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
require "rspec"
require "rspec/core/formatters/base_formatter"

require "guard/rspec_defaults"

module Guard
class RSpecFormatter < ::RSpec::Core::Formatters::BaseFormatter
WIKI_ENV_WARN_URL =
"https://github.com/guard/guard-rspec/wiki/Warning:-no-environment"

NO_ENV_WARNING_MSG = "no environment passed - see #{WIKI_ENV_WARN_URL}"
NO_RESULTS_VALUE_MSG = ":results_file value unknown (using defaults)"

def self.rspec_3?
::RSpec::Core::Version::STRING.split(".").first == "3"
end
Expand Down Expand Up @@ -110,7 +118,12 @@ def _status_failed?(example)

def _results_file
path = ENV["GUARD_RSPEC_RESULTS_FILE"]
fail "Fatal: No output file given for Guard::RSpec formatter!" unless path
if path.nil?
STDERR.puts "Guard::RSpec: Warning: #{NO_ENV_WARNING_MSG}\n" \
"Guard::RSpec: Warning: #{NO_RESULTS_VALUE_MSG}"
path = RSpecDefaults::TEMPORARY_FILE_PATH
end

File.expand_path(path)
end
end
Expand Down
29 changes: 29 additions & 0 deletions spec/lib/guard/rspec_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,35 @@ def rspec_summary_args(*args)
end.to raise_error(TypeError, "foo")
end
end

context "when no env is passed" do
let(:file) { File.join(Dir.pwd, "tmp/rspec_guard_result") }

before do
ENV["GUARD_RSPEC_RESULTS_FILE"] = nil

allow(FileUtils).to receive(:mkdir_p).
with(File.dirname(file)) {}

allow(File).to receive(:open).
with(file, "w") do |_, _, &block|
block.call writer
end
end

it "warns" do
expect(STDERR).to receive(:puts).with(/no environment/)
formatter.dump_summary(*example_dump_summary_args)
end

it "uses default file" do
expect(File).to receive(:open).
with(file, "w") do |_, _, &block|
block.call writer
end
formatter.dump_summary(*example_dump_summary_args)
end
end
end

context "with failures" do
Expand Down