require 'spec_helper' describe 'RubyVersionReader' do before :all do @remember_version = RUBY_VERSION capture_stderr{ RUBY_VERSION = '1.8.7' } end it 'should display RUBY_VERSION if called directly (to_s)' do RubyVersionReader.to_s.should == '1.8.7' end context 'with "is" method, with parameter' do it 'should check for main version (1.8 or 1.9) when Float paramater is given' do RubyVersionReader.is?( 1.8 ).should == true RubyVersionReader.is?( 1.9 ).should == false end it 'should check with string comparison if parameter is not Float' do RubyVersionReader.is?( '1.8' ).should == false end end context 'with "is" method, without parameter, but method chaining' do it 'should return a string for usage with comparison operators' do (RubyVersionReader.is > '1.8.7').should == false (RubyVersionReader <= '1.8.7').should == true (RubyVersionReader.is.between? '1.8.6', '1.8.7').should == true end it 'should create some handy compare aliases' do RubyVersionReader.is.above( '1.8.7' ).should == false RubyVersionReader.is.at_least( '1.8.7' ).should == true RubyVersionReader.is.exactly( '1.8.7' ).should == true end it 'also allows to check for the release dates' do RubyVersionReader.is.older_than( Date.today ).should == true RubyVersionReader.is.newer_than( '2000-01-01' ).should == true end end it 'should define some accessors' do RubyVersionReader.major.should == 1 RubyVersionReader.minor.should == 8 RubyVersionReader.tiny.should == 7 RubyVersionReader.patchlevel.should == RUBY_PATCHLEVEL RubyVersionReader.description.should == RUBY_DESCRIPTION end context 'with "gemset" method' do it 'should return an empty string by default' do RubyVersionReader.gemset.should == '' end it 'should work with a .ruby-gemset file' do path = '.ruby-gemset' given_gemset_name = 'ruby_version_rspec_gemset' begin # Given File.open(path, 'w') { |file| file << given_gemset_name + "\n\n" } # When/Then RubyVersionReader.gemset.should == given_gemset_name ensure File.delete(path) end end it 'should work by calling `rvm info`' do given_gemset_name = 'ruby_version_rspec_gemset' Object.should_receive(:`) { YAML.dump({ 'ruby-version@ruby-gemset' => { 'environment' => { 'gemset' => given_gemset_name } } }) } puts RubyVersionReader.gemset#.should == given_gemset_name end end after :all do capture_stderr{ RUBY_VERSION = @remember_version } end end