Skip to content

Commit

Permalink
Add a test for #kill_unicorn + small cleanup for existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Omer Gazit authored and Omer Gazit committed Aug 24, 2013
1 parent 4d6f9ae commit 411a479
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions spec/capistrano_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
@configuration.stub(:_cset)
end

share_examples_for "a task" do |task_name|
after do
#Execute the task after the test to trigger the before_task hook
@configuration.find_and_execute_task(task_name)
end
shared_examples_for "a task" do |task_name|
it "sets attributes in before_task hook" do
@configuration.should_receive(:_cset).with(:app_env)
@configuration.should_receive(:_cset).with(:unicorn_pid)
Expand All @@ -24,22 +20,23 @@
@configuration.should_receive(:_cset).with(:unicorn_user)
@configuration.should_receive(:_cset).with(:unicorn_config_path)
@configuration.should_receive(:_cset).with(:unicorn_config_filename)

@configuration.find_and_execute_task(task_name)
end
end


describe "task" do
describe 'unicorn:start' do
before do
@configuration.stub(:start_unicorn)
end

it_should_behave_like "a task", 'unicorn:start'
it_behaves_like "a task", 'unicorn:start'

it "should run start_unicorn" do
@configuration.should_receive(:start_unicorn).and_return("start_unicorn")
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")
@configuration.should have_run("start unicorn command")
end
end

Expand All @@ -48,13 +45,24 @@
@configuration.stub(:kill_unicorn)
end

it_should_behave_like "a task", 'unicorn:stop'
it_behaves_like "a task", 'unicorn:stop'

it "should run kill_unicorn" do
@configuration.should_receive(:kill_unicorn).with('QUIT').and_return("kill_unicorn")
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")
@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

0 comments on commit 411a479

Please sign in to comment.