Permalink
Browse files

Fixed specs, moved helper methods to spec_helper.

  • Loading branch information...
1 parent 8358fe1 commit c3d6377541fe088417498dabdd5108472ce978df @CvX committed Apr 25, 2012
@@ -1,4 +1,4 @@
# Find more details about this configuration file at http://github.com/fnando/i18n-js
translations:
- - file: "public/javascripts/translations/all.js"
+ - file: "tmp/i18n-js/all.js"
only: "*"
@@ -1,4 +1,4 @@
# Find more details about this configuration file at http://github.com/fnando/i18n-js
translations:
- - file: "public/javascripts/translations.js"
+ - file: "tmp/i18n-js/translations.js"
only: "*"
@@ -1,3 +1,3 @@
translations:
- - file: "/tmp/i18n-js/%{locale}.js"
+ - file: "tmp/i18n-js/%{locale}.js"
only: '*'
@@ -73,4 +73,4 @@ fr:
title: "Visualiser"
note: "plus de détails"
edit:
- title: "Editer"
+ title: "Editer"
@@ -1,5 +1,5 @@
translations:
- - file: "/tmp/i18n-js/bitsnpieces.js"
+ - file: "tmp/i18n-js/bitsnpieces.js"
only:
- "*.date.formats"
- "*.number.currency"
@@ -1,6 +1,6 @@
# Find more details about this configuration file at http://github.com/fnando/i18n-js
translations:
- - file: "public/javascripts/all.js"
+ - file: "tmp/i18n-js/all.js"
+ only: "*"
+ - file: "tmp/i18n-js/tudo.js"
only: "*"
- - file: "public/javascripts/tudo.js"
- only: "*"
@@ -1,3 +1,3 @@
# Find more details about this configuration file at http://github.com/fnando/i18n-js
translations:
- - file: "public/javascripts/no_scope.js"
+ - file: "tmp/i18n-js/no_scope.js"
@@ -1,4 +1,4 @@
# Find more details about this configuration file at http://github.com/fnando/i18n-js
translations:
- - file: "public/javascripts/simple_scope.js"
+ - file: "tmp/i18n-js/simple_scope.js"
only: "*.date.formats"
View
@@ -1,62 +1,55 @@
require "spec_helper"
describe I18n::JS do
- before do
- I18n.load_path = [File.dirname(__FILE__) + "/fixtures/locales.yml"]
- end
-
- around do
- FileUtils.rm_rf("/tmp/i18n-js")
- end
-
context "exporting" do
before do
- I18n::JS.stub :export_dir => "/tmp/i18n-js"
+ I18n::JS.stub :export_dir => temp_path
end
it "exports messages to default path when configuration file doesn't exist" do
I18n::JS.export
- File.join(I18n::JS.export_dir, "translations.js").should be_file
+ file_should_exist "translations.js"
end
it "exports messages using custom output path" do
set_config "custom_path.yml"
- I18n::JS.should_receive(:save).with(translations, "public/javascripts/translations/all.js")
+ I18n::JS.should_receive(:save).with(translations, "tmp/i18n-js/all.js")
I18n::JS.export
end
it "sets default scope to * when not specified" do
set_config "no_scope.yml"
- I18n::JS.should_receive(:save).with(translations, "public/javascripts/no_scope.js")
+ I18n::JS.should_receive(:save).with(translations, "tmp/i18n-js/no_scope.js")
I18n::JS.export
end
it "exports to multiple files" do
set_config "multiple_files.yml"
I18n::JS.export
- File.should be_file(Rails.root.join("public/javascripts/all.js"))
- File.should be_file(Rails.root.join("public/javascripts/tudo.js"))
+ 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 be_file("/tmp/i18n-js/translations.js")
+
+ 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 be_file("/tmp/i18n-js/en.js")
+ file_should_exist "en.js"
end
it "exports with multiple conditions" do
set_config "multiple_conditions.yml"
I18n::JS.export
- File.should be_file("/tmp/i18n-js/bitsnpieces.js")
+ file_should_exist "bitsnpieces.js"
end
end
@@ -126,17 +119,4 @@
target[:a].should eql({:b => 1, :c => 2})
end
end
-
- private
- # Set the configuration as the current one
- def set_config(path)
- config = HashWithIndifferentAccess.new(YAML.load_file(File.dirname(__FILE__) + "/fixtures/#{path}"))
- I18n::JS.stub(:config? => true, :config => config)
- end
-
- # Shortcut to I18n::JS.translations
- def translations
- I18n::JS.translations
- end
end
-
View
@@ -3,3 +3,36 @@
require "active_support/all"
require "i18n/js"
+
+
+RSpec.configure do |config|
+ config.before(:each) do
+ I18n.load_path = [File.dirname(__FILE__) + "/fixtures/locales.yml"]
+ FileUtils.rm_rf(temp_path)
+ end
+
+ config.after(:all) do
+ FileUtils.rm_rf(temp_path)
+ end
+end
+
+
+# Set the configuration as the current one
+def set_config(path)
+ config = HashWithIndifferentAccess.new(YAML.load_file(File.dirname(__FILE__) + "/fixtures/#{path}"))
+ I18n::JS.stub(:config? => true, :config => config)
+end
+
+# Shortcut to I18n::JS.translations
+def translations
+ I18n::JS.translations
+end
+
+def file_should_exist(name)
+ file_path = File.join(I18n::JS.export_dir, name)
+ File.should be_file(file_path)
+end
+
+def temp_path(file_name="")
+ File.join(File.dirname(__FILE__), "..", "tmp", "i18n-js", file_name)
+end

0 comments on commit c3d6377

Please sign in to comment.