Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Version comparison using strings can be faulty. #2024

Closed
wants to merge 1 commit into from

5 participants

@bratish

Version comparison using strings (in the situations like RUBY_VERSION < '1.9.2') can be faulty at times.
Gem::Version is now equipped with symbols for version comparison. It can be used like Gem.ruby_version < '1.9.2'.

@josevalim
Owner

Instead of reopening Gem, maybe we should define ActiveSupport::GemVersion or something like that?

@tenderlove
Owner

This seems like a theoretic problem to me. In theory, it could break. In practice? I have doubts. I'm -1 on this.

@bratish

@josevalim: Will that be very helpful? Internally Gem::Version#<=> is used for comparing. So in any case Gem will come into picture. What do you think?

@tenderlove: I believe, a problem is a problem and it must be addressed. With the string checking approach, Ruby major version 9 is not less than 10. Yeah, major version will not be there in very near future, but this is a failure. For minor version numbers also, is there a policy that prevents them rise past 9?

Additionally this is not only about Ruby versioning. Any gem/lib version can be checked/compared smartly with these methods.

@tenderlove tenderlove closed this
@tenderlove
Owner

We will not monkey patch Gem. Otherwise @drbrain and @zenspider will be upset.

Let's revisit this in 6 years when 1.9.9 is released. In the mean time, we'll avoid the code complexity and maintenance burden of a problem that may (or may not) exist in the future.

@bratish

As I said, this is not only about the Ruby version. This could have been helpful for other version checking also, like
Gem::Version.new(SomeGem::Version) > "x.y.z"

@josevalim
Owner

But the usage inside Rails is limited only to RUBY_VERSION, so I stand by @tenderlove comment. Other people can require and use Gem::Version on their own. :)

@bratish

ok.

@samuelkadolph

There won't be a ruby 1.10. Matz said so.

Hi,

In message "Re: Next Major Version (was Re: Different semantics of Proc
and method call -- bug or feature?)"
on Thu, 3 Aug 2006 00:38:41 +0900, "N Okia" wrecklass1@gmail.com
writes:

|In keeping with your current numbering scheme, does this mean there
|will be a ruby 1.10 release?

The version letters will be stay in one letter each, so that 1.a will
be more likely than 1.10.

http://www.ruby-forum.com/topic/75670#116599

Hi,

In message "Re: Next Major Version (was Re: Different semantics of Proc
and method call -- bug or feature?)"
on Fri, 4 Aug 2006 00:26:39 +0900, "Rick DeNatale"
rick.denatale@gmail.com writes:

|> The version letters will be stay in one letter each, so that 1.a will
|> be more likely than 1.10.

|Matz,
|
|I hesitate to ask YOU this, but are you really sure you want to go that way.
|
|Almost every software package I've run across keeps each level of the
|version "number" as a number, so 1.10 would be much more in line with
|standard practice than 1.a

Ah, well, I forgot to put smiley after the sentence. No, we are not
going to name it neither "1.a" nor "1.10". 1.8.9 will be the last
release of the current stable series. And 1.9 will be the last of the
1.x.

http://www.ruby-forum.com/topic/75670#117142

@drbrain

Gem::Version uses Comparable and #<=> to define #<, #<=, etc.

The Gem::Version patch may be useful if altered <=> instead of all the methods Comparable defines.

@bratish

@samuelkadolph: This reference is informative. Thank you.

