forked from sepastian/capistrano-unicorn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapistrano_integration_spec.rb
84 lines (70 loc) · 3.06 KB
/
capistrano_integration_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
require "spec_helper"
describe CapistranoUnicorn::CapistranoIntegration, "loaded tasks into capistrano" do
before do
@configuration = Capistrano::Configuration.new
@configuration.extend(Capistrano::Spec::ConfigurationExtension)
CapistranoUnicorn::CapistranoIntegration.load_into(@configuration)
end
shared_examples_for "a task" do |task_name|
it "sets attributes in before_task hook" do
# Environments
@configuration.should_receive(:_cset).with(:unicorn_env)
@configuration.should_receive(:_cset).with(:unicorn_rack_env)
# Execution
@configuration.should_receive(:_cset).with(:unicorn_user)
@configuration.should_receive(:_cset).with(:unicorn_bundle)
@configuration.should_receive(:_cset).with(:unicorn_bin)
@configuration.should_receive(:_cset).with(:unicorn_options)
@configuration.should_receive(:_cset).with(:unicorn_restart_sleep_time)
# Relative paths
@configuration.should_receive(:_cset).with(:app_subdir)
@configuration.should_receive(:_cset).with(:unicorn_config_rel_path)
@configuration.should_receive(:_cset).with(:unicorn_config_filename)
@configuration.should_receive(:_cset).with(:unicorn_config_rel_file_path)
@configuration.should_receive(:_cset).with(:unicorn_config_stage_rel_file_path)
# Absolute paths
@configuration.should_receive(:_cset).with(:app_path)
@configuration.should_receive(:_cset).with(:unicorn_pid)
@configuration.should_receive(:_cset).with(:bundle_gemfile)
@configuration.should_receive(:_cset).with(:unicorn_config_path)
@configuration.should_receive(:_cset).with(:unicorn_config_file_path)
@configuration.should_receive(:_cset).with(:unicorn_config_stage_file_path)
@configuration.find_and_execute_task(task_name)
end
end
describe "task" do
describe 'unicorn:start' do
before do
@configuration.stub(:start_unicorn)
@configuration.stub(:_cset)
end
it_behaves_like "a task", 'unicorn:start'
it "runs start_unicorn command" do
@configuration.should_receive(:start_unicorn).and_return("start unicorn command")
@configuration.find_and_execute_task('unicorn:start')
@configuration.should have_run("start unicorn command")
end
end
describe 'unicorn:stop' do
before do
@configuration.stub(:kill_unicorn)
@configuration.stub(:_cset)
end
it_behaves_like "a task", 'unicorn:stop'
it "runs kill_unicorn command" do
@configuration.should_receive(:kill_unicorn).with('QUIT').and_return("kill unicorn command")
@configuration.find_and_execute_task('unicorn:stop')
@configuration.should have_run("kill unicorn command")
end
end
end
describe "#kill_unicorn" do
before do
@configuration.stub(:unicorn_pid).and_return(999)
@configuration.stub(:unicorn_user).and_return("deploy_user")
end
it "generates the kill unicorn command" do
@configuration.kill_unicorn('QUIT').should match /-u deploy_user kill -s QUIT `cat 999`;/
end
end
end