Skip to content
Browse files

make tests green again

  • Loading branch information...
1 parent dfd0d19 commit 510f48cad3aab753579c0d9d8d6f3003d4cac238 @amatsuda committed Mar 13, 2012
Showing with 54 additions and 56 deletions.
  1. +34 −26 spec/i18n_locale_command_spec.rb
  2. +5 −9 spec/i18n_translation_command_spec.rb
  3. +11 −18 spec/translator_spec.rb
  4. +4 −3 spec/yaml_spec.rb
View
60 spec/i18n_locale_command_spec.rb
@@ -1,63 +1,71 @@
-require File.join(File.dirname(__FILE__), 'spec_helper')
-require File.join(File.dirname(__FILE__), '/../generators/i18n_locale/i18n_locale_command')
+require 'spec_helper'
+require 'generators/i18n_locale/i18n_locale_generator'
-describe I18nGenerator::Generator::Commands::Create do
- before do
- (@command = Object.new).extend I18nGenerator::Generator::Commands::Create
- @command.stub!(:locale_name).and_return('ja')
- end
+describe I18nLocaleGenerator do
+ subject { I18nLocaleGenerator.new(['ja']) }
describe 'add_locale_config' do
describe 'when i18n.default_locale is configured in environment.rb' do
before do
@config = "
-Rails::Initializer.run do |config|
- config.i18n.default_locale = :de
+module Tes
+ class Application < Rails::Application
+ config.i18n.default_locale = :de
+ end
end"
end
it 'rewrites the existing default_locale to locale_name value' do
- @command.send(:add_locale_config, @config).should == "
-Rails::Initializer.run do |config|
- config.i18n.default_locale = 'ja'
+ subject.send(:add_locale_config, @config).should == "
+module Tes
+ class Application < Rails::Application
+ config.i18n.default_locale = 'ja'
+ end
end"
end
end
describe 'when i18n.default_locale config is commented in environment.rb' do
before do
@config = "
-Rails::Initializer.run do |config|
- # config.i18n.default_locale = :de
+module Tes
+ class Application < Rails::Application
+ # config.i18n.default_locale = :de
+ end
end"
end
it 'uncomments the existing commented i18n config and sets locale_name value' do
- @command.send(:add_locale_config, @config).should == "
-Rails::Initializer.run do |config|
- config.i18n.default_locale = 'ja'
+ subject.send(:add_locale_config, @config).should == "
+module Tes
+ class Application < Rails::Application
+ config.i18n.default_locale = 'ja'
+ end
end"
end
end
describe 'when i18n.default_locale is not written in environment.rb' do
before do
@config = "
-Rails::Initializer.run do |config|
- something goes here.
- bla bla bla...
+module Tes
+ class Application < Rails::Application
+ something goes here.
+ bla bla bla...
+ end
end"
end
it 'adds the default_locale config inside the config block and sets locale_name value' do
- @command.send(:add_locale_config, @config).should == "
-Rails::Initializer.run do |config|
- config.i18n.default_locale = 'ja'
- something goes here.
- bla bla bla...
+ subject.send(:add_locale_config, @config).should == "
+module Tes
+ class Application < Rails::Application
+ config.i18n.default_locale = 'ja'
+ something goes here.
+ bla bla bla...
+ end
end"
end
end
end
end
-
View
14 spec/i18n_translation_command_spec.rb
@@ -1,11 +1,8 @@
-require File.join(File.dirname(__FILE__), 'spec_helper')
-require File.join(File.dirname(__FILE__), '/../generators/i18n_translation/i18n_translation_command')
+require 'spec_helper'
+require 'generators/i18n_translation/i18n_translation_generator'
-describe I18nGenerator::Generator::Commands::Create do
- before do
- (@command = Object.new).extend I18nGenerator::Generator::Commands::Create
- @command.stub!(:locale_name).and_return('ja')
- end
+describe I18nTranslationGenerator do
+ subject { I18nTranslationGenerator.new(['ja']) }
describe 'each_value' do
it 'iterates through each value' do
@@ -15,10 +12,9 @@
hash[:parent2] = ActiveSupport::OrderedHash.new
hash[:parent2][:child2] = 'child two'
hash[:parent2][:child3] = 'child three'
- @command.__send__(:each_value, [], hash) do |parents, value|
+ subject.send(:each_value, [], hash) do |parents, value|
p "#{parents.join('.')} #{value}"
end
end
end
end
-
View
29 spec/translator_spec.rb
@@ -1,46 +1,39 @@
+# coding: utf-8
$KCODE = 'U'
-require File.join(File.dirname(__FILE__), 'spec_helper')
-require File.join(File.dirname(__FILE__), '../generators/i18n_translation/lib/translator')
-include I18nTranslationGeneratorModule
+require 'spec_helper'
+require 'generators/i18n_translation/lib/translator'
-describe Translator do
- before(:each) do
- @translator = Translator.new 'ja'
- end
+describe I27r::Translator do
+ subject { I27r::Translator.new 'ja' }
describe 'when successfully translated' do
before do
- res_200 = mock('res_200')
- res_200.stub!(:read).and_return('{"responseData": {"translatedText":"こんにちは"}, "responseDetails": null, "responseStatus": 200}')
- OpenURI.stub!(:open_uri).and_return(res_200)
+ subject.stub!(:_translate).and_return('こんにちは')
end
it 'returns translated text' do
- @translator.translate('hello').should == 'こんにちは'
+ subject.translate('hello').should == 'こんにちは'
end
end
describe 'when translation failed with error code' do
before do
- res_500 = mock('res_500')
- res_500.stub!(:read).and_return('{"responseData": {"translatedText":"こんにちは?"}, "responseDetails": null, "responseStatus": 500}')
- OpenURI.stub!(:open_uri).and_return(res_500)
+ subject.stub!(:_translate).and_return('')
end
it 'returns the original text' do
- @translator.translate('hello').should == 'hello'
+ subject.translate('hello').should == 'hello'
end
end
describe 'when translation raised an error' do
before do
- OpenURI.stub!(:open_uri).and_raise('ERROR!')
+ subject.stub!(:_translate).and_raise('ERROR!')
end
it 'returns the original text' do
- @translator.translate('hello').should == 'hello'
+ subject.translate('hello').should == 'hello'
end
end
end
-
View
7 spec/yaml_spec.rb
@@ -1,5 +1,6 @@
-require File.join(File.dirname(__FILE__), 'spec_helper')
-require File.join(File.dirname(__FILE__), '../lib/generators/i18n_translation/lib/yaml')
+# coding: utf-8
+require 'spec_helper'
+require 'generators/i18n_translation/lib/yaml'
describe I27r::YamlDocument do
context 'when loading an existing file' do
@@ -68,7 +69,7 @@
numbers:
one: "いち" #g
two: ""
- three: "さん" #g
+ three: さん #g
aaa:
foo: "ふー"

0 comments on commit 510f48c

Please sign in to comment.
Something went wrong with that request. Please try again.