Skip to content

Commit

Permalink
hack to get options[:clear] working
Browse files Browse the repository at this point in the history
  • Loading branch information
e2 committed Nov 29, 2014
1 parent 243a2ca commit 6cd4a79
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/guard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ def setup(cmdline_options = {})

@queue = Internals::Queue.new(Guard)

UI.reset_and_clear

_evaluate(state.session.evaluator_options)

# NOTE: this should be *after* evaluate so :directories can work
Expand Down Expand Up @@ -146,6 +144,12 @@ def _pluginless_guardfile?
def _evaluate(options)
evaluator = Guardfile::Evaluator.new(options)
evaluator.evaluate

# TODO: remove this workaround when options are removed
state.session.clearing(state.session.options[:clear])

UI.reset_and_clear

msg = "No plugins found in Guardfile, please add at least one."
UI.error msg if _pluginless_guardfile?

Expand Down
58 changes: 58 additions & 0 deletions spec/lib/guard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
let(:state) { instance_double("Guard::Internals::State") }
let(:queue) { instance_double("Guard::Internals::Queue") }

# TODO: needed only for clearing hack
let(:guard_options) { instance_double("Guard::Options") }

before do
allow(Guard::Interactor).to receive(:new).and_return(interactor)
allow(Guard::Guardfile::Evaluator).to receive(:new).and_return(evaluator)
Expand All @@ -25,6 +28,11 @@
allow(Guard::Internals::Session).to receive(:new).and_return(session)
allow(Guard::Internals::Scope).to receive(:new).and_return(scope)
allow(Guard::Internals::Queue).to receive(:new).and_return(queue)

# TODO: these 3 are needed only for clearing hack
allow(session).to receive(:options).and_return(guard_options)
allow(session).to receive(:clearing)
allow(guard_options).to receive(:[])
end

# TODO: setup has too many responsibilities
Expand Down Expand Up @@ -164,6 +172,56 @@
it { is_expected.to have_received(:new).with(true) }
end
end

describe "UI" do
subject { Guard::UI }

context "gets reset clearing is configured" do
before { Guard.setup(options) }
it { is_expected.to have_received(:reset_and_clear) }
end

# TODO: this is hideous - remove once Guard.options is removed
context "with clearing set in a depreacted way" do
context "with successful evaluation" do
it "resets after guardfile evaluation" do
evaluator_called = nil
called_after_evaluator = nil
clearing_called = nil

allow(evaluator).to receive(:evaluate) do
evaluator_called = true
allow(guard_options).to receive(:[]).with(:clear).and_return(:foo)
end

expect(session).to receive(:clearing).with(:foo) do
clearing_called = true
end

expect(Guard::UI).to receive(:reset_and_clear) do
called_after_evaluator = evaluator_called
end

Guard.setup(options)
expect(called_after_evaluator).to be
expect(clearing_called).to be
end
end

context "with evaluation failure" do
before do
allow(evaluator).to receive(:evaluate).
and_raise(Guard::Guardfile::Evaluator::NoPluginsError)
end

it "does not clear the screen, even when enabled" do
expect(Guard::UI).to_not receive(:reset_and_clear)
expect(Guard::UI).to receive(:error)
Guard.setup(options)
end
end
end
end
end

describe "._relative_pathname" do
Expand Down

0 comments on commit 6cd4a79

Please sign in to comment.