@drbrain: I am sorry, but I couldn't get the whole (English is not my first language :( ) of your post. Please help.
By Comparable you mean [ http://www.ruby-doc.org/core/classes/Comparable.html ] right?
This Gem::Version patch uses spaceship to define others similar to Comparable module methods except #between?. Do you suggest to include that as well?

@drbrain

@bratish your patch is wrong. To use Comparable you define <=> to do what you need and let Comparable's <, <=, etc call <=> for you. Don't define the methods Comparable defines, it's there to help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 9, 2011
  1. @bratish

    Version comparison using strings is faulty. Gem::Version is now equip…

    bratish authored
    …ped with symbols for version comparison.
This page is out of date. Refresh to see the latest.
Showing with 183 additions and 44 deletions.
  1. +2 −0  actionmailer/test/abstract_unit.rb
  2. +2 −0  actionpack/test/abstract_unit.rb
  3. +2 −0  activemodel/test/cases/helper.rb
  4. +1 −0  activerecord/test/cases/base_test.rb
  5. +1 −0  activeresource/test/abstract_unit.rb
  6. +2 −1  activesupport/lib/active_support/core_ext/date/calculations.rb
  7. +5 −4 activesupport/lib/active_support/core_ext/date/conversions.rb
  8. +2 −1  activesupport/lib/active_support/core_ext/date/freeze.rb
  9. +2 −1  activesupport/lib/active_support/core_ext/date_time/calculations.rb
  10. +2 −1  activesupport/lib/active_support/core_ext/date_time/conversions.rb
  11. +2 −1  activesupport/lib/active_support/core_ext/enumerable.rb
  12. +2 −1  activesupport/lib/active_support/core_ext/exception.rb
  13. +2 −1  activesupport/lib/active_support/core_ext/float/rounding.rb
  14. +2 −1  activesupport/lib/active_support/core_ext/module/introspection.rb
  15. +2 −1  activesupport/lib/active_support/core_ext/object/instance_variables.rb
  16. +1 −0  activesupport/lib/active_support/core_ext/rubygems.rb
  17. +61 −0 activesupport/lib/active_support/core_ext/rubygems/version.rb
  18. +3 −1 activesupport/lib/active_support/core_ext/string/multibyte.rb
  19. +2 −1  activesupport/lib/active_support/core_ext/uri.rb
  20. +3 −2 activesupport/lib/active_support/multibyte/chars.rb
  21. +3 −1 activesupport/lib/active_support/ordered_hash.rb
  22. +6 −3 activesupport/test/abstract_unit.rb
  23. +2 −1  activesupport/test/core_ext/date_ext_test.rb
  24. +9 −8 activesupport/test/core_ext/hash_ext_test.rb
  25. +2 −1  activesupport/test/core_ext/range_ext_test.rb
  26. +42 −0 activesupport/test/core_ext/rubygems_ext_test.rb
  27. +6 −5 activesupport/test/core_ext/string_ext_test.rb
  28. +2 −1  activesupport/test/core_ext/time_with_zone_test.rb
  29. +3 −2 activesupport/test/multibyte_chars_test.rb
  30. +2 −1  activesupport/test/multibyte_utils_test.rb
  31. +5 −4 activesupport/test/ordered_hash_test.rb
View
2  actionmailer/test/abstract_unit.rb
@@ -11,6 +11,8 @@
$VERBOSE = old
end
+require 'active_support/core_ext/rubygems'
+
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/string/encoding'
View
2  actionpack/test/abstract_unit.rb
@@ -12,6 +12,8 @@
ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp')
+require 'active_support/core_ext/rubygems'
+
require 'active_support/core_ext/kernel/reporting'
require 'active_support/core_ext/string/encoding'
View
2  activemodel/test/cases/helper.rb
@@ -5,9 +5,11 @@
require 'config'
require 'active_model'
+require 'active_support/core_ext/rubygems'
require 'active_support/core_ext/string/access'
# Show backtraces for deprecated behavior for quicker cleanup.
ActiveSupport::Deprecation.debug = true
require 'test/unit'
+
View
1  activerecord/test/cases/base_test.rb
@@ -22,6 +22,7 @@
require 'models/edge'
require 'models/joke'
require 'rexml/document'
+require 'active_support/core_ext/rubygems'
require 'active_support/core_ext/exception'
class Category < ActiveRecord::Base; end
View
1  activeresource/test/abstract_unit.rb
@@ -6,6 +6,7 @@
require 'test/unit'
require 'active_resource'
require 'active_support'
+require 'active_support/core_ext/rubygems'
require 'active_support/test_case'
require 'setter_trap'
View
3  activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -7,7 +7,7 @@
class Date
DAYS_INTO_WEEK = { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6 }
- if RUBY_VERSION < '1.9'
+ if Gem.ruby_version < '1.9'
undef :>>
# Backported from 1.9. The one in 1.8 leads to incorrect next_month and
@@ -251,3 +251,4 @@ def tomorrow
self + 1
end
end
+
View
9 activesupport/lib/active_support/core_ext/date/conversions.rb
@@ -67,7 +67,7 @@ def readable_inspect
# In this case, it simply returns +self+.
def to_date
self
- end if RUBY_VERSION < '1.9'
+ end if Gem.ruby_version < '1.9'
# Converts a Date instance to a Time, where the time is set to the beginning of the day.
# The timezone can be either :local or :utc (default :local).
@@ -92,15 +92,16 @@ def to_time(form = :local)
# date.to_datetime # => Sat, 10 Nov 2007 00:00:00 0000
def to_datetime
::DateTime.civil(year, month, day, 0, 0, 0, 0)
- end if RUBY_VERSION < '1.9'
+ end if Gem.ruby_version < '1.9'
def iso8601
strftime('%F')
- end if RUBY_VERSION < '1.9'
+ end if Gem.ruby_version < '1.9'
- alias_method :rfc3339, :iso8601 if RUBY_VERSION < '1.9'
+ alias_method :rfc3339, :iso8601 if Gem.ruby_version < '1.9'
def xmlschema
to_time_in_current_zone.xmlschema
end
end
+
View
3  activesupport/lib/active_support/core_ext/date/freeze.rb
@@ -9,7 +9,7 @@
#
# Ruby 1.9 uses a preinitialized instance variable so it's unaffected.
# This hack is as close as we can get to feature detection:
-if RUBY_VERSION < '1.9'
+if Gem.ruby_version < '1.9'
require 'date'
begin
::Date.today.freeze.jd
@@ -31,3 +31,4 @@ def freeze
end
end
end
+
View
3  activesupport/lib/active_support/core_ext/date_time/calculations.rb
@@ -1,4 +1,4 @@
-require 'rational' unless RUBY_VERSION >= '1.9.2'
+require 'rational' unless Gem.ruby_version >= '1.9.2'
class DateTime
class << self
@@ -130,3 +130,4 @@ def <=>(other)
super other.to_datetime
end
end
+
View
3  activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -66,7 +66,7 @@ def to_date
# Attempts to convert self to a Ruby Time object; returns self if out of range of Ruby Time class.
# If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time.
def to_time
- self.offset == 0 ? ::Time.utc_time(year, month, day, hour, min, sec, sec_fraction * (RUBY_VERSION < '1.9' ? 86400000000 : 1000000)) : self
+ self.offset == 0 ? ::Time.utc_time(year, month, day, hour, min, sec, sec_fraction * (Gem.ruby_version < '1.9' ? 86400000000 : 1000000)) : self
end
# To be able to keep Times, Dates and DateTimes interchangeable on conversions.
@@ -101,3 +101,4 @@ def seconds_since_unix_epoch
(self - ::DateTime.civil(1970)) * seconds_per_day
end
end
+
View
3  activesupport/lib/active_support/core_ext/enumerable.rb
@@ -2,7 +2,7 @@
module Enumerable
# Ruby 1.8.7 introduces group_by, but the result isn't ordered. Override it.
- remove_method(:group_by) if [].respond_to?(:group_by) && RUBY_VERSION < '1.9'
+ remove_method(:group_by) if [].respond_to?(:group_by) && Gem.ruby_version < '1.9'
# Collect an enumerable into sets, grouped by the result of a block. Useful,
# for example, for grouping records by date.
@@ -115,3 +115,4 @@ def sum(identity = 0)
(actual_last - first + 1) * (actual_last + first) / 2
end
end
+
View
3  activesupport/lib/active_support/core_ext/exception.rb
@@ -1,3 +1,4 @@
module ActiveSupport
- FrozenObjectError = RUBY_VERSION < '1.9' ? TypeError : RuntimeError
+ FrozenObjectError = Gem.ruby_version < '1.9' ? TypeError : RuntimeError
end
+
View
3  activesupport/lib/active_support/core_ext/float/rounding.rb
@@ -16,4 +16,5 @@ def round(precision = nil)
precisionless_round
end
end
-end if RUBY_VERSION < '1.9'
+end if Gem.ruby_version < '1.9'
+
View
3  activesupport/lib/active_support/core_ext/module/introspection.rb
@@ -57,7 +57,7 @@ def parents
parents
end
- if RUBY_VERSION < '1.9'
+ if Gem.ruby_version < '1.9'
# Returns the constants that have been defined locally by this object and
# not in an ancestor. This method is exact if running under Ruby 1.9. In
# previous versions it may miss some constants if their definition in some
@@ -86,3 +86,4 @@ def local_constant_names
local_constants.map { |c| c.to_s }
end
end
+
View
3  activesupport/lib/active_support/core_ext/object/instance_variables.rb
@@ -23,7 +23,7 @@ def instance_values #:nodoc:
# end
#
# C.new(0, 1).instance_variable_names # => ["@y", "@x"]
- if RUBY_VERSION >= '1.9'
+ if Gem.ruby_version >= '1.9'
def instance_variable_names
instance_variables.map { |var| var.to_s }
end
@@ -31,3 +31,4 @@ def instance_variable_names
alias_method :instance_variable_names, :instance_variables
end
end
+
View
1  activesupport/lib/active_support/core_ext/rubygems.rb
@@ -0,0 +1 @@
+require 'active_support/core_ext/rubygems/version'
View
61 activesupport/lib/active_support/core_ext/rubygems/version.rb
@@ -0,0 +1,61 @@
+module Gem
+ class Version
+ # Checks if this version is inferior than the other.
+ #
+ # Gem::Version.new("1.8.7") < "1.9.2" #=> true
+ # Gem::Version.new("1.9") < "1.8.7" #=> false
+ #
+ # <tt>Gem.ruby_version < "1.9.2"</tt> can be handy, as <tt>Gem.ruby_version</tt> returns
+ # an object of <tt>Gem::Version</tt>
+ def < other_version
+ (self <=> Version.new(other_version)) == -1
+ end
+
+ # Checks if this version is superior than the other.
+ #
+ # Gem::Version.new("1.8.7") > "1.9.2" #=> false
+ # Gem::Version.new("1.9") > "1.8.7" #=> true
+ #
+ # <tt>Gem.ruby_version > "1.9.2"</tt> can be handy, as <tt>Gem.ruby_version</tt> returns
+ # an object of <tt>Gem::Version</tt>
+ def > other_version
+ (self <=> Version.new(other_version)) == 1
+ end
+
+ # Checks if both the versions are similar.
+ #
+ # Gem::Version.new("1.9.2") == "1.9.2" #=> true
+ # Gem::Version.new("1.9") == "1.8.7" #=> false
+ #
+ # <tt>Gem.ruby_version == "1.9.2"</tt> can be handy, as <tt>Gem.ruby_version</tt> returns
+ # an object of <tt>Gem::Version</tt>
+ def == other_version
+ (self <=> Version.new(other_version)) == 0
+ end
+
+ # Checks if this version is superior or similar to the other.
+ #
+ # Gem::Version.new("1.8.7") >= "1.9.2" #=> false
+ # Gem::Version.new("1.9") >= "1.8.7" #=> true
+ # Gem::Version.new("1.9") >= "1.9" #=> true
+ #
+ # <tt>Gem.ruby_version >= "1.9.2"</tt> can be handy, as <tt>Gem.ruby_version</tt> returns
+ # an object of <tt>Gem::Version</tt>
+ def >= other_version
+ (self > other_version) || (self == other_version)
+ end
+
+ # Checks if this version is inferior or similar to the other.
+ #
+ # Gem::Version.new("1.8.7") <= "1.9.2" #=> true
+ # Gem::Version.new("1.8.7") <= "1.8.7" #=> true
+ # Gem::Version.new("1.9") <= "1.8.7" #=> false
+ #
+ # <tt>Gem.ruby_version <= "1.9.2"</tt> can be handy, as <tt>Gem.ruby_version</tt> returns
+ # an object of <tt>Gem::Version</tt>
+ def <= other_version
+ (self < other_version) || (self == other_version)
+ end
+ end
+end
+
View
4 activesupport/lib/active_support/core_ext/string/multibyte.rb
@@ -1,8 +1,9 @@
# encoding: utf-8
+require 'active_support/core_ext/rubygems'
require 'active_support/multibyte'
class String
- if RUBY_VERSION >= "1.9"
+ if Gem.ruby_version >= "1.9"
# == Multibyte proxy
#
# +mb_chars+ is a multibyte safe proxy for string methods.
@@ -70,3 +71,4 @@ def is_utf8?
end
end
end
+
View
3  activesupport/lib/active_support/core_ext/uri.rb
@@ -1,6 +1,6 @@
# encoding: utf-8
-if RUBY_VERSION >= '1.9'
+if Gem.ruby_version >= '1.9'
require 'uri'
str = "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # Ni-ho-nn-go in UTF-8, means Japanese.
@@ -28,3 +28,4 @@ def parser
end
end
end
+
View
5 activesupport/lib/active_support/multibyte/chars.rb
@@ -38,7 +38,7 @@ class Chars
alias to_s wrapped_string
alias to_str wrapped_string
- if RUBY_VERSION >= "1.9"
+ if Gem.ruby_version >= "1.9"
# Creates a new Chars instance by wrapping _string_.
def initialize(string)
@wrapped_string = string
@@ -94,7 +94,7 @@ def <=>(other)
@wrapped_string <=> other.to_s
end
- if RUBY_VERSION < "1.9"
+ if Gem.ruby_version < "1.9"
# Returns +true+ if the Chars class can and should act as a proxy for the string _string_. Returns
# +false+ otherwise.
def self.wants?(string)
@@ -475,3 +475,4 @@ def chars(string) #:nodoc:
end
end
end
+
View
4 activesupport/lib/active_support/ordered_hash.rb
@@ -4,6 +4,7 @@
end
require 'yaml'
+require 'active_support/core_ext/rubygems'
YAML.add_builtin_type("omap") do |type, val|
ActiveSupport::OrderedHash[val.map(&:to_a).map(&:first)]
@@ -48,7 +49,7 @@ def nested_under_indifferent_access
end
# Hash is ordered in Ruby 1.9!
- if RUBY_VERSION < '1.9'
+ if Gem.ruby_version < '1.9'
# In MRI the Hash class is core and written in C. In particular, methods are
# programmed with explicit C function calls and polymorphism is not honored.
@@ -215,3 +216,4 @@ def sync_keys!
end
end
end
+
View
9 activesupport/test/abstract_unit.rb
@@ -7,6 +7,8 @@
$VERBOSE = old
end
+require 'active_support/core_ext/rubygems'
+
lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
$:.unshift(lib) unless $:.include?('lib') || $:.include?(lib)
@@ -31,7 +33,7 @@
require 'active_support'
# Include shims until we get off 1.8.6
-require 'active_support/ruby/shim' if RUBY_VERSION < '1.8.7'
+require 'active_support/ruby/shim' if Gem.ruby_version < '1.8.7'
def uses_memcached(test_name)
require 'memcache'
@@ -44,7 +46,7 @@ def uses_memcached(test_name)
end
def with_kcode(code)
- if RUBY_VERSION < '1.9'
+ if Gem.ruby_version < '1.9'
begin
old_kcode, $KCODE = $KCODE, code
yield
@@ -59,6 +61,7 @@ def with_kcode(code)
# Show backtraces for deprecated behavior for quicker cleanup.
ActiveSupport::Deprecation.debug = true
-if RUBY_VERSION < '1.9'
+if Gem.ruby_version < '1.9'
$KCODE = 'UTF8'
end
+
View
3  activesupport/test/core_ext/date_ext_test.rb
@@ -374,7 +374,7 @@ def test_xmlschema_when_zone_is_set
end
end
- if RUBY_VERSION < '1.9'
+ if Gem.ruby_version < '1.9'
def test_rfc3339
assert_equal('1980-02-28', Date.new(1980, 2, 28).rfc3339)
end
@@ -461,3 +461,4 @@ def test_can_freeze_twice
end
end
end
+
View
17 activesupport/test/core_ext/hash_ext_test.rb
@@ -9,7 +9,7 @@
class HashExtTest < Test::Unit::TestCase
class IndifferentHash < HashWithIndifferentAccess
end
-
+
class SubclassingArray < Array
end
@@ -27,7 +27,7 @@ def setup
@symbols = { :a => 1, :b => 2 }
@mixed = { :a => 1, 'b' => 2 }
@fixnums = { 0 => 1, 1 => 2 }
- if RUBY_VERSION < '1.9.0'
+ if Gem.ruby_version < '1.9.0'
@illegal_symbols = { "\0" => 1, "" => 2, [] => 3 }
else
@illegal_symbols = { [] => 3 }
@@ -272,14 +272,14 @@ def test_indifferent_hash_with_array_of_hashes
hash = { "urls" => { "url" => [ { "address" => "1" }, { "address" => "2" } ] }}.with_indifferent_access
assert_equal "1", hash[:urls][:url].first[:address]
end
-
+
def test_should_preserve_array_subclass_when_value_is_array
array = SubclassingArray.new
array << { "address" => "1" }
hash = { "urls" => { "url" => array }}.with_indifferent_access
assert_equal SubclassingArray, hash[:urls][:url].class
end
-
+
def test_should_preserve_array_class_when_hash_value_is_frozen_array
array = SubclassingArray.new
array << { "address" => "1" }
@@ -906,13 +906,13 @@ def test_tag_with_attrs_and_whitespace
hash = Hash.from_xml(xml)
assert_equal "bacon is the best", hash['blog']['name']
end
-
+
def test_empty_cdata_from_xml
xml = "<data><![CDATA[]]></data>"
-
+
assert_equal "", Hash.from_xml(xml)["data"]
end
-
+
def test_xsd_like_types_from_xml
bacon_xml = <<-EOT
<bacon>
@@ -955,7 +955,7 @@ def test_type_trickles_through_when_unknown
assert_equal expected_product_hash, Hash.from_xml(product_xml)["product"]
end
-
+
def test_should_use_default_value_for_unknown_key
hash_wia = HashWithIndifferentAccess.new(3)
assert_equal 3, hash_wia[:new_key]
@@ -1103,3 +1103,4 @@ def test_expansion_count_is_limited
end
end
end
+
View
3  activesupport/test/core_ext/range_ext_test.rb
@@ -63,7 +63,7 @@ def test_original_step
assert_equal [1,3,5,7,9], array
end
- if RUBY_VERSION < '1.9'
+ if Gem.ruby_version < '1.9'
def test_cover
assert((1..3).cover?(2))
assert !(1..3).cover?(4)
@@ -75,3 +75,4 @@ def test_cover_is_not_override
end
end
end
+
View
42 activesupport/test/core_ext/rubygems_ext_test.rb
@@ -0,0 +1,42 @@
+require 'abstract_unit'
+
+class RubygemsVersionTests < Test::Unit::TestCase
+ def test_with_different_versions_for_greater_than_symbol
+ assert(Gem::Version.new('1.9') > '1.8.7')
+ assert(!(Gem::Version.new('1.8.7') > '1.9'))
+ assert(Gem::Version.new('10.9') > '9.10')
+ assert(!(Gem::Version.new('9.10') > '10.9'))
+ assert(Gem::Version.new('1.10.9') > '1.9.10')
+ assert(!(Gem::Version.new('1.9.10') > '1.10.9'))
+ end
+
+ def test_with_different_versions_for_less_than_symbol
+ assert(!(Gem::Version.new('1.9') < '1.8.7'))
+ assert(Gem::Version.new('1.8.7') < '1.9')
+ assert(!(Gem::Version.new('10.9') < '9.10'))
+ assert(Gem::Version.new('9.10') < '10.9')
+ assert(!(Gem::Version.new('1.10.9') < '1.9.10'))
+ assert(Gem::Version.new('1.9.10') < '1.10.9')
+ end
+
+ def test_with_different_versions_for_equals_to_symbol
+ assert(!(Gem::Version.new('1.9') == '1.8.7'))
+ assert(Gem::Version.new('1.8.7') == '1.8.7')
+ assert(!(Gem::Version.new('10.9') == '9.10'))
+ end
+
+
+ def test_with_different_versions_for_greater_than_equals_to_symbol
+ assert(Gem::Version.new('1.9') >= '1.9')
+ assert(!(Gem::Version.new('1.8.7') >= '1.9'))
+ assert(Gem::Version.new('10.9') >= '9.10')
+ end
+
+
+ def test_with_different_versions_for_less_than_equals_to_symbol
+ assert(Gem::Version.new('1.9') <= '1.9')
+ assert(Gem::Version.new('1.8.7') <= '1.9')
+ assert(!(Gem::Version.new('10.9') <= '9.10'))
+ end
+end
+
View
11 activesupport/test/core_ext/string_ext_test.rb
@@ -143,7 +143,7 @@ def test_ord
assert_equal 97, 'abc'.ord
end
- if RUBY_VERSION < '1.9'
+ if Gem.ruby_version < '1.9'
def test_getbyte
assert_equal 97, 'a'.getbyte(0)
assert_equal 99, 'abc'.getbyte(2)
@@ -270,7 +270,7 @@ def test_truncate_with_omission_and_seperator
assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, :omission => "[...]", :separator => ' ')
end
- if RUBY_VERSION < '1.9.0'
+ if Gem.ruby_version < '1.9.0'
def test_truncate_multibyte
with_kcode 'none' do
assert_equal "\354\225\210\353\205\225\355...", "\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224".truncate(10)
@@ -309,7 +309,7 @@ def test_string_should_recognize_utf8_strings
assert !BYTE_STRING.is_utf8?
end
- if RUBY_VERSION < '1.9'
+ if Gem.ruby_version < '1.9'
def test_mb_chars_returns_self_when_kcode_not_set
with_kcode('none') do
assert_kind_of String, UNICODE_STRING.mb_chars
@@ -354,7 +354,7 @@ def to_s
test "A fixnum is safe by default" do
assert 5.html_safe?
end
-
+
test "a float is safe by default" do
assert 5.7.html_safe?
end
@@ -450,7 +450,7 @@ def to_s
end
test 'knows whether it is encoding aware' do
- if RUBY_VERSION >= "1.9"
+ if Gem.ruby_version >= "1.9"
assert 'ruby'.encoding_aware?
else
assert !'ruby'.encoding_aware?
@@ -470,3 +470,4 @@ class StringExcludeTest < ActiveSupport::TestCase
assert_equal true, 'foo'.exclude?('p')
end
end
+
View
3  activesupport/test/core_ext/time_with_zone_test.rb
@@ -434,7 +434,7 @@ def test_instance_created_with_local_time_enforces_fall_dst_rules
end
def test_ruby_19_weekday_name_query_methods
- ruby_19_or_greater = RUBY_VERSION >= '1.9'
+ ruby_19_or_greater = Gem.ruby_version >= '1.9'
%w(sunday? monday? tuesday? wednesday? thursday? friday? saturday?).each do |name|
assert_equal ruby_19_or_greater, @twz.respond_to?(name)
end
@@ -917,3 +917,4 @@ def with_env_tz(new_tz = 'US/Eastern')
old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ')
end
end
+
View
5 activesupport/test/multibyte_chars_test.rb
@@ -102,7 +102,7 @@ class MultibyteCharsUTF8BehaviourTest < Test::Unit::TestCase
def setup
@chars = UNICODE_STRING.dup.mb_chars
- if RUBY_VERSION < '1.9'
+ if Gem.ruby_version < '1.9'
# Multibyte support all kinds of whitespace (ie. NEWLINE, SPACE, EM SPACE)
@whitespace = "\n\t#{[32, 8195].pack('U*')}"
else
@@ -150,7 +150,7 @@ def test_tidy_bytes_bang_should_change_wrapped_string
assert_not_equal original, proxy.to_s
end
- if RUBY_VERSION >= '1.9'
+ if Gem.ruby_version >= '1.9'
def test_unicode_string_should_have_utf8_encoding
assert_equal Encoding::UTF_8, UNICODE_STRING.encoding
end
@@ -701,3 +701,4 @@ class MultibyteInternalsTest < ActiveSupport::TestCase
end
end
end
+
View
3  activesupport/test/multibyte_utils_test.rb
@@ -57,7 +57,7 @@ class MultibyteUtilsTest < ActiveSupport::TestCase
end
end
- if RUBY_VERSION < '1.9'
+ if Gem.ruby_version < '1.9'
test "clean leaves ASCII strings intact" do
with_encoding('None') do
[
@@ -136,3 +136,4 @@ def with_encoding(enc)
alias with_encoding with_kcode
end
end
+
View
9 activesupport/test/ordered_hash_test.rb
@@ -81,7 +81,7 @@ def test_each_key
keys = []
assert_equal @ordered_hash, @ordered_hash.each_key { |k| keys << k }
assert_equal @keys, keys
- expected_class = RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator
+ expected_class = Gem.ruby_version < '1.9' ? Enumerable::Enumerator : Enumerator
assert_kind_of expected_class, @ordered_hash.each_key
end
@@ -89,7 +89,7 @@ def test_each_value
values = []
assert_equal @ordered_hash, @ordered_hash.each_value { |v| values << v }
assert_equal @values, values
- expected_class = RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator
+ expected_class = Gem.ruby_version < '1.9' ? Enumerable::Enumerator : Enumerator
assert_kind_of expected_class, @ordered_hash.each_value
end
@@ -97,7 +97,7 @@ def test_each
values = []
assert_equal @ordered_hash, @ordered_hash.each {|key, value| values << value}
assert_equal @values, values
- expected_class = RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator
+ expected_class = Gem.ruby_version < '1.9' ? Enumerable::Enumerator : Enumerator
assert_kind_of expected_class, @ordered_hash.each
end
@@ -115,7 +115,7 @@ def test_each_pair
assert_equal @values, values
assert_equal @keys, keys
- expected_class = RUBY_VERSION < '1.9' ? Enumerable::Enumerator : Enumerator
+ expected_class = Gem.ruby_version < '1.9' ? Enumerable::Enumerator : Enumerator
assert_kind_of expected_class, @ordered_hash.each_pair
end
@@ -330,3 +330,4 @@ def test_invert
assert_equal @values.zip(@keys), @ordered_hash.invert.to_a
end
end
+
Something went wrong with that request. Please try again.