spec/i18n_spec.rb in formtastic-3.1.5 vs spec/i18n_spec.rb in formtastic-4.0.0.rc1
- old
+ new
@@ -1,24 +1,24 @@
# encoding: utf-8
require 'spec_helper'
-describe 'Formtastic::I18n' do
+RSpec.describe 'Formtastic::I18n' do
FORMTASTIC_KEYS = [:required, :yes, :no, :create, :update].freeze
it "should be defined" do
- lambda { Formtastic::I18n }.should_not raise_error
+ expect { Formtastic::I18n }.not_to raise_error
end
describe "default translations" do
it "should be defined" do
- lambda { Formtastic::I18n::DEFAULT_VALUES }.should_not raise_error
- Formtastic::I18n::DEFAULT_VALUES.is_a?(::Hash).should == true
+ expect { Formtastic::I18n::DEFAULT_VALUES }.not_to raise_error
+ expect(Formtastic::I18n::DEFAULT_VALUES.is_a?(::Hash)).to eq(true)
end
it "should exists for the core I18n lookup keys" do
- (Formtastic::I18n::DEFAULT_VALUES.keys & FORMTASTIC_KEYS).size.should == FORMTASTIC_KEYS.size
+ expect((Formtastic::I18n::DEFAULT_VALUES.keys & FORMTASTIC_KEYS).size).to eq(FORMTASTIC_KEYS.size)
end
end
describe "when I18n locales are available" do
@@ -40,27 +40,27 @@
::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"
- Formtastic::I18n.t(:create, :model => 'Post').should == "Default Create Post"
- Formtastic::I18n.t(:update, :model => 'Post').should == "Default Update Post"
+ expect(Formtastic::I18n.t(:required)).to eq("Default Required")
+ expect(Formtastic::I18n.t(:yes)).to eq("Default Yes")
+ expect(Formtastic::I18n.t(:no)).to eq("Default No")
+ expect(Formtastic::I18n.t(:create, :model => 'Post')).to eq("Default Create Post")
+ expect(Formtastic::I18n.t(:update, :model => 'Post')).to eq("Default Update Post")
end
it "should all belong to scope 'formtastic'" do
- Formtastic::I18n.t(:duck, :scope => [:custom_scope]).should == 'Duck'
+ expect(Formtastic::I18n.t(:duck, :scope => [:custom_scope])).to eq('Duck')
end
it "should override default I18n lookup args if these are specified" do
- Formtastic::I18n.t(:duck_pond, :scope => [:custom_scope], :ducks => 15).should == '15 ducks in a pond'
+ expect(Formtastic::I18n.t(:duck_pond, :scope => [:custom_scope], :ducks => 15)).to eq('15 ducks in a pond')
end
it "should be possible to override default values" do
- Formtastic::I18n.t(:required, :default => 'Nothing found!').should == 'Nothing found!'
+ expect(Formtastic::I18n.t(:required, :default => 'Nothing found!')).to eq('Nothing found!')
end
end
describe "when no I18n locales are available" do
@@ -69,11 +69,11 @@
::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]
+ expect(Formtastic::I18n.t(key, :model => '%{model}')).to eq(Formtastic::I18n::DEFAULT_VALUES[key])
end
end
end
@@ -96,111 +96,111 @@
:post => {:body => "Elaborate..." },
:author => { :login => "Hello login" }
}
}}
- @new_post.stub(:title)
- @new_post.stub(:column_for_attribute).with(:title).and_return(double('column', :type => :string, :limit => 255))
+ allow(@new_post).to receive(:title)
+ allow(@new_post).to receive(:column_for_attribute).with(:title).and_return(double('column', :type => :string, :limit => 255))
end
after do
::I18n.backend.reload!
end
it "lookup scopes should be defined" do
with_config :i18n_lookups_by_default, true do
- lambda { Formtastic::I18n::SCOPES }.should_not raise_error
+ expect { Formtastic::I18n::SCOPES }.not_to raise_error
end
end
it "should be able to translate with namespaced object" do
with_config :i18n_lookups_by_default, true do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title))
end)
- output_buffer.should have_tag("form label", /Hello post!/)
+ expect(output_buffer).to have_tag("form label", :text => /Hello post!/)
end
end
it "should be able to translate without form-object" do
with_config :i18n_lookups_by_default, true do
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
concat(builder.input(:title))
end)
- output_buffer.should have_tag("form label", /Hello project!/)
+ expect(output_buffer).to have_tag("form label", :text => /Hello project!/)
end
end
it "should be able to translate when method name is same as model" do
with_config :i18n_lookups_by_default, true do
concat(semantic_form_for(:project, :url => 'http://test.host') do |builder|
concat(builder.input(:author))
end)
- output_buffer.should have_tag("form label", /Author/)
+ expect(output_buffer).to have_tag("form label", :text => /Author/)
end
end
it 'should be able to translate nested objects with nested translations' do
with_config :i18n_lookups_by_default, true do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.semantic_fields_for(:author) do |f|
concat(f.input(:name))
end)
end)
- output_buffer.should have_tag("form label", /Hello author name!/)
+ expect(output_buffer).to have_tag("form label", :text => /Hello author name!/)
end
end
it 'should be able to translate nested objects with top level translations' do
with_config :i18n_lookups_by_default, true do
concat(semantic_form_for(@new_post) do |builder|
builder.semantic_fields_for(:author) do |f|
concat(f.input(:name))
end
end)
- output_buffer.should have_tag("form label", /Hello author name!/)
+ expect(output_buffer).to have_tag("form label", :text => /Hello author name!/)
end
end
it 'should be able to translate nested objects with nested object translations' do
with_config :i18n_lookups_by_default, true do
concat(semantic_form_for(@new_post) do |builder|
builder.semantic_fields_for(:project) do |f|
concat(f.input(:title))
end
end)
- output_buffer.should have_tag("form label", /Hello project!/)
+ expect(output_buffer).to have_tag("form label", :text => /Hello project!/)
end
end
it 'should be able to translate nested forms with top level translations' do
with_config :i18n_lookups_by_default, true do
concat(semantic_form_for(:post) do |builder|
builder.semantic_fields_for(:author) do |f|
concat(f.input(:name))
end
end)
- output_buffer.should have_tag("form label", /Hello author name!/)
+ expect(output_buffer).to have_tag("form label", :text => /Hello author name!/)
end
end
it 'should be able to translate helper label as Rails does' do
with_config :i18n_lookups_by_default, true do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:body))
end)
- output_buffer.should have_tag("form label", /Elaborate/)
+ expect(output_buffer).to have_tag("form label", :text => /Elaborate/)
end
end
it 'should be able to translate nested helper label as Rails does' do
with_config :i18n_lookups_by_default, true do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.inputs(:for => :author) do |f|
concat(f.input(:login))
end)
end)
- output_buffer.should have_tag("form label", /Hello login/)
+ expect(output_buffer).to have_tag("form label", :text => /Hello login/)
end
end
# TODO: Add spec for namespaced models?