# Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide. # # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use, # reproduction, modification, or disclosure of this program is # strictly prohibited. Any use of this program by an authorized # licensee is strictly subject to the terms and conditions, # including confidentiality obligations, set forth in the applicable # License Agreement between RightScale.com, Inc. and # the licensee require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper')) describe RightConf::RubyConfigurator do RVM_VERSION = RightConf::RubyConfigurator::RVM_VERSION def success_result(output=nil) flexmock('res', :success? => true, :output => output) end before(:each) do @configurator = create_configurator('ruby { version "0"; rubygems "1" }') flexmock(File).should_receive(:exist?).with('.rvmrc').and_return(true) flexmock(IO).should_receive(:read).with('.rvmrc').and_return("anything") end it 'should succeed on linux when rvm succeeds' do should_execute('rvm', '--version').once.and_return(success_result("rvm #{RVM_VERSION}")) should_execute('rvm', 'list').once.and_return(success_result("=> rvm #{RVM_VERSION}")) should_execute('rvm', 'use', '0').once.and_return(success_result('Using ')) should_execute('rvm', '0@', 'gem', '--version').once.and_return(success_result('1')) @configurator.run_linux end it 'should install rvm if needed' do rvm_tar = "rvm-#{RVM_VERSION}.tar.gz" should_execute('rvm', '--version').once.and_return(success_result("rvm")) should_execute('rvm', 'list').once.and_return(success_result("=> rvm #{RVM_VERSION}")) should_execute('curl', '-O', '-f', "https://rvm.beginrescueend.com/releases/#{rvm_tar}", {:abort_on_failure=>"Failed to download rvm #{RVM_VERSION}"}).once.and_return(success_result) should_execute('tar', 'zxf', rvm_tar, {:abort_on_failure=>"Failed to extract rvm tgz from #{File.expand_path(File.join(File.dirname(__FILE__), '..', '..', "rvm-#{RVM_VERSION}.tar.gz"))}"}).once.and_return(success_result) flexmock(Dir).should_receive(:chdir).and_yield should_execute('./install', {:abort_on_failure=>"Failed to install rvm #{RVM_VERSION}"}).once.and_return(success_result) should_execute('rvm', 'use', '0').once.and_return(success_result('Using ')) should_execute('rvm', '0@', 'gem', '--version').once.and_return(success_result('1')) flexmock(@configurator).should_receive(:setup_bashrc).once.and_return(true) @configurator.run_linux end it 'should install rubygems if needed' do should_execute('rvm', '--version').once.and_return(success_result("rvm #{RVM_VERSION}")) should_execute('rvm', 'list').once.and_return(success_result("=> rvm #{RVM_VERSION}")) should_execute('rvm', 'use', '0').once.and_return(success_result('Using ')) should_execute('rvm', '0@', 'gem', '--version').once.and_return(success_result('0')) should_execute('rvm', '0@', 'rubygems', '1', {:abort_on_failure=>'Failed to install rubygems'}).once.and_return(success_result) @configurator.run_linux end end describe 'bashrc update' do before(:each) do flexmock(File).should_receive(:exist?).with(File.join(ENV['HOME'], '.bash_profile')).once.and_return(true) flexmock(File).should_receive(:exist?).with('.rvmrc').and_return(true) flexmock(FileUtils).should_receive(:mv).and_return(true) f = flexmock('f') f.should_receive(:puts).and_return { |c| @bashrc_content = c } flexmock(File).should_receive(:open).and_yield(f) @configurator = create_configurator('ruby { version "0"; rubygems "1" }', :enable_updater => true) @rvm_bash_activation = @configurator.__send__(:rvm_bash_activation) end it 'should install rvm hook in bashrc when not present' do flexmock(IO).should_receive(:read).and_return('test') @configurator.__send__(:setup_bashrc) @bashrc_content.should == "#{@rvm_bash_activation}\ntest" end it 'should not install rvm hook in bashrc when present' do flexmock(IO).should_receive(:read).and_return('test' + @rvm_bash_activation) @configurator.__send__(:setup_bashrc) @bashrc_content.should be_nil end it 'should install rvm hook after path is set' do flexmock(IO).should_receive(:read).and_return(<<-EOS echo 'zobi la mouche' radio killed the radio star #PATH=something:should be fine this should not: PATH=something AFTER EOS ) @configurator.__send__(:setup_bashrc) @bashrc_content.should == <<-EOS echo 'zobi la mouche' radio killed the radio star #PATH=something:should be fine this should not: PATH=something #{@rvm_bash_activation} AFTER EOS end end