diff --git a/CHANGELOG.md b/CHANGELOG.md index e5846294..74bc7dfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ Reverse Chronological Order: https://github.com/capistrano/capistrano/compare/v3.2.1...HEAD +* Minor Changes + * Added tests for after/before hooks features (@juanibiapina, @miry) + ## `3.2.1` https://github.com/capistrano/capistrano/compare/v3.2.0...v3.2.1 diff --git a/spec/lib/capistrano/dsl/task_enhancements_spec.rb b/spec/lib/capistrano/dsl/task_enhancements_spec.rb new file mode 100644 index 00000000..1f692c61 --- /dev/null +++ b/spec/lib/capistrano/dsl/task_enhancements_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper' + +module Capistrano + class DummyTaskEnhancements + include TaskEnhancements + end + + describe TaskEnhancements do + let(:task_enhancements) { DummyTaskEnhancements.new } + + describe 'ordering' do + + after do + task.clear + before_task.clear + after_task.clear + Rake::Task.clear + end + + let(:order) { [] } + let!(:task) do + Rake::Task.define_task('task', [:order]) do |t, args| + args['order'].push 'task' + end + end + + let!(:before_task) do + Rake::Task.define_task('before_task') do + order.push 'before_task' + end + end + + let!(:after_task) do + Rake::Task.define_task('after_task') do + order.push 'after_task' + end + end + + it 'invokes in proper order if define after than before' do + task_enhancements.after('task', 'after_task') + task_enhancements.before('task', 'before_task') + + Rake::Task['task'].invoke order + + expect(order).to eq(['before_task', 'task', 'after_task']) + end + + it 'invokes in proper order if define before than after' do + task_enhancements.before('task', 'before_task') + task_enhancements.after('task', 'after_task') + + Rake::Task['task'].invoke order + + expect(order).to eq(['before_task', 'task', 'after_task']) + end + + it 'invokes in proper order and with arguments and block' do + task_enhancements.after('task', 'after_task_custom', :order) do |t, args| + order.push 'after_task' + end + + task_enhancements.before('task', 'before_task_custom', :order) do |t, args| + order.push 'before_task' + end + + Rake::Task['task'].invoke(order) + + expect(order).to eq(['before_task', 'task', 'after_task']) + end + + end + end +end