# 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) flexmock(File).should_receive(:exist?).with(File.join(ENV['HOME'], '.rbenv', 'bin', 'rbenv')).and_return(true) should_execute('rbenv', 'local', '42').and_return(success_result) should_execute('which', 'ruby').and_return(success_result(File.join(ENV['HOME'], '.rbenv', 'shims', 'ruby'))) 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("git", "--version").once.and_return(success_result) should_execute("git", "clone", "git://github.com/sstephenson/rbenv.git", "#{ENV['HOME']}/.rbenv", {:abort_on_failure=>"Git clone of rbnev failed - server down?"}).once.and_return(success_result) should_execute("git", "clone", "git://github.com/sstephenson/ruby-build.git", "#{ENV['HOME']}/.rbenv/plugins/ruby-build", {:abort_on_failure=>"Git clone of ruby-build failed - server down?"}).once.and_return(success_result) 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) flexmock(FileUtils).should_receive(:cp).with(/.*\/patches\/ree-1.8.7-2012.02-rs-custom/, "#{ENV['HOME']}/.rbenv/plugins/ruby-build/share/ruby-build/ree-1.8.7-2012.02").and_return(true) flexmock(FileUtils).should_receive(:mkdir_p).with("#{ENV['HOME']}/.rbenv/plugins/ruby-build").and_return(true) flexmock(Kernel).should_receive(:system).and_return(true) should_execute('which', 'ruby').and_return(success_result(File.join(ENV['HOME'], '.rbenv', 'shims', 'ruby'))) end it 'should install rbenv and ruby-build' do should_execute('rbenv', 'local', '42').and_return(success_result) @configurator.run_linux end it 'should install ruby if needed' do flexmock(RightConf::Platform).should_receive(:dispatch).with(Proc) 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