diff --git a/CHANGELOG.md b/CHANGELOG.md index cb5a411..00ff697 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/transpec.rb b/lib/transpec.rb index 15ef531..3b2950d 100644 --- a/lib/transpec.rb +++ b/lib/transpec.rb @@ -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 diff --git a/lib/transpec/rspec_version.rb b/lib/transpec/rspec_version.rb index 875694b..6166ba9 100644 --- a/lib/transpec/rspec_version.rb +++ b/lib/transpec/rspec_version.rb @@ -3,7 +3,11 @@ require 'transpec' module Transpec - class RSpecVersion < Gem::Version + # Gem::Version caches 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 @@ -11,15 +15,33 @@ class RSpecVersion < Gem::Version # 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