require "spec_helper" describe I18n::JS do describe '.config_file_path' do let(:default_path) { I18n::JS::DEFAULT_CONFIG_PATH } let(:new_path) { File.join("tmp", default_path) } subject { described_class.config_file_path } context "when it is not set" do it { should eq default_path } end context "when it is set already" do before { described_class.config_file_path = new_path } it { should eq new_path } end end context "exporting" do before do stub_const('I18n::JS::DEFAULT_EXPORT_DIR_PATH', temp_path) end it "exports messages to default path when configuration file doesn't exist" do I18n::JS.export file_should_exist "translations.js" end it "exports messages using custom output path" do set_config "custom_path.yml" I18n::JS::Segment.should_receive(:new).with("tmp/i18n-js/all.js", translations, {}).and_call_original I18n::JS::Segment.any_instance.should_receive(:save!).with(no_args) I18n::JS.export end it "sets default scope to * when not specified" do set_config "no_scope.yml" I18n::JS::Segment.should_receive(:new).with("tmp/i18n-js/no_scope.js", translations, {}).and_call_original I18n::JS::Segment.any_instance.should_receive(:save!).with(no_args) I18n::JS.export end it "exports to multiple files" do set_config "multiple_files.yml" I18n::JS.export file_should_exist "all.js" file_should_exist "tudo.js" end it "ignores an empty config file" do set_config "no_config.yml" I18n::JS.export file_should_exist "translations.js" end it "exports to a JS file per available locale" do set_config "js_file_per_locale.yml" I18n::JS.export file_should_exist "en.js" file_should_exist "fr.js" en_output = File.read(File.join(I18n::JS.export_i18n_js_dir_path, "en.js")) expect(en_output).to eq(<