capistrano-spec 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +15 -0
- data/README.rdoc +34 -3
- data/Rakefile +2 -2
- data/capistrano-spec.gemspec +7 -5
- data/lib/capistrano/spec.rb +25 -8
- data/spec/stub_commands_spec.rb +76 -0
- data/spec/uploaded_spec.rb +44 -0
- metadata +6 -3
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,28 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
+
capistrano (2.14.2)
|
5
|
+
highline
|
6
|
+
net-scp (>= 1.0.0)
|
7
|
+
net-sftp (>= 2.0.0)
|
8
|
+
net-ssh (>= 2.0.14)
|
9
|
+
net-ssh-gateway (>= 1.1.0)
|
4
10
|
diff-lcs (1.1.3)
|
5
11
|
git (1.2.5)
|
12
|
+
highline (1.6.16)
|
6
13
|
jeweler (1.8.3)
|
7
14
|
bundler (~> 1.0)
|
8
15
|
git (>= 1.2.5)
|
9
16
|
rake
|
10
17
|
rdoc
|
11
18
|
json (1.6.6)
|
19
|
+
net-scp (1.1.0)
|
20
|
+
net-ssh (>= 2.6.5)
|
21
|
+
net-sftp (2.1.1)
|
22
|
+
net-ssh (>= 2.6.5)
|
23
|
+
net-ssh (2.6.6)
|
24
|
+
net-ssh-gateway (1.2.0)
|
25
|
+
net-ssh (>= 2.6.5)
|
12
26
|
rake (0.9.2.2)
|
13
27
|
rdoc (3.12)
|
14
28
|
json (~> 1.4)
|
@@ -25,6 +39,7 @@ PLATFORMS
|
|
25
39
|
ruby
|
26
40
|
|
27
41
|
DEPENDENCIES
|
42
|
+
capistrano
|
28
43
|
jeweler
|
29
44
|
rake
|
30
45
|
rspec
|
data/README.rdoc
CHANGED
@@ -73,7 +73,7 @@ Alright, we can start testing by making Capistrano::Configuration and load Capis
|
|
73
73
|
@configuration = Capistrano::Configuration.new
|
74
74
|
Capistrano::Speak.load_into(@configuration)
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
end
|
78
78
|
|
79
79
|
|
@@ -84,7 +84,7 @@ Now, remember, if you +set+ values, you can access them using +fetch+:
|
|
84
84
|
before do
|
85
85
|
@configuration.set :foo, 'bar'
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
it "should define foo" do
|
89
89
|
@configuration.fetch(:foo).should == 'bar'
|
90
90
|
end
|
@@ -96,7 +96,7 @@ You can also find and execute tasks, so you can verify if you successfully set a
|
|
96
96
|
before do
|
97
97
|
@configuration.find_and_execute_task('speak')
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
it "should define message" do
|
101
101
|
@configuration.fetch(:message).should == 'oh hai'
|
102
102
|
end
|
@@ -147,6 +147,37 @@ You also test [callbacks](http://rubydoc.info/github/capistrano/capistrano/maste
|
|
147
147
|
@configuration.should callback('foo:bar').before('deploy:finalize_update')
|
148
148
|
end
|
149
149
|
|
150
|
+
You can also stub requests if you need to access their output:
|
151
|
+
|
152
|
+
task :pwd do
|
153
|
+
set :pwd, capture('pwd')
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'should capture working directory' do
|
157
|
+
@configuration.stub_command 'pwd', data: '/path/to/working/dir'
|
158
|
+
@configuration.fetch(:pwd).should == '/path/to/working/dir'
|
159
|
+
end
|
160
|
+
|
161
|
+
Additional options are +channel+ and +stream+ for testing custom +run+ blocks:
|
162
|
+
|
163
|
+
task :custom do
|
164
|
+
invoke_command 'pwd', :via => :sudo do |ch, stream, data|
|
165
|
+
# magical foo
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
As +sudo+ and +invoke_command+ use +run+ internal and +capture+ uses
|
170
|
+
+invoke_command+ they are also stub-able by specifying the exact command.
|
171
|
+
|
172
|
+
task :sudo_pwd do
|
173
|
+
set :pwd, capture('pwd', :via => :sudo)
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should capture sudo working directory' do
|
177
|
+
@configuration.stub_command 'sudo -p 'sudo password: ' pwd', data: '/sudo/dir'
|
178
|
+
@configuration.fetch(:pwd).should == '/sudo/dir'
|
179
|
+
end
|
180
|
+
|
150
181
|
== Real world examples
|
151
182
|
|
152
183
|
* [capistrano-mountaintop](https://github.com/technicalpickles/capistrano-mountaintop/blob/master/spec/capistrano-mountaintop_spec.rb)
|
data/Rakefile
CHANGED
@@ -5,13 +5,13 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "capistrano-spec"
|
8
|
-
gem.version = '0.
|
8
|
+
gem.version = '0.3.0'
|
9
9
|
|
10
10
|
gem.summary = %Q{Test your capistrano recipes}
|
11
11
|
gem.description = %Q{Helpers and matchers for testing capistrano}
|
12
12
|
gem.email = "josh@technicalpickles.com"
|
13
13
|
gem.homepage = "http://github.com/technicalpickles/capistrano-spec"
|
14
|
-
gem.authors = ["Joshua Nichols", "Karl Matthias", "Peter M Souter"]
|
14
|
+
gem.authors = ["Joshua Nichols", "Karl Matthias", "Peter M Souter", "Jan Graichen"]
|
15
15
|
gem.add_development_dependency "rspec", ">= 2.0.0"
|
16
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
17
|
end
|
data/capistrano-spec.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "capistrano-spec"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Joshua Nichols", "Karl Matthias", "Peter M Souter"]
|
12
|
-
s.date = "2013-04-
|
11
|
+
s.authors = ["Joshua Nichols", "Karl Matthias", "Peter M Souter", "Jan Graichen"]
|
12
|
+
s.date = "2013-04-07"
|
13
13
|
s.description = "Helpers and matchers for testing capistrano"
|
14
14
|
s.email = "josh@technicalpickles.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,11 +28,13 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/capistrano/spec.rb",
|
29
29
|
"spec/capistrano-spec_spec.rb",
|
30
30
|
"spec/spec.opts",
|
31
|
-
"spec/spec_helper.rb"
|
31
|
+
"spec/spec_helper.rb",
|
32
|
+
"spec/stub_commands_spec.rb",
|
33
|
+
"spec/uploaded_spec.rb"
|
32
34
|
]
|
33
35
|
s.homepage = "http://github.com/technicalpickles/capistrano-spec"
|
34
36
|
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version = "1.8.
|
37
|
+
s.rubygems_version = "1.8.25"
|
36
38
|
s.summary = "Test your capistrano recipes"
|
37
39
|
|
38
40
|
if s.respond_to? :specification_version then
|
data/lib/capistrano/spec.rb
CHANGED
@@ -11,6 +11,15 @@ module Capistrano
|
|
11
11
|
|
12
12
|
def run(cmd, options={}, &block)
|
13
13
|
runs[cmd] = {:options => options, :block => block}
|
14
|
+
if (stub = stubbed_commands[cmd])
|
15
|
+
raise ::Capistrano::CommandError if stub[:fail]
|
16
|
+
raise stub[:raise] if stub[:raise]
|
17
|
+
|
18
|
+
data = stub[:data]
|
19
|
+
data = stub[:with].call(cmd) if stub[:with].respond_to? :call
|
20
|
+
|
21
|
+
block.call stub[:channel], stub[:stream], data if block_given?
|
22
|
+
end
|
14
23
|
end
|
15
24
|
|
16
25
|
def runs
|
@@ -24,7 +33,15 @@ module Capistrano
|
|
24
33
|
def uploads
|
25
34
|
@uploads ||= {}
|
26
35
|
end
|
27
|
-
|
36
|
+
|
37
|
+
def stubbed_commands
|
38
|
+
@stubbed_commands ||= {}
|
39
|
+
end
|
40
|
+
|
41
|
+
def stub_command(command, options = {}, &block)
|
42
|
+
options[:with] = block if block_given?
|
43
|
+
stubbed_commands[command] = { :stream => :out, :data => '' }.merge options
|
44
|
+
end
|
28
45
|
end
|
29
46
|
|
30
47
|
module Helpers
|
@@ -124,13 +141,13 @@ module Capistrano
|
|
124
141
|
end
|
125
142
|
|
126
143
|
define :have_uploaded do |path|
|
144
|
+
@to = nil # Reset `to` because it will influence next match otherwise.
|
145
|
+
|
127
146
|
match do |configuration|
|
128
|
-
|
129
|
-
if
|
130
|
-
|
131
|
-
|
132
|
-
upload
|
133
|
-
end
|
147
|
+
uploads = configuration.uploads
|
148
|
+
uploads = uploads.select { |f, u| f == path } if path
|
149
|
+
uploads = uploads.select { |f, u| u[:to] == @to } if @to
|
150
|
+
uploads.any?
|
134
151
|
end
|
135
152
|
|
136
153
|
def to(to)
|
@@ -158,7 +175,7 @@ module Capistrano
|
|
158
175
|
failure_message_for_should do |actual|
|
159
176
|
"expected configuration to run #{cmd}, but did not"
|
160
177
|
end
|
161
|
-
|
178
|
+
|
162
179
|
end
|
163
180
|
|
164
181
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'capistrano'
|
3
|
+
|
4
|
+
describe 'Command stubbing' do
|
5
|
+
before do
|
6
|
+
@configuration = Capistrano::Configuration.new
|
7
|
+
@configuration.extend Capistrano::Spec::ConfigurationExtension
|
8
|
+
@configuration.load do
|
9
|
+
def remote_pwd
|
10
|
+
capture 'pwd'
|
11
|
+
end
|
12
|
+
|
13
|
+
def remote_sudo_pwd
|
14
|
+
capture 'pwd', :via => :sudo
|
15
|
+
end
|
16
|
+
|
17
|
+
def custom_pwd
|
18
|
+
run 'pwd' do |ch, stream, data|
|
19
|
+
return "#{stream}: #{data}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def no_block
|
24
|
+
run 'pwd'
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should allow to stub command output' do
|
31
|
+
@configuration.stub_command 'pwd', :data => '/stubded/path'
|
32
|
+
@configuration.remote_pwd.should == '/stubded/path'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should allow to stub sudo command output' do
|
36
|
+
@configuration.stub_command "sudo -p 'sudo password: ' pwd", :data => '/stubbed/path'
|
37
|
+
@configuration.remote_sudo_pwd.should == '/stubbed/path'
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should allow to stub custom command output' do
|
41
|
+
@configuration.stub_command 'pwd', :data => '/stubbed/path'
|
42
|
+
@configuration.custom_pwd.should == 'out: /stubbed/path'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should allow to stub stream' do
|
46
|
+
@configuration.stub_command 'pwd', :data => '/stubbed/path', :stream => :err
|
47
|
+
@configuration.custom_pwd.should == 'err: /stubbed/path'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should allow to stub commands without block' do
|
51
|
+
@configuration.stub_command 'pwd'
|
52
|
+
expect { @configuration.no_block }.to_not raise_error(NoMethodError)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should allow to stub command processing' do
|
56
|
+
@configuration.stub_command 'pwd', with: proc { |cmd| cmd }
|
57
|
+
@configuration.remote_pwd.should == 'pwd'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should allow to stub command processing (2)' do
|
61
|
+
testvar = false
|
62
|
+
@configuration.stub_command 'pwd' do |cmd| testvar = true end
|
63
|
+
@configuration.no_block
|
64
|
+
testvar.should be_true
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should allow to stub command processing with error' do
|
68
|
+
@configuration.stub_command 'pwd', raise: ::Capistrano::CommandError
|
69
|
+
expect { @configuration.no_block }.to raise_error(::Capistrano::CommandError)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should allow to stub command processing with CommandError' do
|
73
|
+
@configuration.stub_command 'pwd', fail: true
|
74
|
+
expect { @configuration.no_block }.to raise_error(::Capistrano::CommandError)
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'capistrano'
|
3
|
+
|
4
|
+
describe 'Capistrano has uploaded' do
|
5
|
+
include Capistrano::Spec::Matchers
|
6
|
+
|
7
|
+
before do
|
8
|
+
@configuration = Capistrano::Configuration.new
|
9
|
+
@configuration.extend Capistrano::Spec::ConfigurationExtension
|
10
|
+
@configuration.load do
|
11
|
+
def upload_from_to
|
12
|
+
upload 'source.file', 'target.file'
|
13
|
+
end
|
14
|
+
|
15
|
+
def upload_to
|
16
|
+
upload 'temp.XC3PO.file', 'target.file' # E.g. uploading generated tar
|
17
|
+
end
|
18
|
+
|
19
|
+
def upload_from
|
20
|
+
upload 'source.file', 'temp.XC3PO.file' # E.g. uploading to temp file
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'some file' do
|
26
|
+
@configuration.upload 'source.file', 'target.file'
|
27
|
+
@configuration.should have_uploaded
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'a specific file to a specific location' do
|
31
|
+
@configuration.upload_from_to
|
32
|
+
@configuration.should have_uploaded('source.file').to('target.file')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'a specific file to some location' do
|
36
|
+
@configuration.upload_from
|
37
|
+
@configuration.should have_uploaded('source.file')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'some file to a specific location' do
|
41
|
+
@configuration.upload_to
|
42
|
+
@configuration.should have_uploaded.to('target.file')
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Joshua Nichols
|
9
9
|
- Karl Matthias
|
10
10
|
- Peter M Souter
|
11
|
+
- Jan Graichen
|
11
12
|
autorequire:
|
12
13
|
bindir: bin
|
13
14
|
cert_chain: []
|
14
|
-
date: 2013-04-
|
15
|
+
date: 2013-04-07 00:00:00.000000000 Z
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|
17
18
|
name: rspec
|
@@ -49,6 +50,8 @@ files:
|
|
49
50
|
- spec/capistrano-spec_spec.rb
|
50
51
|
- spec/spec.opts
|
51
52
|
- spec/spec_helper.rb
|
53
|
+
- spec/stub_commands_spec.rb
|
54
|
+
- spec/uploaded_spec.rb
|
52
55
|
homepage: http://github.com/technicalpickles/capistrano-spec
|
53
56
|
licenses: []
|
54
57
|
post_install_message:
|
@@ -69,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
72
|
version: '0'
|
70
73
|
requirements: []
|
71
74
|
rubyforge_project:
|
72
|
-
rubygems_version: 1.8.
|
75
|
+
rubygems_version: 1.8.25
|
73
76
|
signing_key:
|
74
77
|
specification_version: 3
|
75
78
|
summary: Test your capistrano recipes
|