diff options
author | Luke Kanies <luke@madstop.com> | 2008-07-04 15:05:29 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-07-04 15:05:29 -0500 |
commit | 31ffeabad92338d317c3193d50e8dd9a1a78977c (patch) | |
tree | bd2933bda2de1d827218cdecbb644088c1c8a4f2 /spec | |
parent | 73c06c05aec8834b6fdebac107fb289575779020 (diff) | |
download | puppet-31ffeabad92338d317c3193d50e8dd9a1a78977c.tar.gz puppet-31ffeabad92338d317c3193d50e8dd9a1a78977c.tar.xz puppet-31ffeabad92338d317c3193d50e8dd9a1a78977c.zip |
Adding tests to the Transaction::Change class.
There's a small amount of refactoring here, mostly
removing code that appears to not be used at all.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/unit/transaction/change.rb | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/spec/unit/transaction/change.rb b/spec/unit/transaction/change.rb new file mode 100755 index 000000000..bb9915bda --- /dev/null +++ b/spec/unit/transaction/change.rb @@ -0,0 +1,156 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/transaction/change' + +describe Puppet::Transaction::Change do + Change = Puppet::Transaction::Change + + describe "when initializing" do + before do + @property = stub 'property', :path => "/property/path", :should => "shouldval" + end + + it "should require the property and current value" do + lambda { Change.new() }.should raise_error + end + + it "should set its property to the provided property" do + Change.new(@property, "value").property.should == :property + end + + it "should set its 'is' value to the provided value" do + Change.new(@property, "value").is.should == "value" + end + + it "should retrieve the 'should' value from the property" do + # Yay rspec :) + Change.new(@property, "value").should.should == @property.should + end + + it "should set its path to the path of the property plus 'change'" do + Change.new(@property, "value").path.should == [@property.path, "change"] + end + end + + describe "when an instance" do + before do + @property = stub 'property', :path => "/property/path", :should => "shouldval" + @change = Change.new(@property, "value") + end + + it "should be noop if the property is noop" do + @property.expects(:noop).returns true + @change.noop?.should be_true + end + + it "should set its resource to the proxy if it has one" do + @change.proxy = :myresource + @change.resource.should == :myresource + end + + it "should set its resource to the property's resource if no proxy is set" do + @property.expects(:resource).returns :myresource + @change.resource.should == :myresource + end + + it "should have a method for marking that it's been execution" do + @change.changed = true + @change.changed?.should be_true + end + + describe "and creating an event" do + before do + @property.stubs(:resource).returns "myresource" + end + + it "should produce a warning if the event name is not a symbol" do + @property.expects(:warning) + @property.stubs(:event).returns :myevent + @change.event("a string") + end + + it "should use the property to generate the event name if the provided name is not a symbol" do + @property.stubs(:warning) + @property.expects(:event).with(@change.should).returns :myevent + + Puppet::Transaction::Event.expects(:new).with { |args| args[:event] == :myevent } + + @change.event("a string") + end + end + + describe "and executing" do + before do + @transaction = mock 'transaction' + @change.stubs(:transaction).returns @transaction + end + + describe "in noop mode" do + before { @change.stubs(:noop?).returns true } + + it "should log that it is in noop" do + @property.expects(:is_to_s) + @property.expects(:should_to_s) + @property.expects(:log) + + @change.stubs :event + @change.forward + end + + it "should produce a :noop event and return" do + @property.stub_everything + + @change.expects(:event).with(:noop).returns :noop_event + + @change.forward.should == [:noop_event] + end + end + + describe "without noop" do + before do + @change.stubs(:noop?).returns false + @property.stub_everything + @property.stubs(:resource).returns "myresource" + end + + it "should sync the property" do + @property.expects(:sync) + + @change.forward + end + + it "should return nil if syncing the property returns nil" do + @property.stubs(:sync).returns nil + + @change.forward.should be_nil + end + + it "should return nil if syncing the property returns an empty array" do + @property.stubs(:sync).returns [] + + @change.forward.should be_nil + end + + it "should log the change" do + @property.expects(:sync).returns [:one] + + @property.expects(:log) + @property.expects(:change_to_s) + + @change.forward + end + + it "should return an array of events" do + @property.expects(:sync).returns [:one, :two] + + @change.expects(:event).with(:one).returns :uno + @change.expects(:event).with(:two).returns :dos + + @change.forward.should == [:uno, :dos] + end + end + end + end +end |