require File.expand_path(File.dirname(__FILE__) + '/spec_helper') require 'dionysus/version_string' describe Dionysus::VersionString do before(:each) do @version_string = Dionysus::VersionString.new('1.5.7') end it 'should be frozen' do @version_string.should be_frozen end it 'should have to_rubygem_version' do @version_string.to_rubygem_version.should be_a(Gem::Version) gem_version = @version_string.to_gem_version @version_string.to_rubygem_version.should eq(gem_version) end it 'should have prerelease? that delegates to Gem::Version' do @version_string.should_not be_prerelease version = Dionysus::VersionString.new('1.5.alpha') version.should be_prerelease end it 'should have eql?' do (@version_string.eql?('1.5.7')).should be_true end describe 'comparable' do before(:all) do @values = {'1.5.7' => 0, '1.5' => 1, '1.6' => -1} end it 'should work with VersionStrings' do @values.each do |ver, c| (@version_string <=> Dionysus::VersionString.new(ver)).should == c end end it 'should work with Strings' do @values.each do |ver, c| (@version_string <=> ver).should == c end end it 'should work with Gem::Versions' do @values.each do |ver, c| (@version_string <=> Gem::Version.new(ver.dup)) == c end end it 'should not work with anything else' do lambda { @version_string <=> Object.new }.should raise_error(ArgumentError, "Can only compare to a Dionysus::VersionString/String or Gem::Version") end end describe 'satisfies?' do before(:all) do @values = {'~> 1.5.0' => true, '~> 2' => false} end it 'should work with Strings' do @values.each do |req, v| @version_string.satisfies?(req).should == v end end it 'should work with Gem::Requirements' do @values.each do |req, v| @version_string.satisfies?(Gem::Requirement.new(req)).should == v end end it 'should not work with anything else' do lambda { @version_string.satisfies?(Object.new) }.should raise_error(ArgumentError, "Can only compare to a String or Gem::Requirement") end end end