Get rid of util.rb. No longer used.

This commit is contained in:
Mitchell Hashimoto 2010-09-01 14:29:43 -07:00
parent bb97b388f9
commit 3da94252b5
7 changed files with 4 additions and 154 deletions

View File

@ -30,7 +30,7 @@ I18n.load_path << File.expand_path("templates/locales/en.yml", Vagrant.source_ro
# Load them up. One day we'll convert this to autoloads. Today
# is not that day. Low hanging fruit for anyone wishing to do it.
libdir = File.expand_path("lib/vagrant", Vagrant.source_root)
Vagrant::GlobLoader.glob_require(libdir, %w{util util/stacked_proc_runner
Vagrant::GlobLoader.glob_require(libdir, %w{util/stacked_proc_runner
downloaders/base config provisioners/base provisioners/chef systems/base
hosts/base})

View File

@ -1,23 +0,0 @@
module Vagrant
module Util
def self.included(base)
base.extend(self)
end
def error_and_exit(key, data = {})
abort <<-error
=====================================================================
Vagrant experienced an error!
#{Translator.t(key, data).chomp}
=====================================================================
error
end
def wrap_output
puts "====================================================================="
yield
puts "====================================================================="
end
end
end

View File

@ -1,35 +0,0 @@
require 'yaml'
module Vagrant
module Util
# This class is responsible for reading static messages from the strings.yml file.
class Translator
@@strings = nil
class << self
# Resets the internal strings hash to nil, forcing a reload on the next
# access of {strings}.
def reset!
@@strings = nil
end
# Returns the hash of strings from the error YML files. This only loads once,
# then returns a cached value until {reset!} is called.
#
# @return [Hash]
def strings
@@strings ||= YAML.load_file(File.join(Vagrant.source_root, "templates", "strings.yml"))
end
# Renders the string with the given key and data parameters and returns
# the rendered result.
#
# @return [String]
def t(key, data = {})
template = strings[key] || "Unknown strings key: #{key}"
TemplateRenderer.render_string(template, data)
end
end
end
end
end

View File

@ -4,7 +4,6 @@ class ActionWardenTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Action::Warden
@instance = @klass.new([], {})
@klass.any_instance.stubs(:error_and_exit)
end
context "initializing" do

View File

@ -1,61 +0,0 @@
require "test_helper"
class TranslatorUtilTest < Test::Unit::TestCase
include Vagrant::Util
setup do
@klass = Translator
end
context "loading the errors from the YML" do
setup do
YAML.stubs(:load_file)
@klass.reset!
end
should "load the file initially, then never again unless reset" do
YAML.expects(:load_file).with(File.join(Vagrant.source_root, "templates", "strings.yml")).once
@klass.strings
@klass.strings
@klass.strings
@klass.strings
end
should "reload if reset! is called" do
YAML.expects(:load_file).with(File.join(Vagrant.source_root, "templates", "strings.yml")).twice
@klass.strings
@klass.reset!
@klass.strings
end
end
context "getting the string translated" do
setup do
@strings = {}
@strings[:foo] = "foo bar baz"
@klass.stubs(:strings).returns(@strings)
end
should "render the error string" do
TemplateRenderer.expects(:render_string).with(@strings[:foo], anything).once
@klass.t(:foo)
end
should "pass in any data entries" do
data = mock("data")
TemplateRenderer.expects(:render_string).with(@strings[:foo], data).once
@klass.t(:foo, data)
end
should "return the result of the render" do
result = mock("result")
TemplateRenderer.expects(:render_string).returns(result)
assert_equal result, @klass.t(:foo)
end
should "return an unknown if the key doesn't exist" do
result = @klass.t(:unknown)
assert result =~ /Unknown/i
end
end
end

View File

@ -1,27 +0,0 @@
require "test_helper"
class UtilTest < Test::Unit::TestCase
class UtilIncludeTest
include Vagrant::Util
end
setup do
@klass = UtilIncludeTest
end
context "with a class" do
should "have the util methods" do
assert @klass.respond_to?(:error_and_exit)
end
end
context "with an instance" do
setup do
@instance = @klass.new
end
should "have the util methods" do
assert @instance.respond_to?(:error_and_exit)
end
end
end

View File

@ -86,13 +86,11 @@ class VMTest < Test::Unit::TestCase
should "initialize class if given" do
@vm.env.config.vm.system = Vagrant::Systems::Linux
@vm.expects(:error_and_exit).never
@vm.load_system!
assert_nothing_raised { @vm.load_system!}
assert @vm.system.is_a?(Vagrant::Systems::Linux)
end
should "error and exit if class has invalid parent" do
should "raise error if class has invalid parent" do
@vm.env.config.vm.system = FakeSystemClass
assert_raises(Vagrant::Errors::VMSystemError) {
@vm.load_system!
@ -108,9 +106,8 @@ class VMTest < Test::Unit::TestCase
valid.each do |symbol, klass|
@vm.env.config.vm.system = symbol
@vm.expects(:error_and_exit).never
@vm.load_system!
assert_nothing_raised { @vm.load_system! }
assert @vm.system.is_a?(klass)
assert_equal @vm, @vm.system.vm
end