# 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 File.join(File.dirname(__FILE__), 'spec_helper') describe RightConf::Configurator do class TestConfigurator include RightConf::Configurator register :test validate_has_settings :required attr_reader :custom_setting def test_setter(value) @custom_setting = value end def check_darwin; end alias :check_linux :check_darwin alias :check_windows :check_darwin def run_darwin; end alias :run_linux :run_darwin alias :run_windows :run_darwin end class AnotherConfigurator include RightConf::Configurator register :another end before(:each) do @configurator = TestConfigurator.new(1) end it 'should register configurators' do RightConf::ConfiguratorRegistry[:test].should == TestConfigurator RightConf::ConfiguratorRegistry[:another].should == AnotherConfigurator end it 'should have associated key' do TestConfigurator.key.should == :test AnotherConfigurator.key.should == :another end it 'should initialize configuration using meta-programming' do @configurator.instance_eval { test_setting 42 } @configurator[:test_setting].should == 42 end it 'should use configurator setter if it exists' do @configurator.instance_eval { test_setter 43 } @configurator.custom_setting.should == 43 end it 'should check' do flexmock(@configurator).should_receive(:check).and_return(true).once flexmock(RightConf::Platform.instance).should_receive(:dispatch).never @configurator.run end it 'should validate' do @configurator.validate.should =~ /^Required setting.*missing for configuration/ @configurator.instance_eval { required 42 } @configurator.validate.should be_nil end it 'should persist the signature of configurators that ran' do flexmock(RightConf::Profile.instance).should_receive(:set_configurator_signature).once @configurator.run end it 'should skip configurators that have already run' do flexmock(RightConf::Profile.instance).should_receive(:configurator_signature).with('test-1').and_return('42') flexmock(@configurator).should_receive(:signature).and_return('42') flexmock(RightConf::Platform.instance).should_receive(:dispatch).never @configurator.run end end