# Copyright (C) 2011-2012 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 def failure_result(output=nil) flexmock('res', :success? => false, :output => output) end before(:each) do @configurator = create_configurator('ruby { version "42" }') end it 'should abort if rvm is present' do should_execute('rvm').once.and_return(success_result) expect { @configurator.run_linux }.to raise_error end context "with rbenv installed" do before(:each) do should_execute('rvm').once.and_return(failure_result) should_execute('rbenv', 'local', '42').and_return(success_result) end it 'should succeed' do should_execute('rbenv').once.and_return(success_result('rbenv 0.4.0')) @configurator.run_linux end it 'should check rbenv version' do should_execute('rbenv').once.and_return(success_result('rbenv 0.3.0')) expect { @configurator.run_linux }.to raise_error end end context "without rbenv installed" do before(:each) do should_execute('rvm').once.and_return(failure_result) should_execute('rbenv').once.and_return(failure_result) flexmock(File).should_receive(:exist?).with(File.join(ENV['HOME'], '.rbenv', 'bin', 'rbenv')).and_return(false) end it 'should install rbenv and ruby-build' do flexmock(RightConf::PackageInstaller).should_receive(:install).with('rbenv', Hash).once flexmock(RightConf::PackageInstaller).should_receive(:install).with('ruby-build', Hash, Proc).once should_execute('rbenv', 'local', '42').and_return(success_result) @configurator.run_linux end it 'should install ruby if needed' do flexmock(RightConf::PackageInstaller).should_receive(:install).with('rbenv', Hash).once flexmock(RightConf::PackageInstaller).should_receive(:install).with('ruby-build', Hash, Proc).once should_execute('rbenv', 'local', '42').and_return(failure_result) flexmock(RightConf::Platform).should_receive(:dispatch).with('42', Proc) should_execute('rbenv', 'local', '42').and_return(success_result) @configurator.run_linux end end end