Skip to content

Commit 1b69394

Browse files
committed
Merge pull request #374 from guard/fix-373_using_guard_ui
stop using Guard::UI in formatter + isolated test
2 parents 40dfe60 + f565af6 commit 1b69394

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
lines changed

lib/guard/rspec_formatter.rb

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
require_relative "rspec_formatter_results_path"
1111

12-
require "guard/ui"
13-
1412
module Guard
1513
class RSpecFormatter < ::RSpec::Core::Formatters::BaseFormatter
1614
UNSUPPORTED_PATTERN =
@@ -117,9 +115,9 @@ def write_summary(duration, total, failures, pending)
117115

118116
def _write(&block)
119117
file = RSpecFormatterResultsPath.new.path
120-
if Guard.const_defined?(:Compat)
118+
if ENV['GUARD_RSPEC_DEBUGGING'] == '1'
121119
msg = "Guard::RSpec: using results file: #{file.inspect}"
122-
Guard::Compat::UI.debug(format(msg, file))
120+
STDERR.puts format(msg, file)
123121
end
124122
FileUtils.mkdir_p(File.dirname(file))
125123
File.open(file, "w", &block)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RSpec.describe "succeeding spec" do
2+
it "works" do
3+
end
4+
end

spec/acceptance/formatter_spec.rb

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'pathname'
2+
require 'tempfile'
3+
4+
require 'gem_isolator'
5+
6+
RSpec.describe "Formatter test", type: :acceptance do
7+
context "when isolated" do
8+
before { allow(Kernel).to receive(:system).and_call_original }
9+
10+
let!(:formatter) { File.expand_path('lib/guard/rspec_formatter.rb') }
11+
12+
context "when a valid results file path is given" do
13+
around do |example|
14+
Tempfile.open('results') do |tempfile|
15+
@results_file = tempfile.path
16+
example.run
17+
end
18+
end
19+
20+
context "when a succeeding command is given" do
21+
let!(:spec) do
22+
File.expand_path('spec/acceptance/fixtures/succeeding_spec.rb')
23+
end
24+
25+
let(:rspec_args) do
26+
['-r', formatter, '-f', 'Guard::RSpecFormatter', spec]
27+
end
28+
29+
context "when guard is not in Gemfile" do
30+
let(:gems) { [%w(rspec ~>3.4)] }
31+
32+
it "works" do
33+
GemIsolator.isolate(gems: gems) do |env, isolation|
34+
env = env.merge('GUARD_RSPEC_RESULTS_FILE' => @results_file)
35+
36+
# TODO: I don't know why Travis needs a full path for binaries
37+
# for system() to work.
38+
rspec = env['PATH'].sub(/:.*/, '/rspec')
39+
expect(isolation.system(env, rspec, *rspec_args)).to eq(true)
40+
end
41+
end
42+
end
43+
end
44+
end
45+
end
46+
end

spec/spec_helper.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ def instance_double(*args)
2929

3030
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
3131
RSpec.configure do |config|
32+
config.register_ordering :global do |examples|
33+
examples.partition { |ex| ex.metadata[:type] != :acceptance }.flatten(1)
34+
end
35+
36+
# Use global for running acceptance tests last
37+
config.order = :global
38+
3239
config.expect_with :rspec do |expectations|
3340
# This option will default to `true` in RSpec 4. It makes the `description`
3441
# and `failure_message` of custom matchers include text for helper methods
@@ -89,12 +96,6 @@ def instance_double(*args)
8996
# particularly slow.
9097
# config.profile_examples = 10
9198

92-
# Run specs in random order to surface order dependencies. If you find an
93-
# order dependency and want to debug it, you can fix the order by providing
94-
# the seed, which is printed after each run.
95-
# --seed 1234
96-
config.order = :random
97-
9899
# Seed global randomization in this process using the `--seed` CLI option.
99100
# Setting this allows you to use `--seed` to deterministically reproduce
100101
# test failures related to randomization by passing the same `--seed` value

0 commit comments

Comments
 (0)