Permalink
Browse files

Refactored I18n handling in spec testsuite

* Make use of I18n.backend.reload! to clear/reinitialize translation strings
* Start with a minimal set of translation strings and add expected ones in the test
* Reinitialize the translation backend after each test to start with a known state
  • Loading branch information...
1 parent 89dca89 commit aea23c410836a35e60bc58c0b8f08279a2925a6f @mjonuschat mjonuschat committed Apr 15, 2010
Showing with 46 additions and 50 deletions.
  1. +1 −0 CHANGELOG
  2. +36 −39 spec/commit_button_spec.rb
  3. +8 −11 spec/i18n_spec.rb
  4. +1 −0 spec/inputs/time_input_spec.rb
View
@@ -1,4 +1,5 @@
(HEAD)
+* Changed I18n handling in spec tests to use I18n.backend.reload! instead of assigning nil
* Changed semantic_remote_form_for to allow for unobstrusive javascript / :remote option (rails3)
* Changed spec_helper to support Rails 2 with Rspec od Rails 3 with Rspec 3 environments
* Changed Rakefile to initalize the correct testing framework for the enviroment
View
@@ -140,7 +140,7 @@
end
after do
- ::I18n.backend.store_translations :en, :formtastic => {:submit => nil}
+ ::I18n.backend.reload!
end
it 'should render an input with default I18n-localized label (fallback)' do
@@ -157,33 +157,34 @@
:formtastic => {
:actions => {
:submit => 'Custom Submit',
- :post => {
- :submit => 'Custom Submit {{model}}'
- }
}
}
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
end
- it 'should render an input with localized label (I18n)' do
- semantic_form_for(:post, :url => 'http://example.com') do |builder|
- concat(builder.commit_button)
- end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit Post"][@class~="submit"]})
+ after do
+ ::I18n.backend.reload!
end
- it 'should render an input with anoptional localized label (I18n) - if first is not set' do
+ it 'should render an input with localized label (I18n)' do
::I18n.backend.store_translations :en,
:formtastic => {
:actions => {
:post => {
- :submit => nil
+ :submit => 'Custom Submit {{model}}'
}
}
}
semantic_form_for(:post, :url => 'http://example.com') do |builder|
concat(builder.commit_button)
end
+ output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit Post"][@class~="submit"]})
+ end
+
+ it 'should render an input with anoptional localized label (I18n) - if first is not set' do
+ semantic_form_for(:post, :url => 'http://example.com') do |builder|
+ concat(builder.commit_button)
+ end
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Submit"][@class~="submit"]})
end
@@ -213,7 +214,7 @@
end
after do
- ::I18n.backend.store_translations :en, :formtastic => {:create => nil}
+ ::I18n.backend.reload!
end
it 'should render an input with default I18n-localized label (fallback)' do
@@ -230,40 +231,35 @@
:formtastic => {
:actions => {
:create => 'Custom Create',
- :post => {
- :create => 'Custom Create {{model}}'
- }
}
}
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
end
after do
- ::I18n.backend.store_translations :en, :formtastic => nil
+ ::I18n.backend.reload!
end
it 'should render an input with localized label (I18n)' do
- semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button)
- end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create Post"][@class~="create"]})
- end
-
- it 'should render an input with anoptional localized label (I18n) - if first is not set' do
::I18n.backend.store_translations :en,
:formtastic => {
:actions => {
:post => {
- :create => nil
+ :create => 'Custom Create {{model}}'
}
}
}
semantic_form_for(@new_post) do |builder|
concat(builder.commit_button)
end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create"][@class~="create"]})
- ::I18n.backend.store_translations :en, :formtastic => nil
-
+ output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create Post"][@class~="create"]})
+ end
+
+ it 'should render an input with anoptional localized label (I18n) - if first is not set' do
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.commit_button)
+ end
+ output_buffer.should have_tag(%Q{li.commit input[@value="Custom Create"][@class~="create"]})
end
end
@@ -292,7 +288,7 @@
end
after do
- ::I18n.backend.store_translations :en, :formtastic => {:update => nil}
+ ::I18n.backend.reload!
end
it 'should render an input with default I18n-localized label (fallback)' do
@@ -309,33 +305,34 @@
:formtastic => {
:actions => {
:update => 'Custom Save',
- :post => {
- :update => 'Custom Save {{model}}'
- }
}
}
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
end
- it 'should render an input with localized label (I18n)' do
- semantic_form_for(@new_post) do |builder|
- concat(builder.commit_button)
- end
- output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save Post"][@class~="update"]})
+ after do
+ ::I18n.backend.reload!
end
-
- it 'should render an input with anoptional localized label (I18n) - if first is not set' do
+
+ it 'should render an input with localized label (I18n)' do
::I18n.backend.store_translations :en,
:formtastic => {
:actions => {
:post => {
- :update => nil
+ :update => 'Custom Save {{model}}'
}
}
}
semantic_form_for(@new_post) do |builder|
concat(builder.commit_button)
end
+ output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save Post"][@class~="update"]})
+ end
+
+ it 'should render an input with anoptional localized label (I18n) - if first is not set' do
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.commit_button)
+ end
output_buffer.should have_tag(%Q{li.commit input[@value="Custom Save"][@class~="update"]})
::I18n.backend.store_translations :en, :formtastic => {}
end
View
@@ -24,7 +24,6 @@
before do
@formtastic_strings = {
- :required => 'Default Required',
:yes => 'Default Yes',
:no => 'Default No',
:create => 'Default Create {{model}}',
@@ -36,8 +35,13 @@
}
::I18n.backend.store_translations :en, :formtastic => @formtastic_strings
end
+
+ after do
+ ::I18n.backend.reload!
+ end
it "should translate core strings correctly" do
+ ::I18n.backend.store_translations :en, {:formtastic => {:required => 'Default Required'}}
::Formtastic::I18n.t(:required).should == "Default Required"
::Formtastic::I18n.t(:yes).should == "Default Yes"
::Formtastic::I18n.t(:no).should == "Default No"
@@ -54,7 +58,6 @@
end
it "should be possible to override default values" do
- ::I18n.backend.store_translations :en, {:formtastic => {:required => nil}}
::Formtastic::I18n.t(:required, :default => 'Nothing found!').should == 'Nothing found!'
end
@@ -63,15 +66,9 @@
describe "when no I18n locales are available" do
before do
- ::I18n.backend.store_translations :en, :formtastic => {
- :required => nil,
- :yes => nil,
- :no => nil,
- :create => nil,
- :update => nil
- }
+ ::I18n.backend.reload!
end
-
+
it "should use default strings" do
(::Formtastic::I18n::DEFAULT_VALUES.keys).each do |key|
::Formtastic::I18n.t(key, :model => '{{model}}').should == ::Formtastic::I18n::DEFAULT_VALUES[key]
@@ -102,7 +99,7 @@
end
after do
- ::I18n.backend.store_translations :en, :formtastic => nil
+ ::I18n.backend.reload!
::Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
end
@@ -12,6 +12,7 @@
describe "general" do
before do
+ ::I18n.backend.reload!
output_buffer.replace ''
end

0 comments on commit aea23c4

Please sign in to comment.