Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Outputter #64

Merged
merged 8 commits into from

2 participants

Gabe Berke-Williams Mike Burns
Gabe Berke-Williams
Admin

Adds CommandLine class to run commands, and uses Kumade.outputter instead of inheriting from Base.

lib/kumade.rb
@@ -21,4 +22,12 @@ module Kumade
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
Mike Burns Admin

Move this into the Configuration object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/kumade/git.rb
((10 lines not shown))
end
def create(branch)
- unless branch_exist?(branch)
- run_or_error("git branch #{branch}", "Failed to create #{branch}")
+ unless has_branch?(branch)
Mike Burns Admin

How about:

if needs_branch?(branch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/kumade/packager.rb
((6 lines not shown))
end
def package
- return success(success_message) if Kumade.configuration.pretending?
+ return Kumade.outputter.success(success_message) if Kumade.configuration.pretending?
Mike Burns Admin

Moving the Outputter into the Configuration could turn this line into:

return configuration.pretend_success(success_message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Gabe Berke-Williams gabebw merged commit 342082a into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 225 additions and 187 deletions.
  1. +6 −8 features/kumade_executable.feature
  2. +1 −1  lib/kumade.rb
  3. +0 −18 lib/kumade/base.rb
  4. +3 −3 lib/kumade/cli.rb
  5. +3 −4 lib/kumade/command_line.rb
  6. +8 −0 lib/kumade/configuration.rb
  7. +6 −6 lib/kumade/deployer.rb
  8. +11 −13 lib/kumade/git.rb
  9. +2 −3 lib/kumade/heroku.rb
  10. +21 −0 lib/kumade/outputter.rb
  11. +5 −6 lib/kumade/packager.rb
  12. +2 −3 lib/kumade/rake_task_runner.rb
  13. +0 −17 spec/kumade/base_spec.rb
  14. +1 −1  spec/kumade/cli_spec.rb
  15. +14 −16 spec/kumade/command_line_spec.rb
  16. +13 −0 spec/kumade/configuration_spec.rb
  17. +23 −22 spec/kumade/deployer_spec.rb
  18. +18 −26 spec/kumade/git_spec.rb
  19. +9 −17 spec/kumade/heroku_spec.rb
  20. +50 −0 spec/kumade/outputter_spec.rb
  21. +1 −1  spec/kumade/packager_list_spec.rb
  22. +8 −9 spec/kumade/packager_spec.rb
  23. +1 −1  spec/kumade/packagers/jammit_packager_spec.rb
  24. +1 −1  spec/kumade/packagers/more_packager_spec.rb
  25. +1 −1  spec/kumade/packagers/noop_packager_spec.rb
  26. +7 −9 spec/kumade/rake_task_runner_spec.rb
  27. +10 −1 spec/spec_helper.rb
14 features/kumade_executable.feature
View
@@ -22,13 +22,12 @@ Feature: Kumade executable
"""
==> Git repo is clean
==> Packaged with Kumade::JammitPackager
- run git push origin master
+ git push origin master
==> Pushed master -> origin
- run git branch deploy
- run git push -f pretend-staging deploy:master
+ git branch deploy >/dev/null
+ git push -f pretend-staging deploy:master
==> Pushed deploy:master -> pretend-staging
==> Migrated pretend-staging
- run git checkout master && git branch -D deploy
==> Deployed to: pretend-staging
"""
But the output should not contain "==> Packaged with Kumade::MorePackager"
@@ -53,13 +52,12 @@ Feature: Kumade executable
"""
==> Git repo is clean
==> Packaged with Kumade::JammitPackager
- run git push origin new_branch
+ git push origin new_branch
==> Pushed new_branch -> origin
- run git branch deploy
- run git push -f pretend-staging deploy:master
+ git branch deploy >/dev/null
+ git push -f pretend-staging deploy:master
==> Pushed deploy:master -> pretend-staging
==> Migrated pretend-staging
- run git checkout new_branch && git branch -D deploy
==> Deployed to: pretend-staging
"""
2  lib/kumade.rb
View
@@ -1,5 +1,4 @@
module Kumade
- autoload :Base, "kumade/base"
autoload :Git, "kumade/git"
autoload :Deployer, "kumade/deployer"
autoload :CLI, "kumade/cli"
@@ -14,6 +13,7 @@ module Kumade
autoload :PackagerList, "kumade/packager_list"
autoload :RakeTaskRunner, "kumade/rake_task_runner"
autoload :CommandLine, "kumade/command_line"
+ autoload :Outputter, "kumade/outputter"
def self.configuration
@@configuration ||= Configuration.new
18 lib/kumade/base.rb
View
@@ -1,18 +0,0 @@
-require "thor"
-
-module Kumade
- class Base < Thor::Shell::Color
- def initialize
- super()
- end
-
- def error(message)
- say("==> ! #{message}", :red)
- raise Kumade::DeploymentError.new(message)
- end
-
- def success(message)
- say("==> #{message}", :green)
- end
- end
-end
6 lib/kumade/cli.rb
View
@@ -44,11 +44,11 @@ def self.swapping_stdout_for(io, print_output = false)
def deploy
if Kumade.configuration.pretending?
- puts "==> In Pretend Mode"
+ Kumade.configuration.outputter.info("In Pretend Mode")
end
- puts "==> Deploying to: #{Kumade.configuration.environment}"
+ Kumade.configuration.outputter.info("Deploying to: #{Kumade.configuration.environment}")
self.class.deployer.new.deploy
- puts "==> Deployed to: #{Kumade.configuration.environment}"
+ Kumade.configuration.outputter.info("Deployed to: #{Kumade.configuration.environment}")
end
def parse_arguments!(args)
7 lib/kumade/command_line.rb
View
@@ -1,18 +1,17 @@
require 'cocaine'
module Kumade
- class CommandLine < Base
+ class CommandLine
def initialize(command_to_run)
- super()
@command_line = Cocaine::CommandLine.new(command_to_run)
end
def run_or_error(error_message = nil)
- run_with_status || error(error_message)
+ run_with_status || Kumade.configuration.outputter.error(error_message)
end
def run_with_status
- say_status(:run, command)
+ Kumade.configuration.outputter.say_command(command)
Kumade.configuration.pretending? || run
end
8 lib/kumade/configuration.rb
View
@@ -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
12 lib/kumade/deployer.rb
View
@@ -2,11 +2,10 @@
require 'cocaine'
module Kumade
- class Deployer < Base
+ class Deployer
attr_reader :git, :heroku, :packager
def initialize
- super()
@git = Git.new
@heroku = Heroku.new
@branch = @git.current_branch
@@ -19,7 +18,8 @@ def deploy
pre_deploy
heroku.sync
heroku.migrate_database
- rescue
+ rescue => deploying_error
+ 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?
- success("#{Kumade.configuration.environment} is a Heroku remote")
+ Kumade.configuration.outputter.success("#{Kumade.configuration.environment} is a Heroku remote")
else
- 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
- 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
24 lib/kumade/git.rb
View
@@ -1,10 +1,6 @@
require 'cocaine'
module Kumade
- class Git < Base
- def initialize
- super()
- end
-
+ class Git
def heroku_remote?
remote_url = `git config --get remote.#{Kumade.configuration.environment}.url`.strip
!! remote_url.strip.match(/^git@heroku\..+:(.+)\.git$/)
@@ -23,27 +19,29 @@ def push(branch, remote = 'origin', force = false)
command_line = CommandLine.new(command)
command_line.run_or_error("Failed to push #{branch} -> #{remote}")
- success("Pushed #{branch} -> #{remote}")
+ Kumade.configuration.outputter.success("Pushed #{branch} -> #{remote}")
end
def create(branch)
unless has_branch?(branch)
- CommandLine.new("git branch #{branch}").run_or_error("Failed to create #{branch}")
+ CommandLine.new("git branch #{branch} >/dev/null").run_or_error("Failed to create #{branch}")
end
end
def delete(branch_to_delete, branch_to_checkout)
- command_line = CommandLine.new("git checkout #{branch_to_checkout} && git branch -D #{branch_to_delete}")
- command_line.run_or_error("Failed to clean up #{branch_to_delete} branch")
+ if has_branch?(branch_to_delete)
+ command_line = CommandLine.new("git checkout #{branch_to_checkout} 2>/dev/null && git branch -D #{branch_to_delete}")
+ command_line.run_or_error("Failed to clean up #{branch_to_delete} branch")
+ end
end
def add_and_commit_all_assets_in(dir)
- command = ["git checkout -b #{Kumade::Heroku::DEPLOY_BRANCH}",
+ command = ["git checkout -b #{Kumade::Heroku::DEPLOY_BRANCH} 2>/dev/null",
"git add -f #{dir}",
"git commit -m 'Compiled assets.'"].join(' && ')
command_line = CommandLine.new(command)
command_line.run_or_error("Cannot deploy: couldn't commit assets")
- success("Added and committed all assets")
+ Kumade.configuration.outputter.success("Added and committed all assets")
end
def current_branch
@@ -64,9 +62,9 @@ def dirty?
def ensure_clean_git
if ! Kumade.configuration.pretending? && dirty?
- error("Cannot deploy: repo is not clean.")
+ Kumade.configuration.outputter.error("Cannot deploy: repo is not clean.")
else
- success("Git repo is clean")
+ Kumade.configuration.outputter.success("Git repo is clean")
end
end
5 lib/kumade/heroku.rb
View
@@ -1,12 +1,11 @@
require 'cocaine'
module Kumade
- class Heroku < Base
+ class Heroku
DEPLOY_BRANCH = "deploy"
attr_reader :git
def initialize
- super()
@git = Git.new
@branch = @git.current_branch
end
@@ -18,7 +17,7 @@ def sync
def migrate_database
heroku("rake db:migrate") unless Kumade.configuration.pretending?
- success("Migrated #{Kumade.configuration.environment}")
+ Kumade.configuration.outputter.success("Migrated #{Kumade.configuration.environment}")
end
def delete_deploy_branch
21 lib/kumade/outputter.rb
View
@@ -0,0 +1,21 @@
+module Kumade
+ class Outputter
+ def success(message)
+ puts "==> #{message}"
+ end
+
+ def info(message)
+ puts "==> #{message}"
+ end
+
+ def error(message)
+ puts "==> ! #{message}"
+ raise Kumade::DeploymentError, message
+ end
+
+ def say_command(command)
+ prefix = " " * 8
+ puts "#{prefix}#{command}"
+ end
+ end
+end
11 lib/kumade/packager.rb
View
@@ -1,7 +1,6 @@
module Kumade
- class Packager < Base
+ class Packager
def initialize(git, packager = Packager.available_packager)
- super()
@packager = packager
@git = git
end
@@ -18,20 +17,20 @@ def self.available_packager
private
def precompile_assets
- RakeTaskRunner.new("kumade:before_asset_compilation", self).invoke
+ RakeTaskRunner.new("kumade:before_asset_compilation").invoke
end
def package
- return 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)
- success(success_message)
+ Kumade.configuration.outputter.success(success_message)
end
rescue => packager_exception
- error("Error: #{packager_exception.class}: #{packager_exception.message}")
+ Kumade.configuration.outputter.error("Error: #{packager_exception.class}: #{packager_exception.message}")
end
end
5 lib/kumade/rake_task_runner.rb
View
@@ -1,14 +1,13 @@
module Kumade
class RakeTaskRunner
- def initialize(task_name, runner)
+ def initialize(task_name)
@task_name = task_name
- @runner = runner
end
def invoke
return unless task_defined?
- @runner.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
17 spec/kumade/base_spec.rb
View
@@ -1,17 +0,0 @@
-require 'spec_helper'
-
-describe Kumade::Base, "#success" do
- it { should respond_to(:success) }
-end
-
-describe Kumade::Base, "#error" do
- before { STDOUT.stubs(:puts) }
-
- it { should respond_to(:error) }
-
- it "prints its message and raises its message" do
- lambda { subject.error("I'm an error!") }.should raise_error(Kumade::DeploymentError)
-
- STDOUT.should have_received(:puts).with(regexp_matches(/I'm an error!/))
- end
-end
2  spec/kumade/cli_spec.rb
View
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Kumade::CLI do
+describe Kumade::CLI, :with_mock_outputter do
let(:out) { StringIO.new }
let(:environment) { 'my-environment' }
let(:deployer) { stub("Deployer", :new => deployer_instance) }
30 spec/kumade/command_line_spec.rb
View
@@ -1,18 +1,13 @@
require 'spec_helper'
-describe Kumade::CommandLine, "#run_or_error" do
- let(:command_line) { stub("Cocaine::CommandLine instance", :run => nil) }
- subject { Kumade::CommandLine.new("echo") }
-
- before do
- subject.stubs(:error)
- subject.stubs(:say_status)
-
- Cocaine::CommandLine.stubs(:new).returns(command_line)
- end
+describe Kumade::CommandLine, "#run_or_error", :with_mock_outputter do
+ subject { Kumade::CommandLine.new("echo") }
context "when pretending" do
+ let(:command_line) { stub("Cocaine::CommandLine instance", :run => nil, :command => 'command') }
+
before do
+ Cocaine::CommandLine.stubs(:new).returns(command_line)
Kumade.configuration.pretending = true
end
@@ -21,12 +16,16 @@
command_line.should have_received(:run).never
end
+
+ it "prints the command" do
+ subject.run_or_error
+ Kumade.configuration.outputter.should have_received(:say_command).with(command_line.command).once
+ end
end
context "when successful" do
before do
Kumade.configuration.pretending = false
- command_line.stubs(:run => true)
end
it "returns true" do
@@ -43,25 +42,24 @@
it "prints an error message" do
subject.run_or_error("something bad")
- subject.should have_received(:error).with("something bad")
+ Kumade.configuration.outputter.should have_received(:error).with("something bad")
end
end
end
-describe Kumade::CommandLine, "#run_with_status" do
+describe Kumade::CommandLine, "#run_with_status", :with_mock_outputter do
let(:command) { "echo" }
let(:command_line) { stub("Cocaine::CommandLine instance", :run => nil, :command => command) }
subject { Kumade::CommandLine.new(command) }
before do
Cocaine::CommandLine.stubs(:new).returns(command_line)
- subject.stubs(:say_status)
end
it "prints the command" do
subject.run_with_status
- subject.should have_received(:say_status).with(:run, "echo").once
+ Kumade.configuration.outputter.should have_received(:say_command).with(command).once
end
context "when pretending" do
@@ -89,7 +87,7 @@
end
end
-describe Kumade::CommandLine, "#run" do
+describe Kumade::CommandLine, "#run", :with_mock_outputter do
context "when successful" do
subject { Kumade::CommandLine.new("echo") }
13 spec/kumade/configuration_spec.rb
View
@@ -5,6 +5,19 @@
it { should_not be_pretending }
end
+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
45 spec/kumade/deployer_spec.rb
View
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Kumade::Deployer, "#pre_deploy" do
+describe Kumade::Deployer, "#pre_deploy", :with_mock_outputter do
let(:git) { subject.git }
it "calls the correct methods" do
@@ -12,11 +12,10 @@
end
end
-describe Kumade::Deployer, "#deploy" do
+describe Kumade::Deployer, "#deploy", :with_mock_outputter do
let(:remote_name) { 'staging' }
before do
- STDOUT.stubs(:puts)
force_add_heroku_remote(remote_name)
end
@@ -29,20 +28,26 @@
subject.deploy
end
- it "calls post_deploy if deploy fails" do
- subject.git.stubs(:heroku_remote?).raises(RuntimeError)
+ context "if deploy fails" do
+ before { subject.git.stubs(:heroku_remote?).raises(RuntimeError.new("fun times")) }
- subject.expects(:post_deploy)
+ it "calls post_deploy" do
+ subject.expects(:post_deploy)
+ subject.deploy
+ end
- subject.deploy
+ it "prints the error" do
+ subject.deploy
+ Kumade.configuration.outputter.should have_received(:error).with("RuntimeError: fun times")
+ end
end
end
-describe Kumade::Deployer, "#sync_origin" do
+describe Kumade::Deployer, "#sync_origin", :with_mock_outputter do
let(:new_branch) { 'new-branch' }
before do
- `git checkout -b #{new_branch}`
+ `git checkout -b #{new_branch} 2>/dev/null`
end
it "pushes the current branch to origin" do
@@ -52,14 +57,14 @@
end
end
-describe Kumade::Deployer, "#ensure_clean_git" do
+describe Kumade::Deployer, "#ensure_clean_git", :with_mock_outputter do
it "calls git.ensure_clean_git" do
subject.git.expects(:ensure_clean_git)
subject.ensure_clean_git
end
end
-describe Kumade::Deployer, "#ensure_heroku_remote_exists" do
+describe Kumade::Deployer, "#ensure_heroku_remote_exists", :with_mock_outputter do
let(:environment) { 'staging' }
before do
@@ -68,31 +73,28 @@
end
context "when the remote points to Heroku" do
- before { STDOUT.stubs(:puts) }
-
it "does not print an error" do
subject.ensure_heroku_remote_exists
- STDOUT.should have_received(:puts).with(regexp_matches(/==> !/)).never
+ Kumade.configuration.outputter.should have_received(:error).never
end
it "prints a success message" do
subject.ensure_heroku_remote_exists
- STDOUT.should have_received(:puts).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
context "when the remote does not exist" do
before do
remove_remote(environment)
- STDOUT.stubs(:puts)
end
it "prints an error" do
- lambda { subject.ensure_heroku_remote_exists }.should raise_error(Kumade::DeploymentError)
+ subject.ensure_heroku_remote_exists
- STDOUT.should have_received(:puts).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
@@ -101,19 +103,18 @@
before do
`git remote add #{bad_environment} blerg@example.com`
- STDOUT.stubs(:puts)
Kumade.configuration.environment = bad_environment
end
it "prints an error" do
- lambda { subject.ensure_heroku_remote_exists }.should raise_error(Kumade::DeploymentError)
+ subject.ensure_heroku_remote_exists
- STDOUT.should have_received(:puts).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
-describe Kumade::Deployer, "packaging" do
+describe Kumade::Deployer, "packaging", :with_mock_outputter do
let(:git) { stub("git", :current_branch => "awesome", :delete => true) }
let(:packager) { stub("packager", :run => true) }
44 spec/kumade/git_spec.rb
View
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Kumade::Git, "#heroku_remote?" do
+describe Kumade::Git, "#heroku_remote?", :with_mock_outputter do
context "when the environment is a Heroku repository" do
include_context "with Heroku environment"
@@ -20,7 +20,7 @@
end
end
-describe Kumade::Git, ".environments" do
+describe Kumade::Git, ".environments", :with_mock_outputter do
let(:environment) { 'staging' }
let(:not_a_heroku_env) { 'fake_heroku' }
let(:not_a_heroku_url) { 'git@github.com:gabebw/kumade.git' }
@@ -40,14 +40,13 @@
end
end
-describe Kumade::Git, "#push" do
+describe Kumade::Git, "#push", :with_mock_outputter do
let(:branch) { 'branch' }
let(:remote) { 'my-remote' }
let(:command_line) { stub("Kumade::CommandLine instance", :run_or_error => true) }
before do
Kumade::CommandLine.stubs(:new => command_line)
- subject.stubs(:success)
end
it "pushes to the correct remote" do
@@ -64,31 +63,30 @@
it "prints a success message" do
subject.push(branch, remote)
- subject.should have_received(:success).with("Pushed #{branch} -> #{remote}")
+ Kumade.configuration.outputter.should have_received(:success).with("Pushed #{branch} -> #{remote}")
end
end
-describe Kumade::Git, "#create" do
+describe Kumade::Git, "#create", :with_mock_outputter do
let(:branch) { "my-new-branch" }
it "creates a branch" do
subject.create(branch)
- system("git show-ref #{branch}").should be_true
+ system("git show-ref #{branch} > /dev/null").should be_true
end
context "when the branch already exists" do
before do
subject.create(branch)
- subject.stubs(:error)
end
it "does not error" do
subject.create(branch)
- subject.should have_received(:error).never
+ Kumade.configuration.outputter.should have_received(:error).never
end
end
end
-describe Kumade::Git, "#delete" do
+describe Kumade::Git, "#delete", :with_mock_outputter do
let(:branch_to_delete) { 'branch_to_delete' }
let(:branch_to_checkout) { 'branch_to_checkout' }
@@ -108,7 +106,7 @@
end
end
-describe Kumade::Git, "#add_and_commit_all_assets_in" do
+describe Kumade::Git, "#add_and_commit_all_assets_in", :with_mock_outputter do
let(:directory) { 'assets' }
before do
@@ -118,8 +116,6 @@
f.write('some content')
end
end
-
- subject.stubs(:success)
end
it "switches to the deploy branch" do
@@ -139,7 +135,7 @@
it "prints a success message" do
subject.add_and_commit_all_assets_in(directory)
- subject.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
@@ -155,15 +151,15 @@
end
end
-describe Kumade::Git, "#current_branch" do
+describe Kumade::Git, "#current_branch", :with_mock_outputter do
it "returns the current branch" do
subject.current_branch.should == 'master'
- `git checkout -b new-branch`
+ `git checkout -b new-branch 2>/dev/null`
subject.current_branch.should == 'new-branch'
end
end
-describe Kumade::Git, "#remote_exists?" do
+describe Kumade::Git, "#remote_exists?", :with_mock_outputter do
context "when pretending" do
before { Kumade.configuration.pretending = true }
it "returns true no matter what" do
@@ -189,7 +185,7 @@
end
end
-describe Kumade::Git, "#dirty?" do
+describe Kumade::Git, "#dirty?", :with_mock_outputter do
context "when dirty" do
before { dirty_the_repo }
@@ -202,11 +198,7 @@
end
-describe Kumade::Git, "#ensure_clean_git" do
- before do
- subject.stubs(:success => nil, :error => nil)
- end
-
+describe Kumade::Git, "#ensure_clean_git", :with_mock_outputter do
context "when pretending" do
before do
Kumade.configuration.pretending = true
@@ -215,14 +207,14 @@
it "prints a success message" do
subject.ensure_clean_git
- subject.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
- subject.should have_received(:success).with("Git repo is clean")
+ Kumade.configuration.outputter.should have_received(:success).with("Git repo is clean")
end
end
@@ -231,7 +223,7 @@
it "prints an error message" do
subject.ensure_clean_git
- subject.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
26 spec/kumade/heroku_spec.rb
View
@@ -1,12 +1,12 @@
require 'spec_helper'
-describe Kumade::Heroku, "DEPLOY_BRANCH" do
+describe Kumade::Heroku, "DEPLOY_BRANCH", :with_mock_outputter do
subject { Kumade::Heroku::DEPLOY_BRANCH }
it { should == "deploy" }
end
-describe Kumade::Heroku, "#sync" do
+describe Kumade::Heroku, "#sync", :with_mock_outputter do
let(:environment) { 'staging' }
before do
@@ -23,11 +23,10 @@
end
end
-describe Kumade::Heroku, "#migrate_database" do
+describe Kumade::Heroku, "#migrate_database", :with_mock_outputter do
let(:environment) { 'staging' }
before do
- STDOUT.stubs(:puts)
subject.stubs(:heroku)
force_add_heroku_remote(environment)
end
@@ -40,7 +39,6 @@
context "when pretending" do
before do
- STDOUT.stubs(:puts)
Kumade.configuration.pretending = true
end
@@ -53,17 +51,16 @@
it "prints a message" do
subject.migrate_database
- STDOUT.should have_received(:puts).with(regexp_matches(/Migrated #{environment}/))
+ Kumade.configuration.outputter.should have_received(:success).with(regexp_matches(/Migrated #{environment}/))
end
end
end
-describe Kumade::Heroku, "#heroku" do
+describe Kumade::Heroku, "#heroku", :with_mock_outputter do
let(:command_instance) { stub("Kumade::CommandLine instance", :run_or_error => true) }
before do
Kumade::CommandLine.stubs(:new => command_instance)
- STDOUT.stubs(:puts)
end
context "when on Cedar" do
@@ -89,7 +86,7 @@
end
end
-describe Kumade::Heroku, "#cedar?" do
+describe Kumade::Heroku, "#cedar?", :with_mock_outputter do
context "when on Cedar" do
include_context "when on Cedar"
@@ -107,17 +104,12 @@
end
end
-describe Kumade::Heroku, "#delete_deploy_branch" do
- let(:command_instance) { stub("Kumade::CommandLine instance", :run_or_error => true) }
-
- before do
- Kumade::CommandLine.stubs(:new => command_instance)
- end
+describe Kumade::Heroku, "#delete_deploy_branch", :with_mock_outputter do
+ before { subject.git.stubs(:delete) }
it "deletes the deploy branch" do
subject.delete_deploy_branch
- Kumade::CommandLine.should have_received(:new).with("git checkout master && git branch -D deploy").once
- command_instance.should have_received(:run_or_error).once
+ subject.git.should have_received(:delete).with(Kumade::Heroku::DEPLOY_BRANCH, 'master').once
end
end
50 spec/kumade/outputter_spec.rb
View
@@ -0,0 +1,50 @@
+require 'spec_helper'
+
+describe Kumade::Outputter, "#success" do
+ before { STDOUT.stubs(:puts) }
+
+ it "prints a message to STDOUT" do
+ subject.success("woo hoo")
+ STDOUT.should have_received(:puts).with(regexp_matches(/==> woo hoo/))
+ end
+end
+
+describe Kumade::Outputter, "#error" do
+ before { STDOUT.stubs(:puts) }
+
+ it "raises a DeploymentError with the given message" do
+ lambda { subject.error("uh oh") }.should raise_error(Kumade::DeploymentError, "uh oh")
+ end
+
+ it "prints a message to STDOUT" do
+ subject.error("uh oh") rescue nil
+ STDOUT.should have_received(:puts).with(regexp_matches(/==> ! uh oh/))
+ end
+end
+
+describe Kumade::Outputter, "#info" do
+ before { STDOUT.stubs(:puts) }
+
+ it "prints a message to STDOUT" do
+ subject.info("the more you know")
+ STDOUT.should have_received(:puts).with(regexp_matches(/==> the more you know/))
+ end
+end
+
+describe Kumade::Outputter, "#say_command" do
+ before { STDOUT.stubs(:puts) }
+
+ it "prints a formatted message to STDOUT" do
+ subject.say_command("git checkout master")
+ STDOUT.should have_received(:puts).with(" " * 8 + "git checkout master")
+ end
+end
+
+describe Kumade::Outputter, "#info" do
+ before { STDOUT.stubs(:puts) }
+
+ it "prints a message to STDOUT" do
+ subject.info("the more you know")
+ STDOUT.should have_received(:puts).with(regexp_matches(/==> the more you know/))
+ end
+end
2  spec/kumade/packager_list_spec.rb
View
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Kumade::PackagerList, "detecting packages" do
+describe Kumade::PackagerList, "detecting packages", :with_mock_outputter do
it "returns an array containing the Jammit packager if Jammit is installed" do
Kumade::JammitPackager.stubs(:installed? => true)
Kumade::MorePackager.stubs(:installed? => false)
17 spec/kumade/packager_spec.rb
View
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe Kumade::Packager, ".available_packager" do
+describe Kumade::Packager, ".available_packager", :with_mock_outputter do
let(:packager_1) { "1st packager" }
let(:packager_2) { "2nd packager" }
@@ -15,21 +15,20 @@
end
end
-describe Kumade::Packager, "#run" do
+describe Kumade::Packager, "#run", :with_mock_outputter do
let(:git) { stub("git", :dirty? => true, :add_and_commit_all_assets_in => true) }
let(:packager) { stub("packager", :name => "MyPackager", :package => true, :assets_path => 'fake_assets_path') }
let(:rake_task_runner) { stub("RakeTaskRunner", :invoke => true) }
before do
Kumade::RakeTaskRunner.stubs(:new => rake_task_runner)
- subject.stubs(:success => nil, :error => nil)
end
subject { Kumade::Packager.new(git, packager) }
it "precompiles assets" do
subject.run
- Kumade::RakeTaskRunner.should have_received(:new).with("kumade:before_asset_compilation", subject)
+ Kumade::RakeTaskRunner.should have_received(:new).with("kumade:before_asset_compilation")
rake_task_runner.should have_received(:invoke)
end
@@ -41,7 +40,7 @@
it "prints a success message" do
subject.run
- subject.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
@@ -57,7 +56,7 @@
it "prints a success message" do
subject.run
- subject.should have_received(:success).with("Packaged with MyPackager")
+ Kumade.configuration.outputter.should have_received(:success).with("Packaged with MyPackager")
end
it "packages" do
@@ -68,7 +67,7 @@
it "prints an error if an exception is raised" do
packager.stubs(:package).raises(RuntimeError.new("my specific error"))
subject.run
- subject.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
@@ -87,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
- subject.should have_received(:success).never
+ Kumade.configuration.outputter.should have_received(:success).never
end
end
@@ -99,7 +98,7 @@
it "does not print a success message" do
subject.run
- subject.should have_received(:success).never
+ Kumade.configuration.outputter.should have_received(:success).never
end
it "doesn't perform a commit" do
2  spec/kumade/packagers/jammit_packager_spec.rb
View
@@ -2,7 +2,7 @@
require "jammit"
-describe Kumade::JammitPackager do
+describe Kumade::JammitPackager, :with_mock_outputter do
subject { Kumade::JammitPackager }
it_should_behave_like "packager"
2  spec/kumade/packagers/more_packager_spec.rb
View
@@ -2,7 +2,7 @@
require "less"
-describe Kumade::MorePackager do
+describe Kumade::MorePackager, :with_mock_outputter do
subject { Kumade::MorePackager }
before do
2  spec/kumade/packagers/noop_packager_spec.rb
View
@@ -1,6 +1,6 @@
require "spec_helper"
-describe Kumade::NoopPackager do
+describe Kumade::NoopPackager, :with_mock_outputter do
subject { Kumade::NoopPackager }
it_should_behave_like "packager"
16 spec/kumade/rake_task_runner_spec.rb
View
@@ -1,19 +1,17 @@
require "spec_helper"
-describe Kumade::RakeTaskRunner do
- let(:runner) { stub("runner", :success => true) }
-
+describe Kumade::RakeTaskRunner, :with_mock_outputter do
context "when the task doesn't exist" do
- subject { Kumade::RakeTaskRunner.new("bogus:task", runner) }
+ subject { Kumade::RakeTaskRunner.new("bogus:task") }
it "does not notify the user that the task was run successfully" do
subject.invoke
- runner.should have_received(:success).never
+ Kumade.configuration.outputter.should have_received(:success).never
end
end
context "when Rakefile exists" do
- subject { Kumade::RakeTaskRunner.new("bogus:task", runner) }
+ subject { Kumade::RakeTaskRunner.new("bogus:task") }
before do
File.stubs(:exist?).with("Rakefile").returns(true)
@@ -40,7 +38,7 @@
Rake::Task[task_name].reenable
end
- subject { Kumade::RakeTaskRunner.new(task_name, runner) }
+ subject { Kumade::RakeTaskRunner.new(task_name) }
context "when pretending" do
before do
@@ -49,7 +47,7 @@
it "notifies the user that the task was run successfully" do
subject.invoke
- runner.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
@@ -65,7 +63,7 @@
it "notifies the user that the task was run successfully" do
subject.invoke
- runner.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
11 spec/spec_helper.rb
View
@@ -19,7 +19,6 @@ def remove_remote(remote_name)
end
end
-
spec_dir = Pathname.new(File.expand_path(File.dirname(__FILE__)))
Dir[spec_dir.join('support', '**', "*.rb")].each {|f| require File.expand_path(f) }
@@ -46,6 +45,16 @@ def remove_remote(remote_name)
end
end
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+
+ config.before(:each, :with_mock_outputter) do
+ Kumade.configuration.outputter = stub("Null Outputter", :success => true, :error => true, :info => true, :say_command => true)
+ end
+
+ config.after(:each, :with_mock_outputter) do
+ Kumade.configuration.outputter = Kumade::Outputter.new
+ end
+
config.after do
Kumade.configuration = Kumade::Configuration.new
end
Something went wrong with that request. Please try again.