Permalink
Browse files

[FIX] Ensure we used the merged commands sequence. Spec to validate.

  • Loading branch information...
1 parent 5be3464 commit 2cb873f53eee33b9078944a162558452466969ac @crafterm committed Sep 9, 2011
Showing with 49 additions and 27 deletions.
  1. +2 −2 lib/sprinkle/installers/transfer.rb
  2. +47 −25 spec/sprinkle/installers/transfer_spec.rb
@@ -135,7 +135,7 @@ def process(roles) #:nodoc:
unless pre.empty?
sequence = pre; sequence = sequence.join('; ') if sequence.is_a? Array
logger.info "#{@package.name} pre-transfer commands: #{sequence} for roles: #{roles}\n"
- @delivery.process @package.name, [pre].flatten, roles
+ @delivery.process @package.name, sequence, roles
end
recursive = @options[:recursive]
@@ -169,7 +169,7 @@ def process(roles) #:nodoc:
unless post.empty?
sequence = post; sequence = sequence.join('; ') if sequence.is_a? Array
logger.info "#{@package.name} post-transfer commands: #{sequence} for roles: #{roles}\n"
- @delivery.process @package.name, [post].flatten, roles
+ @delivery.process @package.name, sequence, roles
end
end
end
@@ -17,41 +17,63 @@
installer do; prefix '/usr/bin'; end
end
end
-
+
def create_transfer(source, dest, options={}, &block)
i = Sprinkle::Installers::Transfer.new(@package, source, dest, options, &block)
i.delivery = @delivery
i
end
-
+
describe 'when created' do
it 'should accept a source and destination to install' do
@installer.source.should == @source
@installer.destination.should == @destination
end
end
-
+
describe 'during installation' do
- before do
- @installer = create_transfer @source, @destination do
- pre :install, 'op1'
- post :install, 'op2'
+
+ context 'single pre/post commands' do
+ before do
+ @installer = create_transfer @source, @destination do
+ pre :install, 'op1'
+ post :install, 'op2'
+ end
+
+ @delivery = @installer.delivery
+ end
+
+ it "should call the pre and post install commands around the file transfer" do
+ @delivery.should_receive(:process).with(@package.name, 'op1', @roles).and_return
+ @delivery.should_receive(:transfer).and_return
+ @delivery.should_receive(:process).with(@package.name, 'op2', @roles).and_return
+ end
+
+ it "should call transfer with recursive defaulted to nil" do
+ @delivery.should_receive(:process).and_return
+ @delivery.should_receive(:transfer).with(@package.name, @source, @destination, @roles, nil)
+ end
+
+ end
+
+ context 'multiple pre/post commands' do
+ before do
+ @installer = create_transfer @source, @destination do
+ pre :install, 'op1', 'op1-1'
+ post :install, 'op2', 'op2-1'
+ end
+
+ @delivery = @installer.delivery
+ end
+
+ it "should call the pre and post install commands around the file transfer" do
+ @delivery.should_receive(:process).with(@package.name, 'op1; op1-1', @roles).and_return
+ @delivery.should_receive(:transfer).and_return
+ @delivery.should_receive(:process).with(@package.name, 'op2; op2-1', @roles).and_return
end
- @delivery = @installer.delivery
end
- it "should call the pre and post install commands around the file transfer" do
- @delivery.should_receive(:process).with(@package.name, ['op1'], @roles).once.ordered.and_return
- @delivery.should_receive(:transfer).ordered.and_return
- @delivery.should_receive(:process).with(@package.name, ['op2'], @roles).once.ordered.and_return
- end
-
- it "should call transfer with recursive defaulted to nil" do
- @delivery.should_receive(:process).and_return
- @delivery.should_receive(:transfer).with(@package.name, @source, @destination, @roles, nil)
- end
-
after do
@installer.process @roles
end
@@ -65,22 +87,22 @@ def create_transfer(source, dest, options={}, &block)
end
it "should render the source file as a template to a tempfile" do
- @tempfile = Tempfile.new("foo")
+ @tempfile = Tempfile.new("foo")
@installer.should_receive(:render_template_file).with(@source, anything, @package.name).and_return(@tempfile)
@delivery.stub!(:transfer)
end
-
+
it "should call transfer with recursive set to false" do
- @tempfile = Tempfile.new("foo")
+ @tempfile = Tempfile.new("foo")
@installer.should_receive(:render_template_file).with(@source, anything, @package.name).and_return(@tempfile)
@delivery.should_receive(:transfer).with(@package.name, @tempfile.path, @destination, @roles, false).ordered.and_return
end
-
+
after do
@installer.process @roles
end
end
-
+
describe "if the :recursive flag is explicitly set to false" do
before do
@installer = create_transfer @source, @destination, :recursive => false
@@ -90,7 +112,7 @@ def create_transfer(source, dest, options={}, &block)
delivery = @installer.delivery
delivery.should_receive(:transfer).with(@package.name, @source, @destination, @roles, false).ordered.and_return
end
-
+
after do
@installer.process @roles
end

0 comments on commit 2cb873f

Please sign in to comment.