# 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 'rubygems' require 'rspec' require "flexmock" require File.join(File.dirname(__FILE__), '..', 'lib', 'rconf') RSpec.configure do |c| c.mock_with(:flexmock) end # Create configurator for testing and setup common mocks # # === Parameters # code(String):: Code using rconf language syntax used to initialize configurator # opts[:enable_updater](TrueClass|FalseClass):: Don't mock out environment updater if set # # === Return # configurator(RightConf::Configurator):: Created configurator def create_configurator(code, opts={}) lang = RightConf::Language.parse(code) configurator = lang.configurators.first [:report_check, :report_error, :report_result, :report_success].each do |meth| flexmock(configurator).should_receive(meth) end flexmock(configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') } flexmock(File).should_receive(:exist?).with(File.join(ENV['HOME'], '.rconf')).and_return(false) flexmock(RightConf::EnvironmentUpdater).should_receive(:update) unless opts[:enable_updater] configurator end # Helper method to mock Command.execute # # === Parameters # Parameters are passed through to flexmock 'with' method # # === Return # mock(Flexmock):: Corresponding flexmock instance def should_execute(*with) mock = flexmock(RightConf::Command.instance).should_receive(:execute).with(*with) end # Helper method to mock Command.execute_in_ruby # # === Parameters # Parameters are passed through to flexmock 'with' method # # === Return # mock(Flexmock):: Corresponding flexmock instance def should_execute_in_ruby(*with) mock = flexmock(RightConf::Command.instance).should_receive(:execute_in_ruby).with(*with) end # Helper method to mock Command.sudo # # === Parameters # Parameters are passed through to flexmock 'with' method # # === Return # mock(Flexmock):: Corresponding flexmock instance def should_sudo(*with) mock = flexmock(RightConf::Command.instance).should_receive(:sudo).with(*with) end