diff --git a/lib/vagrant/action/vm/check.rb b/lib/vagrant/action/vm/check.rb new file mode 100644 index 000000000..ab062e4bb --- /dev/null +++ b/lib/vagrant/action/vm/check.rb @@ -0,0 +1,21 @@ +module Vagrant + class Action + module VM + class Check + def initialize(app, env) + @app = app + end + + def call(env) + box_name = env["config"].vm.box + + env.logger.info "Checking if the box '#{box_name}' was already downloaded" + + box = Vagrant::Box.find(env.env , box_name) + env.logger.info "The box #{box} were found" + @app.call(env) + end + end + end + end +end diff --git a/test/vagrant/action/vm/check_test.rb b/test/vagrant/action/vm/check_test.rb new file mode 100644 index 000000000..181595506 --- /dev/null +++ b/test/vagrant/action/vm/check_test.rb @@ -0,0 +1,25 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper') + + +class CheckVMActionTest < Test::Unit::TestCase + setup do + @klass = Vagrant::Action::VM::Check + @app, @env = mock_action_data + @instance = @klass.new(@app, @env) + + @env['config'].vm.box = "foo" + end + should "check if the box exist" do + Vagrant::Box.expects("find").with(@env.env, 'foo') + @instance.call(@env) + end + + + should 'continue the chain process' do + Vagrant::Box.stubs('find').with(@env.env, 'foo') + @app.expects(:call).with(@env).once + @instance.call(@env) + end + +end +