require 'spec_helper' describe Stackster do it "create a new stack object" do config_mock = mock 'config mock' Stackster::Config.should_receive(:new).and_return config_mock Stackster::Entry.should_receive(:new).with :name => 'test-stack', :config => config_mock stack = Stackster::Stack.new :name => 'test-stack' stack.class.should == Stackster::Stack end it "create a new stack object with the given config" do config_mock = mock 'config mock' Stackster::Config.should_receive(:new).with(:config => 'test-config', :logger => 'my-logger'). and_return config_mock Stackster::Entry.should_receive(:new).with :name => 'test-stack', :config => config_mock stack = Stackster::Stack.new :name => 'test-stack', :config => 'test-config', :logger => 'my-logger' stack.class.should == Stackster::Stack end describe "mocking a stack object" do before do @config_mock = mock 'config mock' Stackster::Config.should_receive(:new).and_return @config_mock @entry_mock = mock 'entry mock' Stackster::Entry.should_receive(:new).with(:name => 'test-stack', :config => @config_mock). and_return @entry_mock @stack = Stackster::Stack.new :name => 'test-stack', :config => 'my-config', :logger => 'my-logger' end context "when creating a stack" do it "should create a new stack" do stack_creater_mock = mock 'stack creater' @entry_mock.should_receive(:set_attributes).with({ 'test-attr' => 'test-value' }) @entry_mock.should_receive(:save) Stackster::StackCreater.should_receive(:new).with(:name => 'test-stack', :entry => @entry_mock, :template_file => 'template_file', :config => @config_mock). and_return stack_creater_mock stack_creater_mock.should_receive(:create) @stack.create :template => 'template_file', :attributes => { 'test-attr' => 'test-value' } end it "should not create a stack entry if the create fails" end context "when updating a stack" do it "should should update an existing stack" do stack_updater_mock = mock 'stack updater' stack_reader_mock = mock 'stack reader' @entry_mock.should_receive(:set_attributes). with({ 'update' => 'test-attrs' }) @entry_mock.should_receive(:save) stack_reader_mock.should_receive(:template).and_return('template-body-json') Stackster::StackReader.should_receive(:new).with(:name => 'test-stack', :config => @config_mock). and_return stack_reader_mock Stackster::StackUpdater.should_receive(:new).with(:name => 'test-stack', :entry => @entry_mock, :template_body => 'template-body-json', :config => @config_mock). and_return stack_updater_mock stack_updater_mock.should_receive(:update_stack_if_parameters_changed) @stack.update :attributes => { 'update' => 'test-attrs' } end it "should not update a stack entry if the create fails" end context "when destroying a stack" do it "should destroy a stack" do stack_destroyer_mock = mock 'stack destroyer' Stackster::StackDestroyer.should_receive(:new).with(:name => 'test-stack', :config => @config_mock). and_return stack_destroyer_mock stack_destroyer_mock.should_receive(:destroy) @entry_mock.should_receive(:delete_attributes) @stack.destroy end end ['attributes', 'display', 'show', 'outputs', 'status', 'events', 'instances', 'instances_public_ip_addresses', 'instances_private_ip_addresses', 'resources', 'template'].each do |t| it "should test #{t}" end end end