# 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 lang = RightConf::Language.parse('ruby { version "0"; rubygems "1" }') @configurator = lang.configurators.first [:report_check, :report_result, :report_fatal, :report_success, :report].each do |meth| flexmock(@configurator).should_receive(meth) end end it 'should succeed on linux when rvm succeeds' do flexmock(RightConf::Command.instance).should_receive(:execute).once.with( 'rvm', '--version').and_return(success_result("rvm #{RVM_VERSION}")) flexmock(RightConf::Command.instance).should_receive(:execute).once.with( 'rvm', 'list').and_return(success_result("=> rvm #{RVM_VERSION}")) flexmock(RightConf::Command.instance).should_receive(:execute).once.with( 'rvm', 'use', '0').and_return(success_result('Using')) @configurator.run_linux end it 'should install rvm if needed' do rvm_tar = "rvm-#{RVM_VERSION}.tar.gz" flexmock(RightConf::Command.instance).should_receive(:execute).once.with( 'rvm', '--version').and_return(success_result("rvm")) flexmock(RightConf::Command.instance).should_receive(:execute).once.with( 'rvm', 'list').and_return(success_result("=> rvm #{RVM_VERSION}")) flexmock(RightConf::Command.instance).should_receive(:execute).once.with( 'curl', '-O', '-f', "http://rvm.beginrescueend.com/releases/#{rvm_tar}", {:abort_on_failure=>"Failed to download rvm #{RVM_VERSION}"}).and_return(success_result) flexmock(RightConf::Command.instance).should_receive(:execute).once.with( '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"))}"}).and_return(success_result) flexmock(Dir).should_receive(:chdir).and_yield flexmock(RightConf::Command.instance).should_receive(:execute).once.with( './install', {:abort_on_failure=>"Failed to install rvm #{RVM_VERSION}"}).and_return(success_result) flexmock(RightConf::Command.instance).should_receive(:execute).once.with( 'rvm', 'use', '0').and_return(success_result('Using')) flexmock(@configurator).should_receive(:setup_bashrc).once.and_return(true) @configurator.run_linux end describe 'bashrc update' do before(:each) do flexmock(File).should_receive(:exist?).once.with(File.join(ENV['HOME'], '.bashrc')).once.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) @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 PATH=$PATH: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 PATH=$PATH:should be fine this should not: PATH=something #{@rvm_bash_activation} AFTER EOS end end end