From 342082ad2c8529aa6b22eef62e41814b99827cb9 Mon Sep 17 00:00:00 2001 From: Gabe Berke-Williams Date: Fri, 14 Oct 2011 11:31:54 -0400 Subject: [PATCH] Move outputter into configuration. --- lib/kumade.rb | 8 -------- lib/kumade/cli.rb | 6 +++--- lib/kumade/command_line.rb | 4 ++-- lib/kumade/configuration.rb | 8 ++++++++ lib/kumade/deployer.rb | 8 ++++---- lib/kumade/git.rb | 8 ++++---- lib/kumade/heroku.rb | 2 +- lib/kumade/packager.rb | 6 +++--- lib/kumade/rake_task_runner.rb | 2 +- spec/kumade/command_line_spec.rb | 6 +++--- spec/kumade/configuration_spec.rb | 21 +++++++++++++++++---- spec/kumade/deployer_spec.rb | 10 +++++----- spec/kumade/git_spec.rb | 12 ++++++------ spec/kumade/heroku_spec.rb | 2 +- spec/kumade/packager_spec.rb | 10 +++++----- spec/kumade/rake_task_runner_spec.rb | 6 +++--- spec/kumade_spec.rb | 13 ------------- spec/spec_helper.rb | 4 ++-- 18 files changed, 68 insertions(+), 68 deletions(-) diff --git a/lib/kumade.rb b/lib/kumade.rb index ce65d47..f16d8ba 100644 --- a/lib/kumade.rb +++ b/lib/kumade.rb @@ -22,12 +22,4 @@ def self.configuration def self.configuration=(new_configuration) @@configuration = new_configuration end - - def self.outputter - @@outputter ||= Outputter.new - end - - def self.outputter=(new_outputter) - @@outputter = new_outputter - end end diff --git a/lib/kumade/cli.rb b/lib/kumade/cli.rb index 3fdb9e8..784b0b3 100644 --- a/lib/kumade/cli.rb +++ b/lib/kumade/cli.rb @@ -44,11 +44,11 @@ def self.swapping_stdout_for(io, print_output = false) def deploy if Kumade.configuration.pretending? - Kumade.outputter.info("In Pretend Mode") + Kumade.configuration.outputter.info("In Pretend Mode") end - Kumade.outputter.info("Deploying to: #{Kumade.configuration.environment}") + Kumade.configuration.outputter.info("Deploying to: #{Kumade.configuration.environment}") self.class.deployer.new.deploy - Kumade.outputter.info("Deployed to: #{Kumade.configuration.environment}") + Kumade.configuration.outputter.info("Deployed to: #{Kumade.configuration.environment}") end def parse_arguments!(args) diff --git a/lib/kumade/command_line.rb b/lib/kumade/command_line.rb index 804e61f..ea27f07 100644 --- a/lib/kumade/command_line.rb +++ b/lib/kumade/command_line.rb @@ -7,11 +7,11 @@ def initialize(command_to_run) end def run_or_error(error_message = nil) - run_with_status || Kumade.outputter.error(error_message) + run_with_status || Kumade.configuration.outputter.error(error_message) end def run_with_status - Kumade.outputter.say_command(command) + Kumade.configuration.outputter.say_command(command) Kumade.configuration.pretending? || run end diff --git a/lib/kumade/configuration.rb b/lib/kumade/configuration.rb index c1cff18..27fa2b9 100644 --- a/lib/kumade/configuration.rb +++ b/lib/kumade/configuration.rb @@ -9,5 +9,13 @@ def pretending? def environment @environment || "staging" end + + def outputter + @outputter ||= Outputter.new + end + + def outputter=(new_outputter) + @outputter = new_outputter + end end end diff --git a/lib/kumade/deployer.rb b/lib/kumade/deployer.rb index e7ff24c..52267aa 100644 --- a/lib/kumade/deployer.rb +++ b/lib/kumade/deployer.rb @@ -19,7 +19,7 @@ def deploy heroku.sync heroku.migrate_database rescue => deploying_error - Kumade.outputter.error("#{deploying_error.class}: #{deploying_error.message}") + Kumade.configuration.outputter.error("#{deploying_error.class}: #{deploying_error.message}") ensure post_deploy end @@ -50,12 +50,12 @@ def ensure_clean_git def ensure_heroku_remote_exists if git.remote_exists?(Kumade.configuration.environment) if git.heroku_remote? - Kumade.outputter.success("#{Kumade.configuration.environment} is a Heroku remote") + Kumade.configuration.outputter.success("#{Kumade.configuration.environment} is a Heroku remote") else - Kumade.outputter.error(%{Cannot deploy: "#{Kumade.configuration.environment}" remote does not point to Heroku}) + Kumade.configuration.outputter.error(%{Cannot deploy: "#{Kumade.configuration.environment}" remote does not point to Heroku}) end else - Kumade.outputter.error(%{Cannot deploy: "#{Kumade.configuration.environment}" remote does not exist}) + Kumade.configuration.outputter.error(%{Cannot deploy: "#{Kumade.configuration.environment}" remote does not exist}) end end end diff --git a/lib/kumade/git.rb b/lib/kumade/git.rb index 653c062..c40303d 100644 --- a/lib/kumade/git.rb +++ b/lib/kumade/git.rb @@ -19,7 +19,7 @@ def push(branch, remote = 'origin', force = false) command_line = CommandLine.new(command) command_line.run_or_error("Failed to push #{branch} -> #{remote}") - Kumade.outputter.success("Pushed #{branch} -> #{remote}") + Kumade.configuration.outputter.success("Pushed #{branch} -> #{remote}") end def create(branch) @@ -41,7 +41,7 @@ def add_and_commit_all_assets_in(dir) "git commit -m 'Compiled assets.'"].join(' && ') command_line = CommandLine.new(command) command_line.run_or_error("Cannot deploy: couldn't commit assets") - Kumade.outputter.success("Added and committed all assets") + Kumade.configuration.outputter.success("Added and committed all assets") end def current_branch @@ -62,9 +62,9 @@ def dirty? def ensure_clean_git if ! Kumade.configuration.pretending? && dirty? - Kumade.outputter.error("Cannot deploy: repo is not clean.") + Kumade.configuration.outputter.error("Cannot deploy: repo is not clean.") else - Kumade.outputter.success("Git repo is clean") + Kumade.configuration.outputter.success("Git repo is clean") end end diff --git a/lib/kumade/heroku.rb b/lib/kumade/heroku.rb index 22e4cd8..6e56b89 100644 --- a/lib/kumade/heroku.rb +++ b/lib/kumade/heroku.rb @@ -17,7 +17,7 @@ def sync def migrate_database heroku("rake db:migrate") unless Kumade.configuration.pretending? - Kumade.outputter.success("Migrated #{Kumade.configuration.environment}") + Kumade.configuration.outputter.success("Migrated #{Kumade.configuration.environment}") end def delete_deploy_branch diff --git a/lib/kumade/packager.rb b/lib/kumade/packager.rb index fc21fc3..d826ccc 100644 --- a/lib/kumade/packager.rb +++ b/lib/kumade/packager.rb @@ -21,16 +21,16 @@ def precompile_assets end def package - return Kumade.outputter.success(success_message) if Kumade.configuration.pretending? + return Kumade.configuration.outputter.success(success_message) if Kumade.configuration.pretending? begin @packager.package if @git.dirty? @git.add_and_commit_all_assets_in(@packager.assets_path) - Kumade.outputter.success(success_message) + Kumade.configuration.outputter.success(success_message) end rescue => packager_exception - Kumade.outputter.error("Error: #{packager_exception.class}: #{packager_exception.message}") + Kumade.configuration.outputter.error("Error: #{packager_exception.class}: #{packager_exception.message}") end end diff --git a/lib/kumade/rake_task_runner.rb b/lib/kumade/rake_task_runner.rb index be4d986..877b3b0 100644 --- a/lib/kumade/rake_task_runner.rb +++ b/lib/kumade/rake_task_runner.rb @@ -7,7 +7,7 @@ def initialize(task_name) def invoke return unless task_defined? - Kumade.outputter.success("Running rake task: #{@task_name}") + Kumade.configuration.outputter.success("Running rake task: #{@task_name}") Rake::Task[@task_name].invoke if task_should_be_run? end diff --git a/spec/kumade/command_line_spec.rb b/spec/kumade/command_line_spec.rb index f59a066..96ed99c 100644 --- a/spec/kumade/command_line_spec.rb +++ b/spec/kumade/command_line_spec.rb @@ -19,7 +19,7 @@ it "prints the command" do subject.run_or_error - Kumade.outputter.should have_received(:say_command).with(command_line.command).once + Kumade.configuration.outputter.should have_received(:say_command).with(command_line.command).once end end @@ -42,7 +42,7 @@ it "prints an error message" do subject.run_or_error("something bad") - Kumade.outputter.should have_received(:error).with("something bad") + Kumade.configuration.outputter.should have_received(:error).with("something bad") end end end @@ -59,7 +59,7 @@ it "prints the command" do subject.run_with_status - Kumade.outputter.should have_received(:say_command).with(command).once + Kumade.configuration.outputter.should have_received(:say_command).with(command).once end context "when pretending" do diff --git a/spec/kumade/configuration_spec.rb b/spec/kumade/configuration_spec.rb index 08ecb37..1d7cab3 100644 --- a/spec/kumade/configuration_spec.rb +++ b/spec/kumade/configuration_spec.rb @@ -1,18 +1,31 @@ require 'spec_helper' -describe Kumade::Configuration, "by default", :with_mock_outputter do +describe Kumade::Configuration, "by default" do its(:environment) { should == 'staging' } it { should_not be_pretending } end -describe Kumade::Configuration, "#pretending", :with_mock_outputter do +describe Kumade::Configuration, "#outputter" do + it "defaults to a Kumade::Outputter instance" do + subject.outputter.should be_a Kumade::Outputter + end +end + +describe Kumade::Configuration, "#outputter=" do + it "sets outputter" do + subject.outputter = "new-value" + subject.outputter.should == "new-value" + end +end + +describe Kumade::Configuration, "#pretending" do it "has read/write access for the pretending attribute" do subject.pretending = true subject.should be_pretending end end -describe Kumade::Configuration, "#pretending?", :with_mock_outputter do +describe Kumade::Configuration, "#pretending?" do it "returns false when not pretending" do subject.pretending = false subject.should_not be_pretending @@ -28,7 +41,7 @@ end end -describe Kumade::Configuration, "#environment", :with_mock_outputter do +describe Kumade::Configuration, "#environment" do it "has read/write access for the environment attribute" do subject.environment = 'new-environment' subject.environment.should == 'new-environment' diff --git a/spec/kumade/deployer_spec.rb b/spec/kumade/deployer_spec.rb index 89fa36e..729dd43 100644 --- a/spec/kumade/deployer_spec.rb +++ b/spec/kumade/deployer_spec.rb @@ -38,7 +38,7 @@ it "prints the error" do subject.deploy - Kumade.outputter.should have_received(:error).with("RuntimeError: fun times") + Kumade.configuration.outputter.should have_received(:error).with("RuntimeError: fun times") end end end @@ -76,13 +76,13 @@ it "does not print an error" do subject.ensure_heroku_remote_exists - Kumade.outputter.should have_received(:error).never + Kumade.configuration.outputter.should have_received(:error).never end it "prints a success message" do subject.ensure_heroku_remote_exists - Kumade.outputter.should have_received(:success).with(regexp_matches(/#{environment} is a Heroku remote/)) + Kumade.configuration.outputter.should have_received(:success).with(regexp_matches(/#{environment} is a Heroku remote/)) end end @@ -94,7 +94,7 @@ it "prints an error" do subject.ensure_heroku_remote_exists - Kumade.outputter.should have_received(:error).with(regexp_matches(/Cannot deploy: "#{environment}" remote does not exist/)) + Kumade.configuration.outputter.should have_received(:error).with(regexp_matches(/Cannot deploy: "#{environment}" remote does not exist/)) end end @@ -109,7 +109,7 @@ it "prints an error" do subject.ensure_heroku_remote_exists - Kumade.outputter.should have_received(:error).with(regexp_matches(/Cannot deploy: "#{bad_environment}" remote does not point to Heroku/)) + Kumade.configuration.outputter.should have_received(:error).with(regexp_matches(/Cannot deploy: "#{bad_environment}" remote does not point to Heroku/)) end end end diff --git a/spec/kumade/git_spec.rb b/spec/kumade/git_spec.rb index 4e82305..3ce69bf 100644 --- a/spec/kumade/git_spec.rb +++ b/spec/kumade/git_spec.rb @@ -63,7 +63,7 @@ it "prints a success message" do subject.push(branch, remote) - Kumade.outputter.should have_received(:success).with("Pushed #{branch} -> #{remote}") + Kumade.configuration.outputter.should have_received(:success).with("Pushed #{branch} -> #{remote}") end end @@ -81,7 +81,7 @@ it "does not error" do subject.create(branch) - Kumade.outputter.should have_received(:error).never + Kumade.configuration.outputter.should have_received(:error).never end end end @@ -135,7 +135,7 @@ it "prints a success message" do subject.add_and_commit_all_assets_in(directory) - Kumade.outputter.should have_received(:success).with('Added and committed all assets') + Kumade.configuration.outputter.should have_received(:success).with('Added and committed all assets') end context "if the command fails" do @@ -207,14 +207,14 @@ it "prints a success message" do subject.ensure_clean_git - Kumade.outputter.should have_received(:success).with("Git repo is clean") + Kumade.configuration.outputter.should have_received(:success).with("Git repo is clean") end end context "when repo is clean" do it "prints a success message" do subject.ensure_clean_git - Kumade.outputter.should have_received(:success).with("Git repo is clean") + Kumade.configuration.outputter.should have_received(:success).with("Git repo is clean") end end @@ -223,7 +223,7 @@ it "prints an error message" do subject.ensure_clean_git - Kumade.outputter.should have_received(:error).with("Cannot deploy: repo is not clean.") + Kumade.configuration.outputter.should have_received(:error).with("Cannot deploy: repo is not clean.") end end end diff --git a/spec/kumade/heroku_spec.rb b/spec/kumade/heroku_spec.rb index 180d543..d5cbaf7 100644 --- a/spec/kumade/heroku_spec.rb +++ b/spec/kumade/heroku_spec.rb @@ -51,7 +51,7 @@ it "prints a message" do subject.migrate_database - Kumade.outputter.should have_received(:success).with(regexp_matches(/Migrated #{environment}/)) + Kumade.configuration.outputter.should have_received(:success).with(regexp_matches(/Migrated #{environment}/)) end end end diff --git a/spec/kumade/packager_spec.rb b/spec/kumade/packager_spec.rb index 42b3898..1144455 100644 --- a/spec/kumade/packager_spec.rb +++ b/spec/kumade/packager_spec.rb @@ -40,7 +40,7 @@ it "prints a success message" do subject.run - Kumade.outputter.should have_received(:success).with("Packaged with MyPackager") + Kumade.configuration.outputter.should have_received(:success).with("Packaged with MyPackager") end it "does not package" do @@ -56,7 +56,7 @@ it "prints a success message" do subject.run - Kumade.outputter.should have_received(:success).with("Packaged with MyPackager") + Kumade.configuration.outputter.should have_received(:success).with("Packaged with MyPackager") end it "packages" do @@ -67,7 +67,7 @@ it "prints an error if an exception is raised" do packager.stubs(:package).raises(RuntimeError.new("my specific error")) subject.run - Kumade.outputter.should have_received(:error).with("Error: RuntimeError: my specific error") + Kumade.configuration.outputter.should have_received(:error).with("Error: RuntimeError: my specific error") end end end @@ -86,7 +86,7 @@ it "prints the success message after committing" do git.stubs(:add_and_commit_all_assets_in).raises(RuntimeError.new("something broke")) subject.run - Kumade.outputter.should have_received(:success).never + Kumade.configuration.outputter.should have_received(:success).never end end @@ -98,7 +98,7 @@ it "does not print a success message" do subject.run - Kumade.outputter.should have_received(:success).never + Kumade.configuration.outputter.should have_received(:success).never end it "doesn't perform a commit" do diff --git a/spec/kumade/rake_task_runner_spec.rb b/spec/kumade/rake_task_runner_spec.rb index 17514e9..068f29a 100644 --- a/spec/kumade/rake_task_runner_spec.rb +++ b/spec/kumade/rake_task_runner_spec.rb @@ -6,7 +6,7 @@ it "does not notify the user that the task was run successfully" do subject.invoke - Kumade.outputter.should have_received(:success).never + Kumade.configuration.outputter.should have_received(:success).never end end @@ -47,7 +47,7 @@ it "notifies the user that the task was run successfully" do subject.invoke - Kumade.outputter.should have_received(:success).with("Running rake task: #{task_name}") + Kumade.configuration.outputter.should have_received(:success).with("Running rake task: #{task_name}") end it "does not invoke the task" do @@ -63,7 +63,7 @@ it "notifies the user that the task was run successfully" do subject.invoke - Kumade.outputter.should have_received(:success).with("Running rake task: #{task_name}") + Kumade.configuration.outputter.should have_received(:success).with("Running rake task: #{task_name}") end it "invokes the task" do diff --git a/spec/kumade_spec.rb b/spec/kumade_spec.rb index 3e9235d..1b976f7 100644 --- a/spec/kumade_spec.rb +++ b/spec/kumade_spec.rb @@ -16,16 +16,3 @@ Kumade.configuration.should == "new-value" end end - -describe Kumade, ".outputter" do - it "defaults to a Kumade::Outputter instance" do - Kumade.outputter.should be_a Kumade::Outputter - end -end - -describe Kumade, ".outputter=" do - it "sets Kumade.outputter" do - Kumade.outputter = "new-value" - Kumade.outputter.should == "new-value" - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index acc741b..4668f05 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -48,11 +48,11 @@ def remove_remote(remote_name) config.treat_symbols_as_metadata_keys_with_true_values = true config.before(:each, :with_mock_outputter) do - Kumade.outputter = stub("Null Outputter", :success => true, :error => true, :info => true, :say_command => true) + Kumade.configuration.outputter = stub("Null Outputter", :success => true, :error => true, :info => true, :say_command => true) end config.after(:each, :with_mock_outputter) do - Kumade.outputter = Kumade::Outputter.new + Kumade.configuration.outputter = Kumade::Outputter.new end config.after do