spec/tasks_spec.rb in slackistrano-1.0.0 vs spec/tasks_spec.rb in slackistrano-1.1.0
- old
+ new
@@ -1,10 +1,10 @@
require 'spec_helper'
describe Slackistrano do
before(:each) do
- Rake::Task['load:defaults'].invoke
+ Rake::Task['load:defaults'].execute
end
describe "before/after hooks" do
it "invokes slack:deploy:updating before deploy:updating" do
@@ -33,21 +33,44 @@
end
%w[updating reverting updated reverted failed].each do |stage|
it "posts to slack on slack:deploy:#{stage}" do
set "slack_run_#{stage}".to_sym, ->{ true }
- expect(Slackistrano).to receive :post
+ expect(Slackistrano).to receive(:post).and_return(double(code: '200'))
Rake::Task["slack:deploy:#{stage}"].execute
end
it "does not post to slack on slack:deploy:#{stage} when disabled" do
set "slack_run_#{stage}".to_sym, ->{ false }
- expect(Slackistrano).not_to receive :post
+ expect(Slackistrano).not_to receive(:post)
Rake::Task["slack:deploy:#{stage}"].execute
end
end
+ context "when :slack_channel is an array" do
+ %w[updating reverting updated reverted failed].each do |stage|
+ it "posts to slack on slack:deploy:#{stage} in every channel" do
+ set "slack_channel".to_sym, ->{ %w[one two] }
+ set "slack_run_#{stage}".to_sym, ->{ true }
+ expect(Slackistrano).to receive(:post).twice.and_return(double(code: '200'))
+ Rake::Task["slack:deploy:#{stage}"].execute
+ end
+ end
+ end
+
+ context "when --dry-run is passed" do
+ %w[updating reverting updated reverted failed].each do |stage|
+ it "does not post to slack on slack:deploy:#{stage}" do
+ set "slack_run_#{stage}".to_sym, ->{ true }
+ expect(Capistrano::Configuration.env.send(:config)).to receive(:[]).with(:sshkit_backend).and_return(SSHKit::Backend::Printer)
+ expect(Slackistrano).not_to receive(:post)
+ Rake::Task["slack:deploy:#{stage}"].execute
+ end
+ end
+ end
+
+
[ # stage, color, channel
['updating', nil, nil],
['reverting', nil, nil],
['updated', 'good', nil],
['reverted', '#4CBDEC', nil],
@@ -89,10 +112,10 @@
username: 'Slackistrano',
icon_url: 'http://icon.url',
icon_emoji: ':emoji:',
attachments: [attachment]
}
- )
+ ).and_return(double(code: '200'))
Rake::Task["slack:deploy:#{stage}"].execute
end
end