README.rdoc in capistrano-spec-0.2.2 vs README.rdoc in capistrano-spec-0.3.0
- old
+ new
@@ -71,22 +71,22 @@
describe Capistrano::Speak, "loaded into a configuration" do
before do
@configuration = Capistrano::Configuration.new
Capistrano::Speak.load_into(@configuration)
end
-
+
end
Now you have access to a configuration, so you can start poking around the +@configuration+ object as you see fit.
Now, remember, if you +set+ values, you can access them using +fetch+:
before do
@configuration.set :foo, 'bar'
end
-
+
it "should define foo" do
@configuration.fetch(:foo).should == 'bar'
end
You can also find and execute tasks, so you can verify if you successfully set a value:
@@ -94,11 +94,11 @@
describe 'speak task' do
before do
@configuration.find_and_execute_task('speak')
end
-
+
it "should define message" do
@configuration.fetch(:message).should == 'oh hai'
end
end
@@ -143,9 +143,40 @@
end
end
it "performs foo:bar before deploy:finalize_update" do
@configuration.should callback('foo:bar').before('deploy:finalize_update')
+ end
+
+You can also stub requests if you need to access their output:
+
+ task :pwd do
+ set :pwd, capture('pwd')
+ end
+
+ it 'should capture working directory' do
+ @configuration.stub_command 'pwd', data: '/path/to/working/dir'
+ @configuration.fetch(:pwd).should == '/path/to/working/dir'
+ end
+
+Additional options are +channel+ and +stream+ for testing custom +run+ blocks:
+
+ task :custom do
+ invoke_command 'pwd', :via => :sudo do |ch, stream, data|
+ # magical foo
+ end
+ end
+
+As +sudo+ and +invoke_command+ use +run+ internal and +capture+ uses
++invoke_command+ they are also stub-able by specifying the exact command.
+
+ task :sudo_pwd do
+ set :pwd, capture('pwd', :via => :sudo)
+ end
+
+ it 'should capture sudo working directory' do
+ @configuration.stub_command 'sudo -p 'sudo password: ' pwd', data: '/sudo/dir'
+ @configuration.fetch(:pwd).should == '/sudo/dir'
end
== Real world examples
* [capistrano-mountaintop](https://github.com/technicalpickles/capistrano-mountaintop/blob/master/spec/capistrano-mountaintop_spec.rb)