Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Commit

Permalink
Move outputter into configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Oct 14, 2011
1 parent bb95538 commit 342082a
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 68 deletions.
8 changes: 0 additions & 8 deletions lib/kumade.rb
Expand Up @@ -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
6 changes: 3 additions & 3 deletions lib/kumade/cli.rb
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/kumade/command_line.rb
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions lib/kumade/configuration.rb
Expand Up @@ -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
8 changes: 4 additions & 4 deletions lib/kumade/deployer.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/kumade/git.rb
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/kumade/heroku.rb
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/kumade/packager.rb
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/kumade/rake_task_runner.rb
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions spec/kumade/command_line_spec.rb
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
21 changes: 17 additions & 4 deletions 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
Expand All @@ -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'
Expand Down
10 changes: 5 additions & 5 deletions spec/kumade/deployer_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions spec/kumade/git_spec.rb
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
2 changes: 1 addition & 1 deletion spec/kumade/heroku_spec.rb
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions spec/kumade/packager_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/kumade/rake_task_runner_spec.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 342082a

Please sign in to comment.