spec/configurators/ruby_configurator_spec.rb in rconf-0.10.1 vs spec/configurators/ruby_configurator_spec.rb in rconf-1.0.0

- old
+ new

@@ -11,97 +11,67 @@ 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") - flexmock(File).should_receive(:open).with('.rvmrc', 'w').and_yield(FlexMock.undefined) # Don't override rconf's .rvmrc... + def failure_result(output=nil) + flexmock('res', :success? => false, :output => output) 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', 'current').once.and_return(success_result("0@")) - should_execute('rvm', '0@', 'exec', '--', 'gem', '--version').once.and_return(success_result('1')) - @configurator.run_linux + before(:each) do + @configurator = create_configurator('ruby { version "42" }') 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('curl', '-O', '-f', "https://rvm.io/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').never - @configurator.run_linux + it 'should abort if rvm is present' do + should_execute('rvm').once.and_return(success_result) + expect { @configurator.run_linux }.to raise_error end - it 'should install rubygems if needed' do - should_execute('rvm', '--version').once.and_return(success_result("rvm #{RVM_VERSION}")) - should_execute('rvm', 'current').once.and_return(success_result("0@")) - should_execute('rvm', '0@', 'exec', '--', '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 + context "with rbenv installed" do + before(:each) do + should_execute('rvm').once.and_return(failure_result) + flexmock(File).should_receive(:exist?).with('.ruby-version').and_return(true) + flexmock(IO).should_receive(:read).with('.ruby-version').and_return("42") + end -describe 'bashrc update' do + it 'should succeed' do + should_execute('rbenv').once.and_return(success_result('rbenv 0.4.0')) + @configurator.run_linux + end - 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 check rbenv version' do + should_execute('rbenv').once.and_return(success_result('rbenv 0.3.0')) + expect { @configurator.run_linux }.to raise_error + 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 + 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('.ruby-version').and_return(false) + flexmock(File).should_receive(:exist?).with(File.join(ENV['HOME'], '.rbenv', 'bin', 'rbenv')).and_return(false) + 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 + 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 -