From 374c315ffe163e8d009fc9be9660c4c9b91b7fe3 Mon Sep 17 00:00:00 2001 From: Evgeniy Shelest Date: Wed, 17 Jan 2024 12:23:17 +0300 Subject: [PATCH 1/8] Bump dependencies' versions --- Gemfile | 16 +++++++++------ Gemfile.lock | 56 ++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/Gemfile b/Gemfile index 5e900fb..af27f3a 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,13 @@ -source :rubygems +# frozen_string_literal: true -gem 'rake' -gem 'i18n', '>= 0.5.0' -gem 'rspec', '~> 2.7.0' +ruby "2.7.5" -# Rails 3+ -gem 'activesupport', '~> 3.0.0' +source 'https://rubygems.org' + +gem 'rake', '~> 12.3' +gem "i18n", "1.8.11" +gem 'rspec', '~> 3.12.0' + +# Rails 6+ +gem 'activesupport', '~> 6.1.0' diff --git a/Gemfile.lock b/Gemfile.lock index c1abb5d..a57f98a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,24 +1,46 @@ GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: - activesupport (3.0.10) - diff-lcs (1.1.3) - i18n (0.6.0) - rake (0.9.2.2) - rspec (2.7.0) - rspec-core (~> 2.7.0) - rspec-expectations (~> 2.7.0) - rspec-mocks (~> 2.7.0) - rspec-core (2.7.1) - rspec-expectations (2.7.0) - diff-lcs (~> 1.1.2) - rspec-mocks (2.7.0) + activesupport (6.1.7.6) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + concurrent-ruby (1.2.3) + diff-lcs (1.5.0) + i18n (1.8.11) + concurrent-ruby (~> 1.0) + minitest (5.21.1) + rake (12.3.3) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.2) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.6) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.12.0) + rspec-support (3.12.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + zeitwerk (2.6.12) PLATFORMS ruby DEPENDENCIES - activesupport (~> 3.0.0) - i18n (>= 0.5.0) - rake - rspec (~> 2.7.0) + activesupport (~> 6.1.0) + i18n (= 1.8.11) + rake (~> 12.3) + rspec (~> 3.12.0) + +RUBY VERSION + ruby 2.7.5p203 + +BUNDLED WITH + 2.4.19 From 552f43dfda4efb4ff3db60151ebad9006ff21eb6 Mon Sep 17 00:00:00 2001 From: Evgeniy Shelest Date: Wed, 17 Jan 2024 16:11:49 +0300 Subject: [PATCH 2/8] Fix 23 failed specs. --- Rakefile | 4 ++-- spec/i18n/locale/datetime_spec.rb | 1 + spec/locale_spec.rb | 4 ++-- spec/russian_spec.rb | 4 ++-- spec/transliteration_spec.rb | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index 0e65175..cb074a4 100644 --- a/Rakefile +++ b/Rakefile @@ -5,6 +5,6 @@ require 'rubygems/specification' task :default => :spec desc "Run specs" RSpec::Core::RakeTask.new do |t| - t.pattern = FileList['spec/**/*_spec.rb'] - t.rspec_opts = %w(-fs --color) + t.pattern = 'spec/**/*_spec.rb' + t.rspec_opts = %w(--color) end diff --git a/spec/i18n/locale/datetime_spec.rb b/spec/i18n/locale/datetime_spec.rb index 46d52c7..a7df2c7 100644 --- a/spec/i18n/locale/datetime_spec.rb +++ b/spec/i18n/locale/datetime_spec.rb @@ -1,5 +1,6 @@ # -*- encoding: utf-8 -*- +require "active_support/core_ext/date" require File.dirname(__FILE__) + '/../../spec_helper' describe I18n, "Russian Date/Time localization" do diff --git a/spec/locale_spec.rb b/spec/locale_spec.rb index ebfd56a..5d7d09d 100644 --- a/spec/locale_spec.rb +++ b/spec/locale_spec.rb @@ -33,12 +33,12 @@ it "should load pluralization rules" do lookup(:'i18n.plural.rule').should_not be_nil - lookup(:'i18n.plural.rule').is_a?(Proc).should be_true + lookup(:'i18n.plural.rule').is_a?(Proc).should be true end it "should load transliteration rule" do lookup(:'i18n.transliterate.rule').should_not be_nil - lookup(:'i18n.transliterate.rule').is_a?(Proc).should be_true + lookup(:'i18n.transliterate.rule').is_a?(Proc).should be true end def lookup(*args) diff --git a/spec/russian_spec.rb b/spec/russian_spec.rb index 6226bf3..f1f8956 100644 --- a/spec/russian_spec.rb +++ b/spec/russian_spec.rb @@ -40,7 +40,7 @@ describe "with localize proxy" do before(:each) do - @time = mock(:time) + @time = double(:time) @options = { :format => "%d %B %Y" } end @@ -68,7 +68,7 @@ describe "strftime" do before(:each) do - @time = mock(:time) + @time = double(:time) end it "should call localize with object and format" do diff --git a/spec/transliteration_spec.rb b/spec/transliteration_spec.rb index a4f256b..10d8e96 100644 --- a/spec/transliteration_spec.rb +++ b/spec/transliteration_spec.rb @@ -10,7 +10,7 @@ def t(str) %w(transliterate translit).each do |method| it "'#{method}' method should perform transliteration" do - str = mock(:str) + str = double(:str) Russian::Transliteration.should_receive(:transliterate).with(str) Russian.send(method, str) end From 713e0bbbed50cc2cb669d9fda299daaa257da7a5 Mon Sep 17 00:00:00 2001 From: Evgeniy Shelest Date: Wed, 17 Jan 2024 16:16:19 +0300 Subject: [PATCH 3/8] Remove overriding ActiveModel::Errors full_messages --- .../active_model_ext/custom_error_message.rb | 70 ------------------- lib/russian/russian_rails.rb | 6 +- 2 files changed, 1 insertion(+), 75 deletions(-) delete mode 100644 lib/russian/active_model_ext/custom_error_message.rb diff --git a/lib/russian/active_model_ext/custom_error_message.rb b/lib/russian/active_model_ext/custom_error_message.rb deleted file mode 100644 index 4698409..0000000 --- a/lib/russian/active_model_ext/custom_error_message.rb +++ /dev/null @@ -1,70 +0,0 @@ -# -*- encoding: utf-8 -*- - -if defined?(ActiveModel::Errors) - module ActiveModel - class Errors - # Redefine the ActiveModel::Errors.full_messages method: - # Returns all the full error messages in an array. 'Base' messages are handled as usual. - # Non-base messages are prefixed with the attribute name as usual UNLESS they begin with '^' - # in which case the attribute name is omitted. - # E.g. validates_acceptance_of :accepted_terms, :message => '^Please accept the terms of service' - # - # Переопределяет метод ActiveModel::Errors.full_messages. Сообщения об ошибках для атрибутов - # теперь не имеют префикса с названием атрибута если в сообщении об ошибке первым символом указан "^". - # - # Так, например, - # - # validates_acceptance_of :accepted_terms, :message => 'нужно принять соглашение' - # - # даст сообщение - # - # Accepted terms нужно принять соглашение - # - # однако, - # - # validates_acceptance_of :accepted_terms, :message => '^Нужно принять соглашение' - # - # даст сообщение - # - # Нужно принять соглашение - # - # - # Returns all the full error messages in an array. - # - # class Company - # validates_presence_of :name, :address, :email - # validates_length_of :name, :in => 5..30 - # end - # - # company = Company.create(:address => '123 First St.') - # company.errors.full_messages # => - # ["Name is too short (minimum is 5 characters)", "Name can't be blank", "Address can't be blank"] - def full_messages - full_messages = [] - - each do |attribute, messages| - messages = Array.wrap(messages) - next if messages.empty? - - if attribute == :base - messages.each {|m| full_messages << m } - else - attr_name = attribute.to_s.gsub('.', '_').humanize - attr_name = @base.class.human_attribute_name(attribute, :default => attr_name) - options = { :attribute => attr_name, :default => "%{attribute} %{message}" } - - messages.each do |m| - if m =~ /^\^/ - full_messages << m[1..-1] - else - full_messages << I18n.t(:"errors.format", options.merge(:message => m)) - end - end - end - end - - full_messages - end - end - end -end # if defined? diff --git a/lib/russian/russian_rails.rb b/lib/russian/russian_rails.rb index f036547..a7de112 100644 --- a/lib/russian/russian_rails.rb +++ b/lib/russian/russian_rails.rb @@ -1,8 +1,4 @@ # Rails hacks -if defined?(ActiveModel) - require 'active_model_ext/custom_error_message' -end - if defined?(ActionView::Helpers) - require 'action_view_ext/helpers/date_helper' + require 'action_view_ext/helpers/date_helper' end From 2b613f32a65378097fe62dde0851571f73535846 Mon Sep 17 00:00:00 2001 From: Evgeniy Shelest Date: Wed, 17 Jan 2024 19:24:23 +0300 Subject: [PATCH 4/8] Bump gem dependencies and version. --- lib/russian/version.rb | 6 +++--- russian.gemspec | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/russian/version.rb b/lib/russian/version.rb index 716fd76..9fb6c6c 100644 --- a/lib/russian/version.rb +++ b/lib/russian/version.rb @@ -1,8 +1,8 @@ module Russian module VERSION - MAJOR = 0 - MINOR = 6 - TINY = 0 + MAJOR = 1 + MINOR = 0 + TINY = 1 STRING = [MAJOR, MINOR, TINY].join('.') end diff --git a/russian.gemspec b/russian.gemspec index 21076d9..2a6c4b7 100644 --- a/russian.gemspec +++ b/russian.gemspec @@ -19,8 +19,8 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.summary = %q{Russian language support for Ruby and Rails} - s.add_dependency('i18n', '>= 0.5.0') + s.add_dependency('i18n', '1.8.11') - s.add_development_dependency 'activesupport', '>= 3.0.0' - s.add_development_dependency 'rspec', '~> 2.7.0' + s.add_development_dependency 'activesupport', '>= 6.1.0' + s.add_development_dependency 'rspec', '~> 3.12.0' end From cbc909fec79419b62b6cfd71b5c360109de706cf Mon Sep 17 00:00:00 2001 From: Evgeniy Shelest Date: Thu, 18 Jan 2024 10:30:32 +0300 Subject: [PATCH 5/8] Return back specs format output --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index cb074a4..0623f4e 100644 --- a/Rakefile +++ b/Rakefile @@ -6,5 +6,5 @@ task :default => :spec desc "Run specs" RSpec::Core::RakeTask.new do |t| t.pattern = 'spec/**/*_spec.rb' - t.rspec_opts = %w(--color) + t.rspec_opts = %w(-fd --color) end From 3ad6891b48278695d79849ee153213cf6b523b38 Mon Sep 17 00:00:00 2001 From: Evgeniy Shelest Date: Thu, 18 Jan 2024 11:03:48 +0300 Subject: [PATCH 6/8] Remove specs deprecations. --- spec/i18n/locale/datetime_spec.rb | 62 +++++++++++++------------- spec/i18n/locale/pluralization_spec.rb | 24 +++++----- spec/locale_spec.rb | 10 ++--- spec/russian_spec.rb | 54 +++++++++++----------- spec/transliteration_spec.rb | 40 ++++++++--------- 5 files changed, 95 insertions(+), 95 deletions(-) diff --git a/spec/i18n/locale/datetime_spec.rb b/spec/i18n/locale/datetime_spec.rb index a7df2c7..56761f8 100644 --- a/spec/i18n/locale/datetime_spec.rb +++ b/spec/i18n/locale/datetime_spec.rb @@ -12,91 +12,91 @@ describe "with date formats" do it "should use default format" do - l(@date).should == "01.12.1985" + expect(l(@date)).to eq "01.12.1985" end it "should use short format" do - l(@date, :format => :short).should == "01 дек." + expect(l(@date, :format => :short)).to eq "01 дек." end it "should use long format" do - l(@date, :format => :long).should == "01 декабря 1985" + expect(l(@date, :format => :long)).to eq "01 декабря 1985" end end describe "with date day names" do it "should use day names" do - l(@date, :format => "%d %B (%A)").should == "01 декабря (воскресенье)" - l(@date, :format => "%d %B %Y года было %A").should == "01 декабря 1985 года было воскресенье" + expect(l(@date, :format => "%d %B (%A)")).to eq "01 декабря (воскресенье)" + expect(l(@date, :format => "%d %B %Y года было %A")).to eq "01 декабря 1985 года было воскресенье" end it "should use standalone day names" do - l(@date, :format => "%A").should == "Воскресенье" - l(@date, :format => "%A, %d %B").should == "Воскресенье, 01 декабря" + expect(l(@date, :format => "%A")).to eq "Воскресенье" + expect(l(@date, :format => "%A, %d %B")).to eq "Воскресенье, 01 декабря" end it "should use abbreviated day names" do - l(@date, :format => "%a").should == "Вс" - l(@date, :format => "%a, %d %b %Y").should == "Вс, 01 дек. 1985" + expect(l(@date, :format => "%a")).to eq "Вс" + expect(l(@date, :format => "%a, %d %b %Y")).to eq "Вс, 01 дек. 1985" end end describe "with month names" do it "should use month names" do - l(@date, :format => "%d %B").should == "01 декабря" - l(@date, :format => "%-d %B").should == "1 декабря" + expect(l(@date, :format => "%d %B")).to eq "01 декабря" + expect(l(@date, :format => "%-d %B")).to eq "1 декабря" if RUBY_VERSION > "1.9.2" - l(@date, :format => "%1d %B").should == "1 декабря" - l(@date, :format => "%2d %B").should == "01 декабря" + expect(l(@date, :format => "%1d %B")).to eq "1 декабря" + expect(l(@date, :format => "%2d %B")).to eq "01 декабря" end - l(@date, :format => "%e %B %Y").should == " 1 декабря 1985" - l(@date, :format => "%d %B").should == "01 декабря" - l(@date, :format => "%e %B %Y").should == " 1 декабря 1985" - l(@date, :format => "А было тогда %eе число %B %Y").should == "А было тогда 1е число декабря 1985" + expect(l(@date, :format => "%e %B %Y")).to eq " 1 декабря 1985" + expect(l(@date, :format => "%d %B")).to eq "01 декабря" + expect(l(@date, :format => "%e %B %Y")).to eq " 1 декабря 1985" + expect(l(@date, :format => "А было тогда %eе число %B %Y")).to eq "А было тогда 1е число декабря 1985" end it "should use standalone month names" do - l(@date, :format => "%B").should == "Декабрь" - l(@date, :format => "%B %Y").should == "Декабрь 1985" + expect(l(@date, :format => "%B")).to eq "Декабрь" + expect(l(@date, :format => "%B %Y")).to eq "Декабрь 1985" end it "should use abbreviated month names" do @date = Date.parse("1985-03-01") - l(@date, :format => "%d %b").should == "01 марта" - l(@date, :format => "%e %b %Y").should == " 1 марта 1985" - l(@date, :format => "%d %b").should == "01 марта" - l(@date, :format => "%e %b %Y").should == " 1 марта 1985" + expect(l(@date, :format => "%d %b")).to eq "01 марта" + expect(l(@date, :format => "%e %b %Y")).to eq " 1 марта 1985" + expect(l(@date, :format => "%d %b")).to eq "01 марта" + expect(l(@date, :format => "%e %b %Y")).to eq " 1 марта 1985" end it "should use standalone abbreviated month names" do @date = Date.parse("1985-03-01") - l(@date, :format => "%b").should == "март" - l(@date, :format => "%b %Y").should == "март 1985" + expect(l(@date, :format => "%b")).to eq "март" + expect(l(@date, :format => "%b %Y")).to eq "март 1985" end end it "should define default date components order: day, month, year" do - I18n.backend.translate(Russian.locale, :"date.order").should == [:day, :month, :year] + expect(I18n.backend.translate(Russian.locale, :"date.order")).to eq [:day, :month, :year] end describe "with time formats" do it "should use default format" do - l(@time).should =~ /^Вс, 01 дек. 1985, 16:05:00/ + expect(l(@time)).to match /^Вс, 01 дек. 1985, 16:05:00/ end it "should use short format" do - l(@time, :format => :short).should == "01 дек., 16:05" + expect(l(@time, :format => :short)).to eq "01 дек., 16:05" end it "should use long format" do - l(@time, :format => :long).should == "01 декабря 1985, 16:05" + expect(l(@time, :format => :long)).to eq "01 декабря 1985, 16:05" end it "should define am and pm" do - I18n.backend.translate(Russian.locale, :"time.am").should_not be_nil - I18n.backend.translate(Russian.locale, :"time.pm").should_not be_nil + expect(I18n.backend.translate(Russian.locale, :"time.am")).to_not be_nil + expect(I18n.backend.translate(Russian.locale, :"time.pm")).to_not be_nil end end diff --git a/spec/i18n/locale/pluralization_spec.rb b/spec/i18n/locale/pluralization_spec.rb index da15865..2acc13c 100644 --- a/spec/i18n/locale/pluralization_spec.rb +++ b/spec/i18n/locale/pluralization_spec.rb @@ -12,17 +12,17 @@ end it "should pluralize correctly" do - @backend.send(:pluralize, :'ru', @hash, 1).should == 'one' - @backend.send(:pluralize, :'ru', @hash, 2).should == 'few' - @backend.send(:pluralize, :'ru', @hash, 3).should == 'few' - @backend.send(:pluralize, :'ru', @hash, 5).should == 'many' - @backend.send(:pluralize, :'ru', @hash, 10).should == 'many' - @backend.send(:pluralize, :'ru', @hash, 11).should == 'many' - @backend.send(:pluralize, :'ru', @hash, 21).should == 'one' - @backend.send(:pluralize, :'ru', @hash, 29).should == 'many' - @backend.send(:pluralize, :'ru', @hash, 131).should == 'one' - @backend.send(:pluralize, :'ru', @hash, 1.31).should == 'other' - @backend.send(:pluralize, :'ru', @hash, 2.31).should == 'other' - @backend.send(:pluralize, :'ru', @hash, 3.31).should == 'other' + expect(@backend.send(:pluralize, :'ru', @hash, 1)).to eq 'one' + expect(@backend.send(:pluralize, :'ru', @hash, 2)).to eq 'few' + expect(@backend.send(:pluralize, :'ru', @hash, 3)).to eq 'few' + expect(@backend.send(:pluralize, :'ru', @hash, 5)).to eq 'many' + expect(@backend.send(:pluralize, :'ru', @hash, 10)).to eq 'many' + expect(@backend.send(:pluralize, :'ru', @hash, 11)).to eq 'many' + expect(@backend.send(:pluralize, :'ru', @hash, 21)).to eq 'one' + expect(@backend.send(:pluralize, :'ru', @hash, 29)).to eq 'many' + expect(@backend.send(:pluralize, :'ru', @hash, 131)).to eq 'one' + expect(@backend.send(:pluralize, :'ru', @hash, 1.31)).to eq 'other' + expect(@backend.send(:pluralize, :'ru', @hash, 2.31)).to eq 'other' + expect(@backend.send(:pluralize, :'ru', @hash, 3.31)).to eq 'other' end end \ No newline at end of file diff --git a/spec/locale_spec.rb b/spec/locale_spec.rb index 5d7d09d..8059166 100644 --- a/spec/locale_spec.rb +++ b/spec/locale_spec.rb @@ -27,18 +27,18 @@ time.pm ).each do |key| it "should define '#{key}' in datetime translations" do - lookup(key).should_not be_nil + expect(lookup(key)).to_not be_nil end end it "should load pluralization rules" do - lookup(:'i18n.plural.rule').should_not be_nil - lookup(:'i18n.plural.rule').is_a?(Proc).should be true + expect(lookup(:'i18n.plural.rule')).to_not be_nil + expect(lookup(:'i18n.plural.rule').is_a?(Proc)).to be true end it "should load transliteration rule" do - lookup(:'i18n.transliterate.rule').should_not be_nil - lookup(:'i18n.transliterate.rule').is_a?(Proc).should be true + expect(lookup(:'i18n.transliterate.rule')).to_not be_nil + expect(lookup(:'i18n.transliterate.rule').is_a?(Proc)).to be true end def lookup(*args) diff --git a/spec/russian_spec.rb b/spec/russian_spec.rb index f1f8956..bfc885a 100644 --- a/spec/russian_spec.rb +++ b/spec/russian_spec.rb @@ -5,11 +5,11 @@ describe Russian do describe "with locale" do it "should define :'ru' LOCALE" do - Russian::LOCALE.should == :'ru' + expect(Russian::LOCALE).to eq :'ru' end it "should provide 'locale' proxy" do - Russian.locale.should == Russian::LOCALE + expect(Russian.locale).to eq Russian::LOCALE end end @@ -22,19 +22,19 @@ it "should keep existing translations while switching backends" do I18n.load_path << File.join(File.dirname(__FILE__), 'fixtures', 'en.yml') Russian.init_i18n - I18n.t(:foo, :locale => :'en').should == "bar" + expect(I18n.t(:foo, :locale => :'en')).to eq "bar" end it "should keep existing :ru translations while switching backends" do I18n.load_path << File.join(File.dirname(__FILE__), 'fixtures', 'ru.yml') Russian.init_i18n - I18n.t(:'date.formats.default', :locale => :'ru').should == "override" + expect(I18n.t(:'date.formats.default', :locale => :'ru')).to eq "override" end it "should NOT set default locale to Russian locale" do locale = I18n.default_locale Russian.init_i18n - I18n.default_locale.should == locale + expect(I18n.default_locale).to eq locale end end @@ -46,7 +46,7 @@ %w(l localize).each do |method| it "'#{method}' should call I18n backend localize" do - I18n.should_receive(:localize).with(@time, @options.merge({ :locale => Russian.locale })) + expect(I18n).to receive(:localize).with(@time, @options.merge({ :locale => Russian.locale })) Russian.send(method, @time, @options) end end @@ -60,7 +60,7 @@ %w(t translate).each do |method| it "'#{method}' should call I18n backend translate" do - I18n.should_receive(:translate).with(@object, @options.merge({ :locale => Russian.locale })) + expect(I18n).to receive(:translate).with(@object, @options.merge({ :locale => Russian.locale })) Russian.send(method, @object, @options) end end @@ -73,12 +73,12 @@ it "should call localize with object and format" do format = "%d %B %Y" - Russian.should_receive(:localize).with(@time, { :format => format }) + expect(Russian).to receive(:localize).with(@time, { :format => format }) Russian.strftime(@time, format) end it "should call localize with object and default format when format is not specified" do - Russian.should_receive(:localize).with(@time, { :format => :default }) + expect(Russian).to receive(:localize).with(@time, { :format => :default }) Russian.strftime(@time) end end @@ -88,30 +88,30 @@ it "'#{method}' should pluralize with variants given" do variants = %w(вещь вещи вещей вещи) - Russian.send(method, 1, *variants).should == "вещь" - Russian.send(method, 2, *variants).should == 'вещи' - Russian.send(method, 3, *variants).should == 'вещи' - Russian.send(method, 5, *variants).should == 'вещей' - Russian.send(method, 10, *variants).should == 'вещей' - Russian.send(method, 21, *variants).should == 'вещь' - Russian.send(method, 29, *variants).should == 'вещей' - Russian.send(method, 129, *variants).should == 'вещей' - Russian.send(method, 131, *variants).should == 'вещь' - Russian.send(method, 3.14, *variants).should == 'вещи' + expect(Russian.send(method, 1, *variants)).to eq "вещь" + expect(Russian.send(method, 2, *variants)).to eq 'вещи' + expect(Russian.send(method, 3, *variants)).to eq 'вещи' + expect(Russian.send(method, 5, *variants)).to eq 'вещей' + expect(Russian.send(method, 10, *variants)).to eq 'вещей' + expect(Russian.send(method, 21, *variants)).to eq 'вещь' + expect(Russian.send(method, 29, *variants)).to eq 'вещей' + expect(Russian.send(method, 129, *variants)).to eq 'вещей' + expect(Russian.send(method, 131, *variants)).to eq 'вещь' + expect(Russian.send(method, 3.14, *variants)).to eq 'вещи' end it "should raise an exception when first parameter is not a number" do - lambda { Russian.send(method, nil, "вещь", "вещи", "вещей") }.should raise_error(ArgumentError) - lambda { Russian.send(method, "вещь", "вещь", "вещи", "вещей") }.should raise_error(ArgumentError) + expect { Russian.send(method, nil, "вещь", "вещи", "вещей") }.to raise_error(ArgumentError) + expect { Russian.send(method, "вещь", "вещь", "вещи", "вещей") }.to raise_error(ArgumentError) end it "should raise an exception when there are not enough variants" do - lambda { Russian.send(method, 1) }.should raise_error(ArgumentError) - lambda { Russian.send(method, 1, "вещь") }.should raise_error(ArgumentError) - lambda { Russian.send(method, 1, "вещь", "вещи") }.should raise_error(ArgumentError) - lambda { Russian.send(method, 1, "вещь", "вещи", "вещей") }.should_not raise_error(ArgumentError) - lambda { Russian.send(method, 3.14, "вещь", "вещи", "вещей") }.should raise_error(ArgumentError) - lambda { Russian.send(method, 3.14, "вещь", "вещи", "вещей", "вещи") }.should_not raise_error(ArgumentError) + expect { Russian.send(method, 1) }.to raise_error(ArgumentError) + expect { Russian.send(method, 1, "вещь") }.to raise_error(ArgumentError) + expect { Russian.send(method, 1, "вещь", "вещи") }.to raise_error(ArgumentError) + expect { Russian.send(method, 1, "вещь", "вещи", "вещей") }.to_not raise_error + expect { Russian.send(method, 3.14, "вещь", "вещи", "вещей") }.to raise_error(ArgumentError) + expect { Russian.send(method, 3.14, "вещь", "вещи", "вещей", "вещи") }.to_not raise_error end end end diff --git a/spec/transliteration_spec.rb b/spec/transliteration_spec.rb index 10d8e96..0a0cdec 100644 --- a/spec/transliteration_spec.rb +++ b/spec/transliteration_spec.rb @@ -11,7 +11,7 @@ def t(str) %w(transliterate translit).each do |method| it "'#{method}' method should perform transliteration" do str = double(:str) - Russian::Transliteration.should_receive(:transliterate).with(str) + expect(Russian::Transliteration).to receive(:transliterate).with(str) Russian.send(method, str) end end @@ -19,33 +19,33 @@ def t(str) # These tests are from rutils, . it "should transliterate properly" do - t("Это просто некий текст").should == "Eto prosto nekiy tekst" - t("щ").should == "sch" - t("стансы").should == "stansy" - t("упущение").should == "upuschenie" - t("ш").should == "sh" - t("Ш").should == "SH" - t("ц").should == "ts" + expect(t("Это просто некий текст")).to eq "Eto prosto nekiy tekst" + expect(t("щ")).to eq "sch" + expect(t("стансы")).to eq "stansy" + expect(t("упущение")).to eq "upuschenie" + expect(t("ш")).to eq "sh" + expect(t("Ш")).to eq "SH" + expect(t("ц")).to eq "ts" end it "should properly transliterate mixed russian-english strings" do - t("Это кусок строки русских букв v peremeshku s latinizey i амперсандом (pozor!) & something").should == - "Eto kusok stroki russkih bukv v peremeshku s latinizey i ampersandom (pozor!) & something" + expect(t("Это кусок строки русских букв v peremeshku s latinizey i амперсандом (pozor!) & something")) + .to eq "Eto kusok stroki russkih bukv v peremeshku s latinizey i ampersandom (pozor!) & something" end it "should properly transliterate mixed case chars in a string" do - t("НЕВЕРОЯТНОЕ УПУЩЕНИЕ").should == "NEVEROYATNOE UPUSCHENIE" - t("Невероятное Упущение").should == "Neveroyatnoe Upuschenie" - t("Шерстяной Заяц").should == "Sherstyanoy Zayats" - t("Н.П. Шерстяков").should == "N.P. Sherstyakov" - t("ШАРОВАРЫ").should == "SHAROVARY" + expect(t("НЕВЕРОЯТНОЕ УПУЩЕНИЕ")).to eq "NEVEROYATNOE UPUSCHENIE" + expect(t("Невероятное Упущение")).to eq "Neveroyatnoe Upuschenie" + expect(t("Шерстяной Заяц")).to eq "Sherstyanoy Zayats" + expect(t("Н.П. Шерстяков")).to eq "N.P. Sherstyakov" + expect(t("ШАРОВАРЫ")).to eq "SHAROVARY" end it "should work for multi-char substrings" do - t("38 воробьёв").should == "38 vorobiev" - t("Вася Воробьёв").should == "Vasya Vorobiev" - t("Алябьев").should == "Alyabiev" - t("АЛЯБЬЕВ").should == "ALYABIEV" + expect(t("38 воробьёв")).to eq "38 vorobiev" + expect(t("Вася Воробьёв")).to eq "Vasya Vorobiev" + expect(t("Алябьев")).to eq "Alyabiev" + expect(t("АЛЯБЬЕВ")).to eq "ALYABIEV" end end -end \ No newline at end of file +end From 7c1e2c1dcb02291b871387daf1634502befea269 Mon Sep 17 00:00:00 2001 From: Andrey Sidorov Date: Wed, 15 May 2024 17:40:29 +0300 Subject: [PATCH 7/8] fix to make it work with kwargs --- lib/russian.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/russian.rb b/lib/russian.rb index 7c426eb..873922d 100644 --- a/lib/russian.rb +++ b/lib/russian.rb @@ -38,13 +38,13 @@ def init_i18n # See I18n::translate def translate(key, options = {}) - I18n.translate(key, options.merge({ :locale => LOCALE })) + I18n.translate(key, **options.merge({ :locale => LOCALE })) end alias :t :translate # See I18n::localize def localize(object, options = {}) - I18n.localize(object, options.merge({ :locale => LOCALE })) + I18n.localize(object, **options.merge({ :locale => LOCALE })) end alias :l :localize From 2b35d3907b707463cc3095428c643557975ceb7c Mon Sep 17 00:00:00 2001 From: Andrey Sidorov Date: Mon, 20 May 2024 15:19:09 +0300 Subject: [PATCH 8/8] change i18n dependency --- russian.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/russian.gemspec b/russian.gemspec index 2a6c4b7..a7d5ae1 100644 --- a/russian.gemspec +++ b/russian.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |s| s.require_paths = ["lib"] s.summary = %q{Russian language support for Ruby and Rails} - s.add_dependency('i18n', '1.8.11') + s.add_dependency('i18n', '> 1.8.11') s.add_development_dependency 'activesupport', '>= 6.1.0' s.add_development_dependency 'rspec', '~> 3.12.0'