diff --git a/Gemfile b/Gemfile index cf49d3848..227f71513 100644 --- a/Gemfile +++ b/Gemfile @@ -8,17 +8,7 @@ group :development, :test do gem 'pry' gem 'pry-nav' - platform :rbx do - gem 'rubinius-debugger' - end - - if RUBY_VERSION >= "1.9" && RUBY_PLATFORM != "java" && RUBY_ENGINE != "rbx" - gem 'ruby-prof' - end - - if RUBY_VERSION <= "1.8.7" - gem 'oniguruma' - end + gem 'ruby-prof' unless RUBY_PLATFORM == "java" gem 'regexp_parser', '~> 0.1.6' end @@ -35,18 +25,10 @@ group :test do gem 'rspec', '~> 2.14.0' gem 'rr', '~> 1.1.2' - if RUBY_VERSION >= "1.9" - gem 'rubyzip' - gem 'coveralls', :require => false - end - - platform :mri_18 do - gem 'rcov' - end + gem 'rubyzip' + gem 'coveralls', :require => false - platform :mri_19 do - gem 'simplecov' - gem 'launchy' - end + gem 'simplecov' + gem 'launchy' end diff --git a/README.md b/README.md index da5b17725..19415e7ac 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ - - ## twitter-cldr-rb [![Build Status](https://secure.travis-ci.org/twitter/twitter-cldr-rb.png?branch=master)](http://travis-ci.org/twitter/twitter-cldr-rb) [![Code Climate](https://codeclimate.com/github/twitter/twitter-cldr-rb.png)](https://codeclimate.com/github/twitter/twitter-cldr-rb) [![Coverage Status](https://coveralls.io/repos/twitter/twitter-cldr-rb/badge.png?branch=master)](https://coveralls.io/r/twitter/twitter-cldr-rb?branch=master) TwitterCldr uses Unicode's Common Locale Data Repository (CLDR) to format certain types of text into their @@ -377,13 +375,10 @@ NOTE: If you're using TwitterCLDR with Rails 3, you may see an error if you try '%<{"count": {"one": "only one", "other": "tons more!"}}'.to_str.localize % { :count => 2 } ``` -The `LocalizedString` class supports all forms of interpolation and combines support from both Ruby 1.8 and 1.9: +The `LocalizedString` class supports all forms of interpolation: ```ruby -# Ruby 1.8 -"five euros plus %.3f in tax" % (13.25 * 0.087) - -# Ruby 1.9 +# Ruby "five euros plus %.3f in tax" % (13.25 * 0.087) "there are %{count} horses in the barn" % { :count => "5" } @@ -392,7 +387,7 @@ The `LocalizedString` class supports all forms of interpolation and combines sup "there are %{count} horses in the barn".localize % { :count => "5" } ``` -When you pass a Hash as an argument and specify placeholders with `%d`, TwitterCLDR will interpret the hash values as named arguments and format the string according to the instructions appended to the closing `>`. In this way, TwitterCLDR supports both Ruby 1.8 and 1.9 interpolation syntax in the same string: +When you pass a Hash as an argument and specify placeholders with `%d`, TwitterCLDR will interpret the hash values as named arguments and format the string according to the instructions appended to the closing `>`: ```ruby "five euros plus %.3f in %{noun}".localize % { :percent => 13.25 * 0.087, :noun => "tax" } @@ -482,7 +477,7 @@ postal_code.regexp # /\d{5}([ \-]\d{4})?/ Get a sample of valid postal codes with the `#sample` method: ```ruby -postal_code.sample(5) # ["10923", "88185", "05466", "19797-5720", "47810"] +postal_code.sample(5) # ["20274-2080", "17661", "18705", "77929", "73034-2737"] ``` ### Phone Codes @@ -628,15 +623,9 @@ regex =~ "fooABC" # 3 Protip: Try to avoid negation in character classes (eg. [^abc] and \P{Lu}) as it tends to negatively affect both performance when constructing regexes as well as matching. -#### Support for Ruby 1.8 - -Ruby 1.8 does not allow escaped Unicode characters in regular expressions and restricts their maximum length. TwitterCLDR's `UnicodeRegex` class supports escaped unicode characters in Ruby 1.8, but cannot offer a work-around for the length issue. For this reason, Ruby 1.8 users are required to install the oniguruma regex engine and require the oniguruma gem in their projects. - -To install oniguruma, run `brew install oniguruma` on MacOS, `[sudo] apt-get install libonig-dev` on Ubuntu (you may need to search for other instructions specific to your platform). Then, install the oniguruma gem via your Gemfile or on your system via `gem install oniguruma`. Once installed, `require oniguruma` somewhere in your project before making use of the `TwitterCldr::Shared::UnicodeRegex` class. - ### Text Segmentation -TwitterCLDR currently supports text segmentation by sentence as described in the [Unicode Technical Report #29](http://www.unicode.org/reports/tr29/). The segmentation algorithm makes use of Unicode regular expressions (described above). Because of this, if you're running Ruby 1.8, you'll need to follow the instructions above to install the oniguruma regular expression engine. Segmentation by word, line, and grapheme boundaries could also be supported if someone wants them. +TwitterCLDR currently supports text segmentation by sentence as described in the [Unicode Technical Report #29](http://www.unicode.org/reports/tr29/). The segmentation algorithm makes use of Unicode regular expressions (described above). Segmentation by word, line, and grapheme boundaries could also be supported if someone wants them. You can break a string into sentences using the `LocalizedString#each_sentence` method: @@ -797,7 +786,7 @@ bidi.to_s ### Unicode YAML Support -Ruby 1.8 does not come with great Unicode support, and nowhere is this more apparent then when dumping Unicode characters in YAML. The Psych gem by @tenderlove is a good replacement and is the default in Ruby 1.9, but requires libyaml and still doesn't handle Unicode characters perfectly. To mitigate this problem (especially in Ruby 1.8), TwitterCLDR contains an adaptation of the [ya2yaml](https://github.com/afunai/ya2yaml) gem by Akira Funai. Our changes specifically add better dumping of Ruby symbols. If you can get Mr. Funai's attention, please gently remind him to merge @camertron's pull request so we can use his gem and not have to maintain a separate version :) Fortunately, YAML parsing can still be done with the usual `YAML.load` or `YAML.load_file`. +The Psych gem that is the default YAML engine inRuby 1.9 doesn't handle Unicode characters perfectly. To mitigate this problem, TwitterCLDR contains an adaptation of the [ya2yaml](https://github.com/afunai/ya2yaml) gem by Akira Funai. Our changes specifically add better dumping of Ruby symbols. If you can get Mr. Funai's attention, please gently remind him to merge @camertron's pull request so we can use his gem and not have to maintain a separate version :) Fortunately, YAML parsing can still be done with the usual `YAML.load` or `YAML.load_file`. You can make use of TwitterCLDR's YAML dumper by calling `localize` and then `to_yaml` on an `Array`, `Hash`, or `String`: @@ -842,15 +831,7 @@ TwitterCldr.locale # will return :ru ## Compatibility -TwitterCLDR is fully compatible with Ruby 1.8.7, 1.9.3, 2.0.0, 2.1.0, and Rubinius (v2.2.7). We are considering dropping support for Ruby 1.8. If you still need to use TwitterCLDR in a Ruby 1.8 environment, please let us know as soon as possible. Please note that certain TwitterCLDR features require additional dependencies or considerations when run on Ruby 1.8. Refer to the sections above for details. - -#### Notes on Ruby 1.8 - -Numerous TwitterCLDR features have been built with the assumption that they will only ever be used on UTF-8 encoded text, which is mostly due to the need to support Ruby 1.8. For this reason, you may find it necessary to set the global `$KCODE` variable to `"UTF-8"`. Setting this variable tells Ruby what encoding to use when loading source files. TwitterCLDR will **not** set this value for you. - -```ruby -$KCODE = "UTF-8" -``` +TwitterCLDR is fully compatible with Ruby 1.9.3, 2.0.0, 2.2.0. ## Requirements @@ -864,7 +845,7 @@ Tests are written in RSpec using RR as the mocking framework. ## Test Coverage -You can run the development test coverage suite with `bundle exec rake spec:cov`, or the full suite with `bundle exec rake spec:cov:full`. TwitterCLDR uses RCov under Ruby 1.8 and Simplecov under Ruby 1.9. +You can run the development test coverage suite (using simplecov) with `bundle exec rake spec:cov`, or the full suite with `bundle exec rake spec:cov:full`. ## JavaScript Support diff --git a/README.md.erb b/README.md.erb index 464303702..379be3d84 100644 --- a/README.md.erb +++ b/README.md.erb @@ -1,5 +1,3 @@ -<% $KCODE = "UTF-8" if RUBY_VERSION <= "1.8.7" %> - ## twitter-cldr-rb [![Build Status](https://secure.travis-ci.org/twitter/twitter-cldr-rb.png?branch=master)](http://travis-ci.org/twitter/twitter-cldr-rb) [![Code Climate](https://codeclimate.com/github/twitter/twitter-cldr-rb.png)](https://codeclimate.com/github/twitter/twitter-cldr-rb) [![Coverage Status](https://coveralls.io/repos/twitter/twitter-cldr-rb/badge.png?branch=master)](https://coveralls.io/r/twitter/twitter-cldr-rb?branch=master) TwitterCldr uses Unicode's Common Locale Data Repository (CLDR) to format certain types of text into their @@ -344,13 +342,10 @@ NOTE: If you're using TwitterCLDR with Rails 3, you may see an error if you try '%<{"count": {"one": "only one", "other": "tons more!"}}'.to_str.localize % { :count => 2 } ``` -The `LocalizedString` class supports all forms of interpolation and combines support from both Ruby 1.8 and 1.9: +The `LocalizedString` class supports all forms of interpolation: ```ruby -# Ruby 1.8 -"five euros plus %.3f in tax" % (13.25 * 0.087) - -# Ruby 1.9 +# Ruby "five euros plus %.3f in tax" % (13.25 * 0.087) "there are %{count} horses in the barn" % { :count => "5" } @@ -359,7 +354,7 @@ The `LocalizedString` class supports all forms of interpolation and combines sup "there are %{count} horses in the barn".localize % { :count => "5" } ``` -When you pass a Hash as an argument and specify placeholders with `%d`, TwitterCLDR will interpret the hash values as named arguments and format the string according to the instructions appended to the closing `>`. In this way, TwitterCLDR supports both Ruby 1.8 and 1.9 interpolation syntax in the same string: +When you pass a Hash as an argument and specify placeholders with `%d`, TwitterCLDR will interpret the hash values as named arguments and format the string according to the instructions appended to the closing `>`: ```ruby "five euros plus %.3f in %{noun}".localize % { :percent => 13.25 * 0.087, :noun => "tax" } @@ -595,15 +590,9 @@ regex =~ "fooABC" # <%= assert(regex =~ "fooABC", 3) %> Protip: Try to avoid negation in character classes (eg. [^abc] and \P{Lu}) as it tends to negatively affect both performance when constructing regexes as well as matching. -#### Support for Ruby 1.8 - -Ruby 1.8 does not allow escaped Unicode characters in regular expressions and restricts their maximum length. TwitterCLDR's `UnicodeRegex` class supports escaped unicode characters in Ruby 1.8, but cannot offer a work-around for the length issue. For this reason, Ruby 1.8 users are required to install the oniguruma regex engine and require the oniguruma gem in their projects. - -To install oniguruma, run `brew install oniguruma` on MacOS, `[sudo] apt-get install libonig-dev` on Ubuntu (you may need to search for other instructions specific to your platform). Then, install the oniguruma gem via your Gemfile or on your system via `gem install oniguruma`. Once installed, `require oniguruma` somewhere in your project before making use of the `TwitterCldr::Shared::UnicodeRegex` class. - ### Text Segmentation -TwitterCLDR currently supports text segmentation by sentence as described in the [Unicode Technical Report #29](http://www.unicode.org/reports/tr29/). The segmentation algorithm makes use of Unicode regular expressions (described above). Because of this, if you're running Ruby 1.8, you'll need to follow the instructions above to install the oniguruma regular expression engine. Segmentation by word, line, and grapheme boundaries could also be supported if someone wants them. +TwitterCLDR currently supports text segmentation by sentence as described in the [Unicode Technical Report #29](http://www.unicode.org/reports/tr29/). The segmentation algorithm makes use of Unicode regular expressions (described above). Segmentation by word, line, and grapheme boundaries could also be supported if someone wants them. You can break a string into sentences using the `LocalizedString#each_sentence` method: @@ -770,7 +759,7 @@ bidi.to_s ### Unicode YAML Support -Ruby 1.8 does not come with great Unicode support, and nowhere is this more apparent then when dumping Unicode characters in YAML. The Psych gem by @tenderlove is a good replacement and is the default in Ruby 1.9, but requires libyaml and still doesn't handle Unicode characters perfectly. To mitigate this problem (especially in Ruby 1.8), TwitterCLDR contains an adaptation of the [ya2yaml](https://github.com/afunai/ya2yaml) gem by Akira Funai. Our changes specifically add better dumping of Ruby symbols. If you can get Mr. Funai's attention, please gently remind him to merge @camertron's pull request so we can use his gem and not have to maintain a separate version :) Fortunately, YAML parsing can still be done with the usual `YAML.load` or `YAML.load_file`. +The Psych gem that is the default YAML engine inRuby 1.9 doesn't handle Unicode characters perfectly. To mitigate this problem, TwitterCLDR contains an adaptation of the [ya2yaml](https://github.com/afunai/ya2yaml) gem by Akira Funai. Our changes specifically add better dumping of Ruby symbols. If you can get Mr. Funai's attention, please gently remind him to merge @camertron's pull request so we can use his gem and not have to maintain a separate version :) Fortunately, YAML parsing can still be done with the usual `YAML.load` or `YAML.load_file`. You can make use of TwitterCLDR's YAML dumper by calling `localize` and then `to_yaml` on an `Array`, `Hash`, or `String`: @@ -815,15 +804,7 @@ TwitterCldr.locale # will return :ru ## Compatibility -TwitterCLDR is fully compatible with Ruby 1.8.7, 1.9.3, 2.0.0, 2.1.0, and Rubinius (v2.2.7). We are considering dropping support for Ruby 1.8. If you still need to use TwitterCLDR in a Ruby 1.8 environment, please let us know as soon as possible. Please note that certain TwitterCLDR features require additional dependencies or considerations when run on Ruby 1.8. Refer to the sections above for details. - -#### Notes on Ruby 1.8 - -Numerous TwitterCLDR features have been built with the assumption that they will only ever be used on UTF-8 encoded text, which is mostly due to the need to support Ruby 1.8. For this reason, you may find it necessary to set the global `$KCODE` variable to `"UTF-8"`. Setting this variable tells Ruby what encoding to use when loading source files. TwitterCLDR will **not** set this value for you. - -```ruby -$KCODE = "UTF-8" -``` +TwitterCLDR is fully compatible with Ruby 1.9.3, 2.0.0, 2.2.0. ## Requirements @@ -837,7 +818,7 @@ Tests are written in RSpec using RR as the mocking framework. ## Test Coverage -You can run the development test coverage suite with `bundle exec rake spec:cov`, or the full suite with `bundle exec rake spec:cov:full`. TwitterCLDR uses RCov under Ruby 1.8 and Simplecov under Ruby 1.9. +You can run the development test coverage suite (using simplecov) with `bundle exec rake spec:cov`, or the full suite with `bundle exec rake spec:cov:full`. ## JavaScript Support diff --git a/Rakefile b/Rakefile index f7bba2082..1c139a42c 100644 --- a/Rakefile +++ b/Rakefile @@ -31,33 +31,21 @@ namespace :spec do end end -if RUBY_VERSION < '1.9.0' - desc 'Run specs with RCov' - RSpec::Core::RakeTask.new('spec:cov') do |t| - t.rcov = true - t.pattern = './spec/**/*_spec.rb' - t.rcov_opts = '-T --sort coverage --exclude gems/,spec/' - end - - desc 'Run full specs suit with RCov' - task 'spec:cov:full' => %w[spec:full_spec_env spec:cov] -else - namespace :spec do - desc 'Run specs with SimpleCov' - task :cov => ['spec:simplecov_env', :spec] do - require 'launchy' - Launchy.open 'coverage/index.html' - end +namespace :spec do + desc 'Run specs with SimpleCov' + task :cov => ['spec:simplecov_env', :spec] do + require 'launchy' + Launchy.open 'coverage/index.html' + end - desc 'Run full specs suit with SimpleCov' - task 'cov:full' => %w[spec:full_spec_env spec:cov] + desc 'Run full specs suit with SimpleCov' + task 'cov:full' => %w[spec:full_spec_env spec:cov] - task :simplecov_env do - puts 'Cleaning up coverage reports' - rm_rf 'coverage' + task :simplecov_env do + puts 'Cleaning up coverage reports' + rm_rf 'coverage' - ENV['SCOV'] = 'true' - end + ENV['SCOV'] = 'true' end end diff --git a/lib/twitter_cldr.rb b/lib/twitter_cldr.rb index a8c8c7803..1d54c820a 100644 --- a/lib/twitter_cldr.rb +++ b/lib/twitter_cldr.rb @@ -3,8 +3,6 @@ # Copyright 2012 Twitter, Inc # http://www.apache.org/licenses/LICENSE-2.0 -# $KCODE = 'UTF-8' unless RUBY_VERSION >= '1.9.0' - require 'yaml' require 'date' require 'time' @@ -40,6 +38,7 @@ module TwitterCldr RESOURCES_DIR = File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'resources') + # TODO: convert this and all other hashes to 1.9 syntax # maps twitter locales to cldr locales TWITTER_LOCALE_MAP = { :msa => :ms, diff --git a/lib/twitter_cldr/localized/localized_date.rb b/lib/twitter_cldr/localized/localized_date.rb index 10d00efde..47a87d219 100644 --- a/lib/twitter_cldr/localized/localized_date.rb +++ b/lib/twitter_cldr/localized/localized_date.rb @@ -26,7 +26,7 @@ def to_time(base = Time.now) utc_dt.hour, utc_dt.min, utc_dt.sec, - utc_dt.sec_fraction * (RUBY_VERSION < '1.9' ? 86400000000 : 1000000) + utc_dt.sec_fraction * 1_000_000 ) LocalizedTime.new(time, @locale, chain_params) diff --git a/lib/twitter_cldr/localized/localized_datetime.rb b/lib/twitter_cldr/localized/localized_datetime.rb index 7f356968c..ed810e704 100644 --- a/lib/twitter_cldr/localized/localized_datetime.rb +++ b/lib/twitter_cldr/localized/localized_datetime.rb @@ -90,7 +90,7 @@ def to_time(base = Time.now) utc_dt.hour, utc_dt.min, utc_dt.sec, - utc_dt.sec_fraction * (RUBY_VERSION < '1.9' ? 86400000000 : 1000000) + utc_dt.sec_fraction * 1_000_000 ) LocalizedTime.new(time, @locale, chain_params) diff --git a/lib/twitter_cldr/parsers/unicode_regex/component.rb b/lib/twitter_cldr/parsers/unicode_regex/component.rb index d7df5b8b0..b604411db 100644 --- a/lib/twitter_cldr/parsers/unicode_regex/component.rb +++ b/lib/twitter_cldr/parsers/unicode_regex/component.rb @@ -11,6 +11,7 @@ class Component protected def to_utf8(codepoints) + # TODO: remove 1.8 workaround and fix tests # note: we do this for ruby 1.8 compatibility # if we didn't have to support 1.8, we could do this instead: # Array(codepoints).map { |cp| "\\u{#{cp.to_s(16).rjust(4, "0")}}"}.join diff --git a/lib/twitter_cldr/resources/locales_resources_importer.rb b/lib/twitter_cldr/resources/locales_resources_importer.rb index 2d7ae1411..8f773c455 100644 --- a/lib/twitter_cldr/resources/locales_resources_importer.rb +++ b/lib/twitter_cldr/resources/locales_resources_importer.rb @@ -87,6 +87,7 @@ def deep_symbolize(component, locale, path) File.open(path, 'w:utf-8') do |output| output.write( + # TODO: remove and ensure that resources are imported in the same format # Quote all strings for compat with 1.8. This is important because # RBNF syntax includes characters that are significant in the Yaml # syntax, like >, <, etc. Psych doesn't have problems parsing them, diff --git a/lib/twitter_cldr/resources/readme_renderer.rb b/lib/twitter_cldr/resources/readme_renderer.rb index 6148b92be..34a2d89d8 100644 --- a/lib/twitter_cldr/resources/readme_renderer.rb +++ b/lib/twitter_cldr/resources/readme_renderer.rb @@ -5,13 +5,6 @@ require 'erb' -# patch to add compare operator to Symbol (for mri 1.8) -class Symbol - def <=>(other) - to_s <=> other.to_s - end -end - module TwitterCldr module Resources diff --git a/lib/twitter_cldr/shared/postal_codes.rb b/lib/twitter_cldr/shared/postal_codes.rb index 50d25f351..b84c7e4ad 100644 --- a/lib/twitter_cldr/shared/postal_codes.rb +++ b/lib/twitter_cldr/shared/postal_codes.rb @@ -76,15 +76,7 @@ def sample(sample_size = 1) private def build_regexp(regexp_str, modifiers = '') - if RUBY_VERSION <= "1.8.7" - begin - Oniguruma::ORegexp.new(regexp_str, modifiers) - rescue NameError - raise "Postal codes require the Oniguruma gem when using Ruby 1.8. Please install, require, and retry." - end - else - Regexp.new(regexp_str, modifiers) - end + Regexp.new(regexp_str, modifiers) end def generator diff --git a/lib/twitter_cldr/shared/unicode_regex.rb b/lib/twitter_cldr/shared/unicode_regex.rb index 6d400954c..a34923b13 100644 --- a/lib/twitter_cldr/shared/unicode_regex.rb +++ b/lib/twitter_cldr/shared/unicode_regex.rb @@ -61,15 +61,7 @@ def initialize(elements, modifiers = nil) end def to_regexp - if RUBY_VERSION <= "1.8.7" - begin - Oniguruma::ORegexp.new(to_regexp_str, modifiers) - rescue NameError - raise "Unicode regular expressions require the Oniguruma gem when using Ruby 1.8. Please install, require, and retry." - end - else - @regexp ||= Regexp.new(to_regexp_str, modifiers) - end + @regexp ||= Regexp.new(to_regexp_str, modifiers) end def to_regexp_str diff --git a/lib/twitter_cldr/tokenizers/numbers/rbnf_tokenizer.rb b/lib/twitter_cldr/tokenizers/numbers/rbnf_tokenizer.rb index 946160496..f4e4c79ce 100644 --- a/lib/twitter_cldr/tokenizers/numbers/rbnf_tokenizer.rb +++ b/lib/twitter_cldr/tokenizers/numbers/rbnf_tokenizer.rb @@ -16,11 +16,7 @@ def tokenize(pattern) def tokenizer @tokenizer ||= begin # i.e. %spellout-numbering, %%2d-year - rule_regex = if RUBY_VERSION <= "1.8.7" - /%%?[\w\-]+/u - else - Regexp.new("%%?[[:word:]\-]+") - end + rule_regex = Regexp.new("%%?[[:word:]\-]+") recognizers = [ # special rule descriptors diff --git a/lib/twitter_cldr/utils/yaml.rb b/lib/twitter_cldr/utils/yaml.rb index fb19a6b00..b4ad7cebd 100644 --- a/lib/twitter_cldr/utils/yaml.rb +++ b/lib/twitter_cldr/utils/yaml.rb @@ -128,8 +128,6 @@ class YAML class << self def dump(obj, opts = {}) - raise 'set $KCODE to "UTF8".' if (RUBY_VERSION < '1.9.0') && ($KCODE != 'UTF8') - @options = opts.dup @options[:indent_size] = 2 if @options[:indent_size].to_i <= 0 @options[:minimum_block_length] = 0 if @options[:minimum_block_length].to_i <= 0 diff --git a/spec/bidi/bidi_spec.rb b/spec/bidi/bidi_spec.rb index e688676f0..96d846e7e 100644 --- a/spec/bidi/bidi_spec.rb +++ b/spec/bidi/bidi_spec.rb @@ -28,7 +28,6 @@ def expand_bitset_str(bitset) File.open(BIDI_TEST_PATH, 'r').each_line do |s| cur_line = s.strip first_char = cur_line[0] - first_char = first_char.chr if first_char.is_a?(Fixnum) # conversion for ruby 1.8 case first_char when "#" diff --git a/spec/core_ext_spec.rb b/spec/core_ext_spec.rb index a09c35dc9..9a2ed951f 100644 --- a/spec/core_ext_spec.rb +++ b/spec/core_ext_spec.rb @@ -10,8 +10,7 @@ [Array, Bignum, DateTime, Fixnum, Float, String, Symbol, Time].each do |klass| describe klass do it 'has public instance method #localize' do - # convert methods names to symbols (they're strings in 1.8) - expect(klass.public_instance_methods.map(&:to_sym)).to include(:localize) + expect(klass.public_instance_methods).to include(:localize) end end end diff --git a/spec/parsers/symbol_table_spec.rb b/spec/parsers/symbol_table_spec.rb index 5c43ed330..47a4a7dab 100644 --- a/spec/parsers/symbol_table_spec.rb +++ b/spec/parsers/symbol_table_spec.rb @@ -15,11 +15,7 @@ expect(table.fetch(:a)).to eq("b") fetch = lambda { table.fetch(:z) } - if RUBY_VERSION > "1.8.7" - expect(fetch).to raise_error(KeyError) - else - expect(fetch).to raise_error(IndexError) - end + expect(fetch).to raise_error(KeyError) end end diff --git a/spec/shared/unicode_regex_spec.rb b/spec/shared/unicode_regex_spec.rb index 1e2af67ad..82bd73e10 100644 --- a/spec/shared/unicode_regex_spec.rb +++ b/spec/shared/unicode_regex_spec.rb @@ -37,11 +37,7 @@ def compile(str, symbol_table = nil) describe "#to_regexp" do it "should return a ruby Regexp" do - if RUBY_VERSION <= "1.8.7" - expect(regex.to_regexp).to be_a(Oniguruma::ORegexp) - else - expect(regex.to_regexp).to be_a(Regexp) - end + expect(regex.to_regexp).to be_a(Regexp) end it "should properly turn various basic regexes into strings" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7a7abbdfe..15630e4a1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,24 +6,10 @@ require 'rspec' require 'rspec/autorun' # somehow makes rcov work with rspec require 'twitter_cldr' +require 'pry-nav' +require 'coveralls' -if defined?(RUBY_ENGINE) - if RUBY_ENGINE == "rbx" - require 'rubinius/debugger' - elsif RUBY_ENGINE == "ruby" - require 'pry-nav' - end -end - -if RUBY_VERSION <= "1.8.7" - $KCODE = "UTF-8" - require 'oniguruma' -end - -if RUBY_VERSION >= "1.9.0" - require 'coveralls' - Coveralls.wear! -end +Coveralls.wear! if ENV['SCOV'] require 'simplecov' diff --git a/spec/utils/yaml/yaml_spec.rb b/spec/utils/yaml/yaml_spec.rb index b8c0f114e..ee6d7e5aa 100644 --- a/spec/utils/yaml/yaml_spec.rb +++ b/spec/utils/yaml/yaml_spec.rb @@ -32,26 +32,14 @@ # Psych doesn't handle Unicode characters properly, have to use Syck instead. if YAML.const_defined?(:ENGINE) # Fix undefined method `syck_to_yaml' for class `Object' error on MRI 1.9.3. - # Target only MRI >= 1.9, because on other Rubies, e.g., JRuby, requiring 'syck' results in a LoadError. - if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby' && RUBY_VERSION >= "1.9.0" && RUBY_VERSION < "2.0.0" + # Target only MRI ~1.9, because on other Rubies, e.g., JRuby, requiring 'syck' results in a LoadError. + if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby' && RUBY_VERSION < "2.0.0" require 'syck' end YAML::ENGINE.yamler = 'syck' end -# There's an incompatibility in how ruby handles struct dumps -# between versions that's beyond our scope. -# (One uses strings internally, the other symbols.) -# This just enables tests to pass. -class << Struct - alias yaml_new_without_indifferent_keys yaml_new - def yaml_new(klass, tag, val) - val.keys.each { |k, v| val[k.to_sym] = val.delete(k) } - yaml_new_without_indifferent_keys(klass, tag, val) - end -end if RUBY_VERSION >= "1.9" && RUBY_VERSION <= "1.9.1" # yaml_new is deprecated in 1.9.2 and later - STRUCT_KLASS = Struct::new('Foo', :bar, :buz) class Moo attr_accessor :val1, :val2 @@ -430,15 +418,13 @@ def ==(k) end it "tests binary dumps" do - unless RUBY_VERSION < '1.9.0' - y = nil + y = nil - expect { y = TwitterCldr::Utils::YAML.dump('日本語'.force_encoding('ASCII-8BIT')) }.not_to raise_error - expect(y).to eq("--- !binary |\n 5pel5pys6Kqe\n\n") + expect { y = TwitterCldr::Utils::YAML.dump('日本語'.force_encoding('ASCII-8BIT')) }.not_to raise_error + expect(y).to eq("--- !binary |\n 5pel5pys6Kqe\n\n") - expect { y = TwitterCldr::Utils::YAML.dump('日本語'.encode('EUC-JP').force_encoding('UTF-8')) }.not_to raise_error - expect(y).to eq("--- !binary |\n xvzL3Ljs\n\n") - end + expect { y = TwitterCldr::Utils::YAML.dump('日本語'.encode('EUC-JP').force_encoding('UTF-8')) }.not_to raise_error + expect(y).to eq("--- !binary |\n xvzL3Ljs\n\n") end end