Skip to content

Commit

Permalink
rework Zeus env workaround [fix #326]
Browse files Browse the repository at this point in the history
  • Loading branch information
e2 committed Jul 10, 2015
1 parent e4393ec commit 8c6d94b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
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

0 comments on commit 8c6d94b

Please sign in to comment.