Sha256: 31b5f3e04522610ecb8382e79316808247c99a35f4695bbafa012c3c25fac3df
Contents?: true
Size: 1.58 KB
Versions: 6
Compression:
Stored size: 1.58 KB
Contents
require File.join(File.dirname(__FILE__), '..', '..', '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(PROJECT_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(PROJECT_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
Version data entries
6 entries across 6 versions & 2 rubygems