From 645014cc96e6462cee3f5ce68705e5b297c1eb3f Mon Sep 17 00:00:00 2001 From: Marcos Tapajos Date: Fri, 9 Sep 2011 16:11:02 -0300 Subject: [PATCH] Fix issue #38 --- lib/kumade/deployer.rb | 6 +++--- spec/kumade/deployer_spec.rb | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/kumade/deployer.rb b/lib/kumade/deployer.rb index b841ec8..4b21aab 100644 --- a/lib/kumade/deployer.rb +++ b/lib/kumade/deployer.rb @@ -1,4 +1,5 @@ require "rake" +require 'cocaine' module Kumade class Deployer < Base @@ -58,11 +59,10 @@ def heroku(command) run_or_error("#{heroku_command} #{command} --remote #{environment}", "Failed to run #{command} on Heroku") end - + def cedar? return @cedar unless @cedar.nil? - - @cedar = heroku("stack").split("\n").grep(/\*/).any? do |line| + @cedar = Cocaine::CommandLine.new("bundle exec heroku stack --remote #{environment}").run.split("\n").grep(/\*/).any? do |line| line.include?("cedar") end end diff --git a/spec/kumade/deployer_spec.rb b/spec/kumade/deployer_spec.rb index 89ca968..c0f7a43 100644 --- a/spec/kumade/deployer_spec.rb +++ b/spec/kumade/deployer_spec.rb @@ -438,16 +438,32 @@ class More end describe Kumade::Deployer, "#cedar?" do + let(:cocaine_mock) { mock("Cocaine::CommandLine") } + before { Cocaine::CommandLine.should_receive(:new).with("bundle exec heroku stack --remote staging").and_return(cocaine_mock) } context "when on Cedar" do subject { Kumade::Deployer.new('staging', false) } - before { subject.stub(:heroku).and_return(" bamboo\n* cedar\n") } - its(:cedar?) { should be_true } + it "should be true" do + cocaine_mock.should_receive(:run).and_return(%{ + aspen-mri-1.8.6 + bamboo-mri-1.9.2 + bamboo-ree-1.8.7 +* cedar (beta) +}) + subject.cedar?.should be_true + end end context "when not on Cedar" do subject { Kumade::Deployer.new('staging', false) } - before { subject.stub(:heroku).and_return("* bamboo\n cedar\n") } - its(:cedar?) { should be_false } + it "should be false" do + cocaine_mock.should_receive(:run).and_return(%{ + aspen-mri-1.8.6 +* bamboo-mri-1.9.2 + bamboo-ree-1.8.7 + cedar (beta) +}) + subject.cedar?.should be_false + end end end