Sha256: 45cade7f9de171cac4d873504271c663cf2d599f95f9e0fd760ab4651a8f88d1

Contents?: true

Size: 1.56 KB

Versions: 11

Compression:

Stored size: 1.56 KB

Contents

require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')

class ErrorsUtilTest < Test::Unit::TestCase
  include Vagrant::Util

  context "loading the errors from the YML" do
    setup do
      YAML.stubs(:load_file)
      Errors.reset!
    end

    should "load the file initially, then never again unless reset" do
      YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "errors.yml")).once
      Errors.errors
      Errors.errors
      Errors.errors
      Errors.errors
    end

    should "reload if reset! is called" do
      YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "errors.yml")).twice
      Errors.errors
      Errors.reset!
      Errors.errors
    end
  end

  context "getting the error string" do
    setup do
      @errors = {}
      @errors[:foo] = "foo bar baz"
      Errors.stubs(:errors).returns(@errors)
    end

    should "render the error string" do
      TemplateRenderer.expects(:render_string).with(@errors[:foo], anything).once
      Errors.error_string(:foo)
    end

    should "pass in any data entries" do
      data = mock("data")
      TemplateRenderer.expects(:render_string).with(@errors[:foo], data).once
      Errors.error_string(:foo, data)
    end

    should "return the result of the render" do
      result = mock("result")
      TemplateRenderer.expects(:render_string).returns(result)
      assert_equal result, Errors.error_string(:foo)
    end

    should "return an unknown if the key doesn't exist" do
      result = Errors.error_string(:unknown)
      assert result =~ /Unknown/i
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
vagrantup-0.3.4 test/vagrant/util/errors_test.rb
vagrantup-0.3.3 test/vagrant/util/errors_test.rb
vagrantup-0.3.2 test/vagrant/util/errors_test.rb
vagrantup-0.3.1 test/vagrant/util/errors_test.rb
vagrantup-0.3.0 test/vagrant/util/errors_test.rb
vagrant-0.3.4 test/vagrant/util/errors_test.rb
vagrant-0.3.3 test/vagrant/util/errors_test.rb
vagrant-0.3.2 test/vagrant/util/errors_test.rb
vagrant-0.3.1 test/vagrant/util/errors_test.rb
vagrant-0.3.0 test/vagrant/util/errors_test.rb
bmabey-vagrant-0.2.0 test/vagrant/util/errors_test.rb