# 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 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 #{RightConf::RubyConfigurator::RVM_VERSION}")) flexmock(RightConf::Command.instance).should_receive(:execute).once.with( 'rvm', 'list').and_return(success_result("=> rvm #{RightConf::RubyConfigurator::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-#{RightConf::RubyConfigurator::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 #{RightConf::RubyConfigurator::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 #{RightConf::RubyConfigurator::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 /Users/raphael/src/right_env/rvm-1.2.6.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 #{RightConf::RubyConfigurator::RVM_VERSION}"}).and_return(success_result) flexmock(RightConf::Command.instance).should_receive(:execute).once.with( 'rvm', 'use', '0').and_return(success_result('Using')) @configurator.run_linux end end