spec/task_spec.rb in screwcap-0.2 vs spec/task_spec.rb in screwcap-0.3
- old
+ new
@@ -2,20 +2,19 @@
describe "Tasks" do
before(:each) do
@stdout = []
@stderr = []
- Task.any_instance.stubs(:log).with() { |msg| @stdout << msg }
- Task.any_instance.stubs(:errorlog).with() { |msg| @stderr << msg }
- Deployer.any_instance.stubs(:log).with() { |msg| @stdout << msg }
- Deployer.any_instance.stubs(:errorlog).with() { |msg| @stderr << msg }
- @deployer = Deployer.new(:recipe_file => "./test/config/simple_recipe.rb", :silent => false)
+ Runner.stubs(:log).with() { |msg,opts| @stdout << msg }
+ Runner.stubs(:errorlog).with() { |msg,opts| @stderr << msg }
+ @deployer = Deployer.new(:recipe_file => "./test/config/simple_recipe.rb", :silent => true)
end
before(:all) do
Net::SSH.stubs(:start).yields(SSHObject.new(:return_stream => :stdout, :return_data => "hostname = asdf\n"))
Net::SCP.stubs(:upload!).returns(nil)
+ Runner.stubs(:ssh_exec!).returns(["ok","",0,nil])
end
it "should be able to create variables" do
task = @deployer.__tasks.find {|t| t.name == :task1 }
task.bango.should == "bongo"
@@ -26,13 +25,13 @@
task.should have(6).__commands
end
it "should be able to execute statements on a remote server" do
task = @deployer.__tasks.find {|t| t.name == :task1 }
- task.execute!
+ Runner.execute! task, @deployer.__options
@stderr.should == []
- @stdout.size.should == 29
+ @stdout.size.should == 26
end
it "should be able to use variables in the run statement" do
task = @deployer.__tasks.find {|t| t.name == :task1 }
command = task.__commands.map{|c| c[:command] }.find {|c| c.index "deploy dir" }
@@ -50,15 +49,15 @@
task.deploy_var_2.should == "purple"
task.deploy_var_3.should == "mountain dew"
end
it "should complain if you do not pass the task a server argument" do
- lambda { Deployer.new(:recipe_file => "./test/config/no_server.rb", :silent => false)}.should raise_error(Screwcap::ConfigurationError)
+ lambda { Deployer.new(:recipe_file => "./test/config/no_server.rb", :silent => true)}.should raise_error(Screwcap::ConfigurationError)
end
it "should complain if you pass a server that is not defined" do
- lambda { Deployer.new(:recipe_file => "./test/config/undefined_server.rb", :silent => false)}.should raise_error(Screwcap::ConfigurationError)
+ lambda { Deployer.new(:recipe_file => "./test/config/undefined_server.rb", :silent => true)}.should raise_error(Screwcap::ConfigurationError)
end
it "should be able to disable parallel running" do
# this is hard to test. with threads and stuff
lambda { @deployer.run! :non_parallel }.should_not raise_error
@@ -69,7 +68,15 @@
end
it "should be able to upload files using the scp command" do
deployer = Deployer.new(:recipe_file => "./test/config/upload.rb", :silent => true)
deployer.run! :upload
+ end
+
+ it "should respond to onfailure" do
+ deployer = Deployer.new(:recipe_file => "./test/config/expect.rb", :silent => true)
+ t = deployer.__tasks.find {|t| t.__name == :expect }
+ Runner.stubs(:ssh_exec!).returns(["","fail",1,nil]).then.returns(["ok","",0,nil])
+ Runner.execute! t, deployer.__options
+ t.__commands.map {|c| [c[:command], c[:from]] }.first.should == ["echo 'we failed'", :failover]
end
end