diff --git a/lib/vagrant/action/builtin/is_state.rb b/lib/vagrant/action/builtin/is_state.rb index 020ddc3c1..9e37b7a21 100644 --- a/lib/vagrant/action/builtin/is_state.rb +++ b/lib/vagrant/action/builtin/is_state.rb @@ -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 diff --git a/test/unit/vagrant/action/builtin/is_state_test.rb b/test/unit/vagrant/action/builtin/is_state_test.rb index c2e74d62c..68040fb63 100644 --- a/test/unit/vagrant/action/builtin/is_state_test.rb +++ b/test/unit/vagrant/action/builtin/is_state_test.rb @@ -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