This repository has been archived by the owner on Jun 8, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
deployer_spec.rb
129 lines (97 loc) · 3.17 KB
/
deployer_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require 'spec_helper'
describe Kumade::Deployer, "#pre_deploy" do
let(:git) { subject.git }
it "calls the correct methods" do
git.expects(:ensure_clean_git)
subject.expects(:package_assets)
git.expects(:push).with(subject.git.current_branch)
subject.pre_deploy
end
end
describe Kumade::Deployer, "#deploy" do
let(:remote_name) { 'staging' }
before do
STDOUT.stubs(:puts)
force_add_heroku_remote(remote_name)
end
it "calls the correct methods" do
subject.expects(:pre_deploy)
subject.heroku.expects(:sync)
subject.heroku.expects(:migrate_database)
subject.expects(:post_deploy)
subject.deploy
end
it "calls post_deploy if deploy fails" do
subject.git.stubs(:heroku_remote?).raises(RuntimeError)
subject.expects(:post_deploy)
subject.deploy
end
end
describe Kumade::Deployer, "#sync_github" do
let(:new_branch) { 'new-branch' }
before do
`git checkout -b #{new_branch}`
end
it "pushes the current branch to github" do
subject.git.expects(:push).with(new_branch)
subject.sync_github
end
end
describe Kumade::Deployer, "#ensure_clean_git" do
it "calls git.ensure_clean_git" do
subject.git.expects(:ensure_clean_git)
subject.ensure_clean_git
end
end
describe Kumade::Deployer, "#ensure_heroku_remote_exists" do
let(:environment) { 'staging' }
before do
force_add_heroku_remote(environment)
Kumade.configuration.environment = environment
end
context "when the remote points to Heroku" do
before { STDOUT.stubs(:puts) }
it "does not print an error" do
subject.ensure_heroku_remote_exists
STDOUT.should_not have_received(:puts).with(regexp_matches(/==> !/))
end
it "prints a success message" do
subject.ensure_heroku_remote_exists
STDOUT.should have_received(:puts).with(regexp_matches(/#{environment} is a Heroku remote/))
end
end
context "when the remote does not exist" do
before do
remove_remote(environment)
STDOUT.stubs(:puts)
end
it "prints an error" do
lambda { subject.ensure_heroku_remote_exists }.should raise_error(Kumade::DeploymentError)
STDOUT.should have_received(:puts).with(regexp_matches(/Cannot deploy: "#{environment}" remote does not exist/))
end
end
context "when the remote does not point to Heroku" do
let(:bad_environment) { 'bad' }
before do
`git remote add #{bad_environment} blerg@example.com`
STDOUT.stubs(:puts)
Kumade.configuration.environment = bad_environment
end
it "prints an error" do
lambda { subject.ensure_heroku_remote_exists }.should raise_error(Kumade::DeploymentError)
STDOUT.should have_received(:puts).with(regexp_matches(/Cannot deploy: "#{bad_environment}" remote does not point to Heroku/))
end
end
end
describe Kumade::Deployer, "packaging" do
let(:git) { stub("git", :current_branch => "awesome", :delete => true) }
let(:packager) { stub("packager", :run => true) }
before do
Kumade::Git.stubs(:new => git)
Kumade::Packager.stubs(:new => packager)
end
it "builds the correct packager" do
subject.deploy
Kumade::Packager.should have_received(:new).with(git)
end
end