core: expand IsState to support inversions

This commit is contained in:
Mitchell Hashimoto 2014-02-26 17:43:55 -08:00
parent e93038fd0e
commit c735e81e4d
2 changed files with 24 additions and 0 deletions

View File

@ -14,6 +14,7 @@ module Vagrant
@app = app
@logger = Log4r::Logger.new("vagrant::action::builtin::is_state")
@check = check
@invert = !!opts[:invert]
end
def call(env)
@ -22,6 +23,7 @@ module Vagrant
@logger.debug("-- Machine state: #{state}")
env[:result] = @check == state
env[:result] = !env[:result] if @invert
@app.call(env)
end
end

View File

@ -15,6 +15,17 @@ describe Vagrant::Action::Builtin::IsState do
let(:state) { double("state") }
describe "#call" do
it "sets result to false if is proper state" do
state.stub(id: :foo)
subject = described_class.new(app, env, :bar)
app.should_receive(:call).with(env)
subject.call(env)
expect(env[:result]).to be_false
end
it "sets result to true if is proper state" do
state.stub(id: :foo)
@ -25,5 +36,16 @@ describe Vagrant::Action::Builtin::IsState do
subject.call(env)
expect(env[:result]).to be_true
end
it "inverts the result if specified" do
state.stub(id: :foo)
subject = described_class.new(app, env, :foo, invert: true)
app.should_receive(:call).with(env)
subject.call(env)
expect(env[:result]).to be_false
end
end
end