forked from technicalpickles/capistrano-spec
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation and documentation.
- Loading branch information
1 parent
f78c02d
commit 8f1723f
Showing
5 changed files
with
340 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Generated by jeweler | ||
# DO NOT EDIT THIS FILE DIRECTLY | ||
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command | ||
# -*- encoding: utf-8 -*- | ||
|
||
Gem::Specification.new do |s| | ||
s.name = %q{capistrano-spec} | ||
s.version = "0.1.0" | ||
|
||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= | ||
s.authors = ["Joshua Nichols"] | ||
s.date = %q{2010-07-20} | ||
s.description = %q{Helpers and matchers for capistrano} | ||
s.email = %q{josh@technicalpickles.com} | ||
s.extra_rdoc_files = [ | ||
"LICENSE", | ||
"README.rdoc" | ||
] | ||
s.files = [ | ||
".document", | ||
".gitignore", | ||
"LICENSE", | ||
"README.rdoc", | ||
"Rakefile", | ||
"lib/capistrano-spec.rb", | ||
"spec/capistrano-spec_spec.rb", | ||
"spec/spec.opts", | ||
"spec/spec_helper.rb" | ||
] | ||
s.homepage = %q{http://github.com/technicalpickles/capistrano-spec} | ||
s.rdoc_options = ["--charset=UTF-8"] | ||
s.require_paths = ["lib"] | ||
s.rubygems_version = %q{1.3.6} | ||
s.summary = %q{Test your capistrano recipes} | ||
s.test_files = [ | ||
"spec/capistrano-spec_spec.rb", | ||
"spec/spec_helper.rb" | ||
] | ||
|
||
if s.respond_to? :specification_version then | ||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION | ||
s.specification_version = 3 | ||
|
||
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then | ||
s.add_development_dependency(%q<rspec>, [">= 1.2.9"]) | ||
else | ||
s.add_dependency(%q<rspec>, [">= 1.2.9"]) | ||
end | ||
else | ||
s.add_dependency(%q<rspec>, [">= 1.2.9"]) | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'capistrano/spec' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
module Capistrano | ||
module Spec | ||
module ConfigurationExtension | ||
def get(remote_path, path, options={}, &block) | ||
gets[remote_path] = {:path => path, :options => options, :block => block} | ||
end | ||
|
||
def gets | ||
@gets ||= {} | ||
end | ||
|
||
def run(cmd, options={}, &block) | ||
runs[cmd] = {:options => options, :block => block} | ||
end | ||
|
||
def runs | ||
@runs ||= {} | ||
end | ||
|
||
def upload(from, to, options={}, &block) | ||
uploads[from] = {:to => to, :options => options, :block => block} | ||
end | ||
|
||
def uploads | ||
@uploads ||= {} | ||
end | ||
|
||
end | ||
|
||
module Helpers | ||
def find_callback(configuration, on, task) | ||
if task.kind_of?(String) | ||
task = configuration.find_task(task) | ||
end | ||
|
||
callbacks = configuration.callbacks[on] | ||
|
||
callbacks && callbacks.select do |task_callback| | ||
task_callback.applies_to?(task) || task_callback.source == task.fully_qualified_name | ||
end | ||
end | ||
|
||
end | ||
|
||
module Matchers | ||
extend ::Spec::Matchers::DSL | ||
|
||
define :callback do |task_name| | ||
extend Helpers | ||
|
||
match do |configuration| | ||
@task = configuration.find_task(task_name) | ||
callbacks = find_callback(configuration, @on, @task) | ||
|
||
if callbacks | ||
@callback = callbacks.first | ||
|
||
if @callback && @after_task_name | ||
@after_task = configuration.find_task(@after_task_name) | ||
@callback.applies_to?(@after_task) | ||
elsif @callback && @before_task_name | ||
@before_task = configuration.find_task(@before_task_name) | ||
@callback.applies_to?(@before_task) | ||
else | ||
! @callback.nil? | ||
end | ||
else | ||
false | ||
end | ||
end | ||
|
||
def on(on) | ||
@on = on | ||
self | ||
end | ||
|
||
def before(before_task_name) | ||
@on = :before | ||
@before_task_name = before_task_name | ||
self | ||
end | ||
|
||
def after(after_task_name) | ||
@on = :after | ||
@after_task_name = after_task_name | ||
self | ||
end | ||
|
||
failure_message_for_should do |actual| | ||
if @after_task_name | ||
"expected configuration to callback #{task_name.inspect} #{@on} #{@after_task_name.inspect}, but did not" | ||
elsif @before_task_name | ||
"expected configuration to callback #{task_name.inspect} #{@on} #{@before_task_name.inspect}, but did not" | ||
else | ||
"expected configuration to callback #{task_name.inspect} on #{@on}, but did not" | ||
end | ||
end | ||
|
||
end | ||
|
||
define :have_gotten do |path| | ||
match do |configuration| | ||
|
||
get = configuration.gets[path] | ||
if @to | ||
get && get[:path] == @to | ||
else | ||
get | ||
end | ||
end | ||
|
||
def to(to) | ||
@to = to | ||
self | ||
end | ||
|
||
failure_message_for_should do |actual| | ||
if @to | ||
"expected configuration to get #{path} to #{@to}, but did not" | ||
else | ||
"expected configuration to get #{path}, but did not" | ||
end | ||
end | ||
end | ||
|
||
define :have_uploaded do |path| | ||
match do |configuration| | ||
upload = configuration.uploads[path] | ||
if @to | ||
upload && upload[:to] == @to | ||
else | ||
upload | ||
end | ||
end | ||
|
||
def to(to) | ||
@to = to | ||
self | ||
end | ||
|
||
failure_message_for_should do |actual| | ||
if @to | ||
"expected configuration to upload #{path} to #{@to}, but did not" | ||
else | ||
"expected configuration to upload #{path}, but did not" | ||
end | ||
end | ||
end | ||
|
||
define :have_run do |cmd| | ||
|
||
match do |configuration| | ||
run = configuration.runs[cmd] | ||
|
||
run | ||
end | ||
|
||
failure_message_for_should do |actual| | ||
"expected configuration to run #{cmd}, but did not" | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end | ||
|