core: expand IsState to support inversions
This commit is contained in:
parent
e93038fd0e
commit
c735e81e4d
|
@ -14,6 +14,7 @@ module Vagrant
|
||||||
@app = app
|
@app = app
|
||||||
@logger = Log4r::Logger.new("vagrant::action::builtin::is_state")
|
@logger = Log4r::Logger.new("vagrant::action::builtin::is_state")
|
||||||
@check = check
|
@check = check
|
||||||
|
@invert = !!opts[:invert]
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
|
@ -22,6 +23,7 @@ module Vagrant
|
||||||
@logger.debug("-- Machine state: #{state}")
|
@logger.debug("-- Machine state: #{state}")
|
||||||
|
|
||||||
env[:result] = @check == state
|
env[:result] = @check == state
|
||||||
|
env[:result] = !env[:result] if @invert
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,17 @@ describe Vagrant::Action::Builtin::IsState do
|
||||||
let(:state) { double("state") }
|
let(:state) { double("state") }
|
||||||
|
|
||||||
describe "#call" do
|
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
|
it "sets result to true if is proper state" do
|
||||||
state.stub(id: :foo)
|
state.stub(id: :foo)
|
||||||
|
|
||||||
|
@ -25,5 +36,16 @@ describe Vagrant::Action::Builtin::IsState do
|
||||||
subject.call(env)
|
subject.call(env)
|
||||||
expect(env[:result]).to be_true
|
expect(env[:result]).to be_true
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue