This repository has been archived by the owner on Jun 8, 2019. It is now read-only.
/
heroku_spec.rb
115 lines (85 loc) · 2.83 KB
/
heroku_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
require 'spec_helper'
describe Kumade::Heroku, "DEPLOY_BRANCH", :with_mock_outputter do
subject { Kumade::Heroku::DEPLOY_BRANCH }
it { should == "deploy" }
end
describe Kumade::Heroku, "#sync", :with_mock_outputter do
let(:environment) { 'staging' }
before do
force_add_heroku_remote(environment)
subject.git.stubs(:create)
subject.git.stubs(:push)
end
it "creates and pushes the deploy branch" do
subject.sync
subject.git.should have_received(:create).with("deploy")
subject.git.should have_received(:push).with("deploy:master", environment, true)
end
end
describe Kumade::Heroku, "#migrate_database", :with_mock_outputter do
let(:environment) { 'staging' }
before do
subject.stubs(:heroku)
force_add_heroku_remote(environment)
end
it "runs db:migrate with the correct app" do
subject.migrate_database
subject.should have_received(:heroku).with("rake db:migrate")
end
context "when pretending" do
before do
Kumade.configuration.pretending = true
end
it "does not run the command" do
subject.migrate_database
subject.should have_received(:heroku).never
end
it "prints a message" do
subject.migrate_database
Kumade.configuration.outputter.should have_received(:success).with(regexp_matches(/Migrated #{environment}/))
end
end
end
describe Kumade::Heroku, "#heroku", :with_mock_outputter do
let(:command_instance) { stub("Kumade::CommandLine instance", :run_or_error => true) }
before do
Kumade::CommandLine.stubs(:new => command_instance)
end
context "when on Cedar" do
include_context "when on Cedar"
it "runs commands with `run`" do
subject.heroku("rake")
Kumade::CommandLine.should have_received(:new).with(regexp_matches(/bundle exec heroku run rake/)).once
command_instance.should have_received(:run_or_error).once
end
end
context "when not on Cedar" do
include_context "when not on Cedar"
it "runs commands without `run`" do
subject.heroku("rake")
Kumade::CommandLine.should have_received(:new).with(regexp_matches(/bundle exec heroku rake/)).once
command_instance.should have_received(:run_or_error).once
end
end
end
describe Kumade::Heroku, "#cedar?", :with_mock_outputter do
context "when on Cedar" do
include_context "when on Cedar"
it "returns true" do
subject.cedar?.should == true
end
end
context "when not on Cedar" do
include_context "when not on Cedar"
it "returns false" do
subject.cedar?.should == false
end
end
end
describe Kumade::Heroku, "#delete_deploy_branch", :with_mock_outputter do
before { subject.git.stubs(:delete) }
it "deletes the deploy branch" do
subject.delete_deploy_branch
subject.git.should have_received(:delete).with(Kumade::Heroku::DEPLOY_BRANCH, 'master').once
end
end