spec/configurators/ruby_configurator_spec.rb in rconf-0.6.10 vs spec/configurators/ruby_configurator_spec.rb in rconf-0.6.11

- old
+ new

@@ -53,11 +53,60 @@ 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