Skip to content

Commit

Permalink
Merge pull request #374 from guard/fix-373_using_guard_ui
Browse files Browse the repository at this point in the history
stop using Guard::UI in formatter + isolated test
  • Loading branch information
e2 committed May 31, 2016
2 parents 40dfe60 + f565af6 commit 1b69394
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 10 deletions.
6 changes: 2 additions & 4 deletions lib/guard/rspec_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

require_relative "rspec_formatter_results_path"

require "guard/ui"

module Guard
class RSpecFormatter < ::RSpec::Core::Formatters::BaseFormatter
UNSUPPORTED_PATTERN =
Expand Down Expand Up @@ -117,9 +115,9 @@ def write_summary(duration, total, failures, pending)

def _write(&block)
file = RSpecFormatterResultsPath.new.path
if Guard.const_defined?(:Compat)
if ENV['GUARD_RSPEC_DEBUGGING'] == '1'
msg = "Guard::RSpec: using results file: #{file.inspect}"
Guard::Compat::UI.debug(format(msg, file))
STDERR.puts format(msg, file)
end
FileUtils.mkdir_p(File.dirname(file))
File.open(file, "w", &block)
Expand Down
4 changes: 4 additions & 0 deletions spec/acceptance/fixtures/succeeding_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RSpec.describe "succeeding spec" do
it "works" do
end
end
46 changes: 46 additions & 0 deletions spec/acceptance/formatter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'pathname'
require 'tempfile'

require 'gem_isolator'

RSpec.describe "Formatter test", type: :acceptance do
context "when isolated" do
before { allow(Kernel).to receive(:system).and_call_original }

let!(:formatter) { File.expand_path('lib/guard/rspec_formatter.rb') }

context "when a valid results file path is given" do
around do |example|
Tempfile.open('results') do |tempfile|
@results_file = tempfile.path
example.run
end
end

context "when a succeeding command is given" do
let!(:spec) do
File.expand_path('spec/acceptance/fixtures/succeeding_spec.rb')
end

let(:rspec_args) do
['-r', formatter, '-f', 'Guard::RSpecFormatter', spec]
end

context "when guard is not in Gemfile" do
let(:gems) { [%w(rspec ~>3.4)] }

it "works" do
GemIsolator.isolate(gems: gems) do |env, isolation|
env = env.merge('GUARD_RSPEC_RESULTS_FILE' => @results_file)

# TODO: I don't know why Travis needs a full path for binaries
# for system() to work.
rspec = env['PATH'].sub(/:.*/, '/rspec')
expect(isolation.system(env, rspec, *rspec_args)).to eq(true)
end
end
end
end
end
end
end
13 changes: 7 additions & 6 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def instance_double(*args)

# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.register_ordering :global do |examples|
examples.partition { |ex| ex.metadata[:type] != :acceptance }.flatten(1)
end

# Use global for running acceptance tests last
config.order = :global

config.expect_with :rspec do |expectations|
# This option will default to `true` in RSpec 4. It makes the `description`
# and `failure_message` of custom matchers include text for helper methods
Expand Down Expand Up @@ -89,12 +96,6 @@ def instance_double(*args)
# particularly slow.
# config.profile_examples = 10

# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random

# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
Expand Down

0 comments on commit 1b69394

Please sign in to comment.