From aadd88fb8ec8b8adff474d1d5264a3a3d029649a Mon Sep 17 00:00:00 2001 From: Kenneth Mayer Date: Fri, 30 Mar 2012 08:39:50 -0700 Subject: [PATCH] memoize @apps when using 'extra' behaviors --- features/step_definitions/remote_steps.rb | 2 +- lib/heroku_san/project.rb | 2 +- spec/heroku_san/project_spec.rb | 38 +++++++++++++---------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/features/step_definitions/remote_steps.rb b/features/step_definitions/remote_steps.rb index 9301c69..6675bd0 100644 --- a/features/step_definitions/remote_steps.rb +++ b/features/step_definitions/remote_steps.rb @@ -1,7 +1,7 @@ World(Aruba::Api) Given /^I have a new Rails project$/ do - cmd = "rails new heroku_san_test --quiet --force --database=postgresql --skip-bundle --skip-javascript --skip-test-unit --skip-sprockets" #" --template #{template}" + cmd = "rails new heroku_san_test --quiet --force --database=postgresql --skip-bundle --skip-javascript --skip-test-unit --skip-sprockets" run_simple unescape(cmd) end diff --git a/lib/heroku_san/project.rb b/lib/heroku_san/project.rb index 8c5e844..25aaad4 100644 --- a/lib/heroku_san/project.rb +++ b/lib/heroku_san/project.rb @@ -43,7 +43,7 @@ def apps if !@apps.empty? @apps else - case all.size + @apps = case all.size when 1 $stdout.puts "Defaulting to #{all.first.inspect} since only one app is defined" all diff --git a/spec/heroku_san/project_spec.rb b/spec/heroku_san/project_spec.rb index e46a3f9..6e0f8ad 100644 --- a/spec/heroku_san/project_spec.rb +++ b/spec/heroku_san/project_spec.rb @@ -26,7 +26,7 @@ end end - describe "Adding an app to the deploy list" do + describe "#apps adds an app to the deploy list" do it "appends known shorthands to apps" do heroku_san.apps.should == [] heroku_san << 'production' @@ -41,25 +41,29 @@ heroku_san << heroku_san.all heroku_san.apps.should == heroku_san.all end - end - describe "#apps extra default behaviors" do - specify "on a git branch that matches an app name" do - heroku_san.should_receive(:git_active_branch) { "staging" } - $stdout.should_receive(:puts).with("Defaulting to 'staging' as it matches the current branch") - heroku_san.apps.should == %w[staging] - end + describe "#apps extra default behaviors" do + specify "on a git branch that matches an app name" do + heroku_san.should_receive(:git_active_branch) { "staging" } + $stdout.should_receive(:puts).with("Defaulting to 'staging' as it matches the current branch") + expect { + heroku_san.apps.should == %w[staging] + }.to change{heroku_san.instance_variable_get('@apps')}.from([]).to(%w[staging]) + end - specify "on a git branch that doesn't matches an app name" do - heroku_san.should_receive(:git_active_branch) { "master" } - heroku_san.apps.should == %w[] - end + specify "on a git branch that doesn't matches an app name" do + heroku_san.should_receive(:git_active_branch) { "master" } + heroku_san.apps.should == %w[] + end - context "but only a single configured app" do - let(:heroku_san) { HerokuSan::Project.new(File.join(SPEC_ROOT, "fixtures", "single_app.yml")) } - it "returns the app" do - $stdout.should_receive(:puts).with('Defaulting to "production" since only one app is defined') - heroku_san.apps.should == %w[production] + context "but only a single configured app" do + let(:heroku_san) { HerokuSan::Project.new(File.join(SPEC_ROOT, "fixtures", "single_app.yml")) } + it "returns the app" do + $stdout.should_receive(:puts).with('Defaulting to "production" since only one app is defined') + expect { + heroku_san.apps.should == %w[production] + }.to change{heroku_san.instance_variable_get('@apps')}.from([]).to(%w[production]) + end end end end