require 'spec_helper' require 'json' describe Stackster do before do @template_body = '{ "Parameters": { "param1" : { "Description" : "param-1" }, "param2" : { "Description" : "param-2" } } }' end it "should update the stack when parameters change" do attributes = { "param1" => "value1", "param3" => "value3" } config_mock = mock 'config mock' logger_mock = mock 'logger mock' entry_mock = mock 'entry mock' cloud_formation_mock = mock 'cloud formation mock' Stackster::AWS::CloudFormation.should_receive(:new). with(:config => config_mock). and_return cloud_formation_mock entry_mock.should_receive(:attributes).and_return attributes cloud_formation_mock.should_receive(:update). with(:name => 'test-stack', :parameters => { 'param1' => 'value1' }, :template => @template_body). and_return true config_mock.should_receive(:logger).and_return(logger_mock) logger_mock.should_receive(:info).exactly(2).times stack_updater = Stackster::StackUpdater.new :name => 'test-stack', :template_body => @template_body, :entry => entry_mock, :config => config_mock stack_updater.update_stack_if_parameters_changed( [ { 'param1' => 'new-value' } ] ). should == true end it "should not update the stack when parameters don't change" do attributes = { "param3" => "value3" } config_mock = mock 'config mock' logger_mock = mock 'logger mock' entry_mock = mock 'entry mock' Stackster::AWS::CloudFormation.should_receive(:new).exactly(0).times config_mock.should_receive(:logger).and_return(logger_mock) logger_mock.should_receive(:info).with("No Cloud Formation parameters require updating.") stack_updater = Stackster::StackUpdater.new :name => 'test-stack', :template_body => @template_body, :entry => entry_mock, :config => config_mock stack_updater.update_stack_if_parameters_changed( [ { 'another-param' => 'new-value' } ] ). should == false end end