spec/cli/deploy_spec.rb in hanzo-0.4.2 vs spec/cli/deploy_spec.rb in hanzo-0.4.3

- old
+ new

@@ -3,11 +3,10 @@ describe Hanzo::CLI do describe :deploy do let(:env) { 'production' } let(:branch) { '1.0.0' } let(:deploy!) { Hanzo::CLI.new(['deploy', env]) } - let(:migrations_exist) { false } let(:heroku_remotes) { { 'production' => 'heroku-app-production' } } let(:migration_dir) { 'db/migrate' } let(:migration_question) { 'Run migrations?' } let(:deploy_question) { "Branch to deploy in #{env}:" } @@ -15,46 +14,74 @@ let(:migration_cmd) { "heroku run rake db:migrate --remote #{env}" } let(:restart_cmd) { "heroku ps:restart --remote #{env}" } let(:deploy_cmd) { "git push -f #{env} #{branch}:master" } before do - Dir.should_receive(:exists?).with(migration_dir).and_return(migrations_exist) - Hanzo::Installers::Remotes.stub(:environments).and_return(heroku_remotes) - Hanzo.should_receive(:ask).with(deploy_question).and_return(branch) - Hanzo.should_receive(:run).with(deploy_cmd).once + expect(Hanzo::Installers::Remotes).to receive(:environments).and_return(['production']) + expect(Hanzo::Installers::Remotes).to receive(:installed_environments).and_return(['production']) end - context 'without migration' do + context 'successful deploy and without migrations' do + let(:migrations_exist) { false } + let(:deploy_result) { true } + + before do + expect(Dir).to receive(:exist?).with(migration_dir).and_return(migrations_exist) + expect(Hanzo).to receive(:ask).with(deploy_question).and_return(branch) + expect(Hanzo).to receive(:run).with(deploy_cmd).once.and_return(deploy_result) + end + it 'should git push to heroku upstream' do deploy! end end - context 'with migrations' do + context 'with existing migrations' do let(:migrations_exist) { true } - context 'that should be ran' do + before do + expect(Hanzo).to receive(:ask).with(deploy_question).and_return(branch) + expect(Hanzo).to receive(:run).with(deploy_cmd).once.and_return(deploy_result) + end + + context 'with successful deploy' do + let(:deploy_result) { true } + before do - Hanzo.should_receive(:agree).with(migration_question).and_return(true) - Hanzo.should_receive(:run).with(migration_cmd) - Hanzo.should_receive(:run).with(restart_cmd) + expect(Dir).to receive(:exist?).with(migration_dir).and_return(migrations_exist) end - it 'should run migrations' do - deploy! + context 'and migrations that should be ran' do + before do + expect(Hanzo).to receive(:agree).with(migration_question).and_return(true) + expect(Hanzo).to receive(:run).with(migration_cmd) + expect(Hanzo).to receive(:run).with(restart_cmd) + end + + specify { deploy! } end + + context 'and migrations that should not be ran' do + before do + expect(Hanzo).to receive(:agree).with(migration_question).and_return(false) + expect(Hanzo).not_to receive(:run).with(migration_cmd) + expect(Hanzo).not_to receive(:run).with(restart_cmd) + end + + specify { deploy! } + end end - context 'that should not be ran' do + context 'without successful deploy' do + let(:deploy_result) { false } + before do - Hanzo.should_receive(:agree).with(migration_question).and_return(false) - Hanzo.should_not_receive(:run).with(migration_cmd) - Hanzo.should_not_receive(:run).with(restart_cmd) + expect(Hanzo).not_to receive(:agree).with(migration_question) + expect(Hanzo).not_to receive(:run).with(migration_cmd) + expect(Hanzo).not_to receive(:run).with(restart_cmd) end - it 'should not run migrations' do - deploy! - end + specify { deploy! } end end end end