Sha256: 93fe815f160a6078e5e7210254c844abae60b94cdced5a60feed9e55f5968bcf

Contents?: true

Size: 1.44 KB

Versions: 101

Compression:

Stored size: 1.44 KB

Contents

require "test_helper"

class ErrorsTest < Test::Unit::TestCase
  setup do
    @klass = Vagrant::Errors::VagrantError
    @super = Class.new(@klass) { error_namespace("vagrant.test.errors") }
  end

  should "set the given status code" do
    klass = Class.new(@super) { status_code(4444) }
    assert_equal 4444, klass.new.status_code
  end

  should "raise an error if attempting to set the same status code twice" do
    klass = Class.new(@super) { status_code(4445) }

    assert_raises(RuntimeError) {
      Class.new(@super) { status_code(4445) }
    }
  end

  should "translate the given message if non-hash is given" do
    klass = Class.new(@super)
    assert_equal I18n.t("vagrant.test.errors.test_key"), klass.new("test_key").message
  end

  should "use the alternate namespace if given" do
    klass = Class.new(@super)
    instance = klass.new(:_key => :test_key, :_namespace => "vagrant.test.alternate")
    assert_equal I18n.t("vagrant.test.alternate.test_key"), instance.message
  end

  should "use the translation from I18n if specified" do
    klass = Class.new(@super) { error_key(:test_key) }
    assert_equal I18n.t("vagrant.test.errors.test_key"), klass.new.message
  end

  should "use the translation with the options specified if key given" do
    klass = Class.new(@super) { error_key(:test_key_with_interpolation) }
    assert_equal I18n.t("vagrant.test.errors.test_key_with_interpolation", :key => "yo"), klass.new(:key => "yo").message
  end
end

Version data entries

101 entries across 101 versions & 9 rubygems

Version Path
bmhatfield-vagrant-1.0.10 test/unit_legacy/vagrant/errors_test.rb
bmhatfield-vagrant-1.0.9 test/unit_legacy/vagrant/errors_test.rb
bmhatfield-vagrant-1.0.8 test/unit_legacy/vagrant/errors_test.rb
bmhatfield-vagrant-1.0.7 test/unit_legacy/vagrant/errors_test.rb
vagrantup-1.0.7 test/unit_legacy/vagrant/errors_test.rb
vagrantup-1.0.6 test/unit_legacy/vagrant/errors_test.rb
vagrantup-1.0.5 test/unit_legacy/vagrant/errors_test.rb
vagrantup-1.0.4 test/unit_legacy/vagrant/errors_test.rb
vagrantup-1.0.3 test/unit_legacy/vagrant/errors_test.rb
vagrantup-1.0.2 test/unit_legacy/vagrant/errors_test.rb
vagrantup-1.0.1 test/unit_legacy/vagrant/errors_test.rb
vagrantup-1.0.0 test/unit_legacy/vagrant/errors_test.rb
vagrantup-0.9.99.2 test/unit_legacy/vagrant/errors_test.rb
vagrantup-0.9.99.1 test/unit_legacy/vagrant/errors_test.rb
vagrantup-0.9.7 test/unit_legacy/vagrant/errors_test.rb
vagrantup-0.9.6 test/unit_legacy/vagrant/errors_test.rb
vagrantup-0.9.5 test/unit_legacy/vagrant/errors_test.rb
vagrantup-0.9.4 test/unit_legacy/vagrant/errors_test.rb
vagrantup-0.9.3 test/unit_legacy/vagrant/errors_test.rb
vagrantup-0.9.2 test/unit_legacy/vagrant/errors_test.rb