From 3da94252b51a358ea877234e28d6dbbea60bf0a7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 1 Sep 2010 14:29:43 -0700 Subject: [PATCH] Get rid of util.rb. No longer used. --- lib/vagrant.rb | 2 +- lib/vagrant/util.rb | 23 ----------- lib/vagrant/util/translator.rb | 35 ---------------- test/vagrant/action/warden_test.rb | 1 - test/vagrant/util/translator_test.rb | 61 ---------------------------- test/vagrant/util_test.rb | 27 ------------ test/vagrant/vm_test.rb | 9 ++-- 7 files changed, 4 insertions(+), 154 deletions(-) delete mode 100644 lib/vagrant/util.rb delete mode 100644 lib/vagrant/util/translator.rb delete mode 100644 test/vagrant/util/translator_test.rb delete mode 100644 test/vagrant/util_test.rb diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 210b69871..f80c4502b 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -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}) diff --git a/lib/vagrant/util.rb b/lib/vagrant/util.rb deleted file mode 100644 index 0c164a6fa..000000000 --- a/lib/vagrant/util.rb +++ /dev/null @@ -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 diff --git a/lib/vagrant/util/translator.rb b/lib/vagrant/util/translator.rb deleted file mode 100644 index ef5072a5f..000000000 --- a/lib/vagrant/util/translator.rb +++ /dev/null @@ -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 diff --git a/test/vagrant/action/warden_test.rb b/test/vagrant/action/warden_test.rb index 6ce0bbe19..5478869ca 100644 --- a/test/vagrant/action/warden_test.rb +++ b/test/vagrant/action/warden_test.rb @@ -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 diff --git a/test/vagrant/util/translator_test.rb b/test/vagrant/util/translator_test.rb deleted file mode 100644 index 5c7fbcdd8..000000000 --- a/test/vagrant/util/translator_test.rb +++ /dev/null @@ -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 diff --git a/test/vagrant/util_test.rb b/test/vagrant/util_test.rb deleted file mode 100644 index 7e8ee707e..000000000 --- a/test/vagrant/util_test.rb +++ /dev/null @@ -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 diff --git a/test/vagrant/vm_test.rb b/test/vagrant/vm_test.rb index 7ce96ff76..288378b15 100644 --- a/test/vagrant/vm_test.rb +++ b/test/vagrant/vm_test.rb @@ -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