require 'rspec/expectations' require 'spree/i18n' require 'spree/testing_support/i18n' describe "i18n" do before do I18n.backend.store_translations(:en, { spree: { foo: "bar", bar: { foo: "bar within bar scope", invalid: nil, legacy_translation: "back in the day..." }, invalid: nil, legacy_translation: "back in the day..." } }) end it "translates within the spree scope" do expect(Spree.normal_t(:foo)).to eql("bar") expect(Spree.translate(:foo)).to eql("bar") end it "translates within the spree scope using a path" do allow(Spree).to receive(:virtual_path).and_return('bar') expect(Spree.normal_t('.legacy_translation')).to eql("back in the day...") expect(Spree.translate('.legacy_translation')).to eql("back in the day...") end it "raise error without any context when using a path" do expect { Spree.normal_t('.legacy_translation') }.to raise_error(StandardError) expect { Spree.translate('.legacy_translation') }.to raise_error(StandardError) end it "prepends a string scope" do expect(Spree.normal_t(:foo, scope: "bar")).to eql("bar within bar scope") end it "prepends to an array scope" do expect(Spree.normal_t(:foo, scope: ["bar"])).to eql("bar within bar scope") end it "returns two translations" do expect(Spree.normal_t([:foo, 'bar.foo'])).to eql(["bar", "bar within bar scope"]) end it "returns reasonable string for missing translations" do expect(Spree.t(:missing_entry)).to include("