Skip to content

Commit

Permalink
Merge pull request #12 from jbscv/master
Browse files Browse the repository at this point in the history
Fix to allow testing multiple callbacks on the same task
  • Loading branch information
petems committed May 16, 2013
2 parents 751b510 + 2b1893b commit d16d3ce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
10 changes: 4 additions & 6 deletions lib/capistrano/spec.rb
Expand Up @@ -70,14 +70,12 @@ module Matchers
callbacks = find_callback(configuration, @on, @task)

if callbacks
@callback = callbacks.first

if @callback && @after_task_name
if @after_task_name
@after_task = configuration.find_task(@after_task_name)
@callback.applies_to?(@after_task)
elsif @callback && @before_task_name
callbacks.any? { |callback| callback.applies_to?(@after_task) }
elsif @before_task_name
@before_task = configuration.find_task(@before_task_name)
@callback.applies_to?(@before_task)
callbacks.any? { |callback| callback.applies_to?(@before_task) }
else
! @callback.nil?
end
Expand Down
13 changes: 8 additions & 5 deletions spec/capistrano-spec_spec.rb
@@ -1,6 +1,5 @@
require 'spec_helper'
require 'capistrano'

require File.expand_path('../recipe/fakerecipe', __FILE__)

describe Capistrano::Spec do
Expand Down Expand Up @@ -55,12 +54,16 @@

describe 'callback' do

it "will not raise error when `before` callback has occured" do
expect{ should callback('fake:thing').before('fake:stuff_and_things')}.to_not raise_error(RSpec::Expectations::ExpectationNotMetError, /expected configuration to callback .*\s* before .*\s*, but did not/)
['fake:before_this_execute_thing', "fake:before_this_also_execute_thing"].each do |task|
it "will not raise error when `before` callback has occured for #{task}" do
fake_recipe.should callback('fake:thing').before(task)
end
end

it "will not raise error when `after` callback has occured" do
expect{ should callback('fake:other_thing').after('fake:thing')}.to_not raise_error(RSpec::Expectations::ExpectationNotMetError, /expected configuration to callback .*\s* after .*\s*, but did not/)
['fake:after_this_execute_thing', "fake:after_this_also_execute_thing"].each do |task|
it "will not raise error when `after` callback has occured for #{task}" do
fake_recipe.should callback('fake:thing').after(task)
end
end
end

Expand Down
16 changes: 12 additions & 4 deletions spec/recipe/fakerecipe.rb
Expand Up @@ -3,8 +3,10 @@ module Capistrano
module Fakerecipe
def self.load_into(configuration)
configuration.load do
before "fake:stuff_and_things", "fake:thing"
after "fake:thing", "fake:other_thing"
before "fake:before_this_execute_thing", "fake:thing"
before "fake:before_this_also_execute_thing", "fake:thing"
after "fake:after_this_execute_thing", "fake:thing"
after "fake:after_this_also_execute_thing", "fake:thing"
namespace :fake do
desc "thing and run fake manifests"
task :thing do
Expand All @@ -14,11 +16,17 @@ def self.load_into(configuration)
get('/tmp/baz', 'baz')
end
desc "More fake tasks!"
task :other_thing do
task :before_this_execute_thing do
#
end
desc "You get the picture..."
task :stuff_and_things do
task :before_this_also_execute_thing do
#
end
task :after_this_execute_thing do
#
end
task :after_this_also_execute_thing do
#
end
end
Expand Down

0 comments on commit d16d3ce

Please sign in to comment.