Permalink
Browse files

Move outputter into configuration.

  • Loading branch information...
1 parent bb95538 commit 342082ad2c8529aa6b22eef62e41814b99827cb9 @gabebw gabebw committed Oct 14, 2011
View
8 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
View
6 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)
View
4 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
View
8 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
View
8 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
View
8 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
View
2 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
View
6 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
View
2 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
View
6 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
View
21 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'
View
10 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
View
12 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
View
2 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
View
10 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
View
6 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
View
13 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
View
4 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

0 comments on commit 342082a

Please sign in to comment.