vaguerent/test/vagrant/command_test.rb

72 lines
1.7 KiB
Ruby

require File.join(File.dirname(__FILE__), '..', 'test_helper')
class CommandTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Command
end
context "initializing" do
setup do
@env = mock("environment")
end
should "set the env attribute" do
@instance = @klass.new(@env)
assert_equal @env, @instance.env
end
end
context "class methods" do
context "executing" do
should "load the environment then send the command on commands" do
env = mock("env")
commands = mock("commands")
env.stubs(:commands).returns(commands)
Vagrant::Environment.expects(:load!).returns(env)
commands.expects(:subcommand).with(1,2,3).once
@klass.execute(1,2,3)
end
end
end
context "with an instance" do
setup do
@env = mock_environment
@instance = @klass.new(@env)
end
context "subcommands" do
setup do
@raw_name = :bar
@name = :foo
@instance.stubs(:camelize).with(@raw_name).returns(@name)
end
should "send the command to the proper class" do
klass = mock("klass")
instance = mock("instance")
args = [1,2,3]
Vagrant::Commands.expects(:const_get).with(@name).returns(klass)
klass.expects(:new).with(@env).returns(instance)
instance.expects(:execute).with(args)
@instance.subcommand(@raw_name, *args)
end
end
context "camelizing" do
should "camel case a string" do
tests = {
"foo_bar_baz" => "FooBarBaz",
"ssh-config" => "SshConfig"
}
tests.each do |test, expected|
assert_equal expected, @instance.camelize(test)
end
end
end
end
end