Skip to content

Commit

Permalink
Avoid inheriting Gem::Version in RSpecVersion
Browse files Browse the repository at this point in the history
Gem::Version caches its instances with class variable @@ALL.

Related to #17.
  • Loading branch information
yujinakayama committed Nov 11, 2013
1 parent a534ee6 commit f7a3e52
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Fix error `singleton can't be dumped (TypeError)` at the end of dynamic analysis ([#17](https://github.com/yujinakayama/transpec/issues/17))
* Do not copy pseudo files (device, socket, etc.) in dynamic analysis ([#17](https://github.com/yujinakayama/transpec/issues/17))
* Fix error `undefined method receive_messages_available?` while conversion ([#17](https://github.com/yujinakayama/transpec/issues/17))

## v1.2.1

Expand Down
2 changes: 1 addition & 1 deletion lib/transpec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.required_rspec_version
if rspec_dependency
rspec_requirement = rspec_dependency.requirement
gem_version = rspec_requirement.requirements.first.find { |r| r.is_a?(Gem::Version) }
RSpecVersion.new(gem_version.to_s)
RSpecVersion.new(gem_version)
else
# Using development version of RSpec with Bundler.
current_rspec_version
Expand Down
32 changes: 27 additions & 5 deletions lib/transpec/rspec_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,45 @@
require 'transpec'

module Transpec
class RSpecVersion < Gem::Version
# Gem::Version caches its instances with class variable @@all,
# so we should not inherit it.
class RSpecVersion
include Comparable

# http://www.ruby-doc.org/stdlib-2.0.0/libdoc/rubygems/rdoc/Gem/Version.html
#
# If any part contains letters (currently only a-z are supported) then that version is
# considered prerelease.
# Prerelease parts are sorted alphabetically using the normal Ruby string sorting rules.
# If a prerelease part contains both letters and numbers, it will be broken into multiple parts
# to provide expected sort behavior (1.0.a10 becomes 1.0.a.10, and is greater than 1.0.a9).
VERSION_2_99 = new('2.99.aaaaaaaaaa')
VERSION_3_0 = new('3.0.aaaaaaaaaa')
GEM_VERSION_2_99 = Gem::Version.new('2.99.aaaaaaaaaa')
GEM_VERSION_3_0 = Gem::Version.new('3.0.aaaaaaaaaa')

attr_reader :gem_version

def initialize(version)
@gem_version = if version.is_a?(Gem::Version)
version
else
Gem::Version.new(version)
end
end

def be_truthy_available?
self >= VERSION_2_99
@gem_version >= GEM_VERSION_2_99
end

def receive_messages_available?
self >= VERSION_3_0
@gem_version >= GEM_VERSION_3_0
end

def <=>(other)
@gem_version <=> other.gem_version
end

def to_s
@gem_version.to_s
end
end
end

0 comments on commit f7a3e52

Please sign in to comment.