Permalink
Browse files

add flag to run with tests

  • Loading branch information...
1 parent c09b5d5 commit 4f687023d9c85c41d1f28f9e67211593fb5e158f @alexgodin alexgodin committed Aug 26, 2011
Showing with 66 additions and 36 deletions.
  1. +21 −11 features/kumade_executable.feature
  2. +15 −5 lib/kumade/deployer.rb
  3. +7 −2 lib/kumade/runner.rb
  4. +22 −17 spec/kumade/deployer_spec.rb
  5. +1 −1 spec/kumade/runner_spec.rb
View
32 features/kumade_executable.feature
@@ -81,44 +81,54 @@ Feature: Kumade executable
And I run kumade with "pretend-staging"
Then the output from "bundle exec kumade pretend-staging" should contain "==> ! Cannot deploy: repo is not clean"
- Scenario: Using rspec
- Given I write to "Rakefile" with:
+ Scenario: No tests run if no -t flag
+ Given I write to "Rakefile" with:
"""
task :spec do
puts 'Hi!'
end
"""
When I run kumade with "pretend-staging -p"
+ Then the output should not contain "Running spec task"
+
+ Scenario: Using rspec
+ Given I write to "Rakefile" with:
+ """
+ task :spec do
+ puts 'Hi!'
+ end
+ """
+ When I run kumade with "pretend-staging -p -t"
Then the output should contain "Running spec task"
- Scenario: Using test unit
- Given I write to "Rakefile" with:
+ Scenario: Using test unit
+ Given I write to "Rakefile" with:
"""
task :test do
puts 'Hi!'
end
"""
- When I run kumade with "pretend-staging -p"
+ When I run kumade with "pretend-staging -p -t"
Then the output should contain "Running test task"
- Scenario: Using cucumber
- Given I write to "Rakefile" with:
+ Scenario: Using cucumber
+ Given I write to "Rakefile" with:
"""
task :cucumber do
puts 'Hi!'
end
"""
- When I run kumade with "pretend-staging -p"
+ When I run kumade with "pretend-staging -p -t"
Then the output should contain "Running cucumber task"
- Scenario: Using capybara
- Given I write to "Rakefile" with:
+ Scenario: Using capybara
+ Given I write to "Rakefile" with:
"""
task :features do
puts 'Hi!'
end
"""
- When I run kumade with "pretend-staging -p"
+ When I run kumade with "pretend-staging -p -t"
Then the output should contain "Running features task"
Scenario: Jammit packager runs if Jammit is installed
View
20 lib/kumade/deployer.rb
@@ -3,12 +3,20 @@ class Deployer < Thor::Shell::Color
DEPLOY_BRANCH = "deploy"
attr_reader :environment, :pretending
- def initialize(environment = 'staging', pretending = false, cedar = false)
+ def initialize(options = { })
super()
- @environment = environment
- @pretending = pretending
+ default = {
+ :environment => 'staging',
+ :pretending => false,
+ :cedar => false,
+ :tests => false
+ }
+ options = default.merge(options)
+ @environment = options[:environment]
+ @pretending = options[:pretending]
@branch = current_branch
- @cedar = cedar
+ @cedar = options[:cedar]
+ @tests = options[:tests]
end
def deploy
@@ -21,7 +29,9 @@ def deploy
def pre_deploy
ensure_clean_git
- run_tests
+ if @tests
+ run_tests
+ end
package_assets
sync_github
end
View
9 lib/kumade/runner.rb
@@ -19,11 +19,11 @@ def self.deploy
@out.puts "==> In Pretend Mode"
end
@out.puts "==> Deploying to: #{environment}"
- Deployer.new(environment, pretending?, @options[:cedar]).deploy
+ Deployer.new(:environment => environment, :pretending => pretending?, :cedar => @options[:cedar], :tests => @options[:tests]).deploy
@out.puts "==> Deployed to: #{environment}"
end
- def self.parse_arguments!(args)
+ def self.parse_arguments!(args)
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: kumade <environment> [options]"
@@ -36,6 +36,10 @@ def self.parse_arguments!(args)
options[:cedar] = cedar
end
+ opts.on("-t", "--tests", "Use this to run tests before deploy") do |tests|
+ options[:tests] = tests
+ end
+
opts.on_tail('-v', '--version', 'Show version') do
@out.puts "kumade #{Kumade::VERSION}"
exit
@@ -53,5 +57,6 @@ def self.parse_arguments!(args)
def self.pretending?
@options[:pretend]
end
+
end
end
View
39 spec/kumade/deployer_spec.rb
@@ -1,19 +1,25 @@
require 'spec_helper'
describe Kumade::Deployer, "#pre_deploy" do
- before { subject.stub(:say) }
+ #before { subject.stub(:say) }
+
+ context "running tests first" do
+ subject { Kumade::Deployer.new(:tests => true) }
+ it "calls the correct methods in order" do
+ %w(
+ ensure_clean_git
+ run_tests
+ package_assets
+ sync_github
+ ).each do |task|
+ subject.should_receive(task).ordered.and_return(true)
+ end
- it "calls the correct methods in order" do
- %w(
- ensure_clean_git
- run_tests
- package_assets
- sync_github
- ).each do |task|
- subject.should_receive(task).ordered.and_return(true)
+ subject.pre_deploy
end
+ end
- subject.pre_deploy
+ context "without running tests first" do
end
it "syncs to github" do
@@ -111,7 +117,7 @@
describe Kumade::Deployer, "#sync_heroku" do
let(:environment) { 'my-env' }
- subject { Kumade::Deployer.new(environment) }
+ subject { Kumade::Deployer.new(:environment => environment) }
before { subject.stub(:say) }
context "when deploy branch exists" do
@@ -498,8 +504,7 @@ class More
end
context "when the remote points to Heroku" do
- subject { Kumade::Deployer.new(environment) }
-
+ subject { Kumade::Deployer.new(:environment => environment) }
it "does not print an error" do
subject.should_not_receive(:error)
@@ -515,7 +520,7 @@ class More
context "when the remote does not exist" do
- subject { Kumade::Deployer.new(environment) }
+ subject { Kumade::Deployer.new(:environment => environment) }
before { remove_remote(environment) }
it "prints an error" do
@@ -526,7 +531,7 @@ class More
end
context "when the remote does not point to Heroku" do
- subject { Kumade::Deployer.new(bad_environment) }
+ subject { Kumade::Deployer.new(:environment => bad_environment) }
it "prints an error" do
subject.should_receive(:error).with(%{Cannot deploy: "#{bad_environment}" remote does not point to Heroku})
@@ -556,7 +561,7 @@ class More
let(:app_name){ 'sushi' }
context "when on Cedar" do
- subject { Kumade::Deployer.new('staging', false, cedar = true) }
+ subject { Kumade::Deployer.new(:cedar => true) }
it "runs commands with `run`" do
subject.should_receive(:run_or_error).with("bundle exec heroku run rake --app #{app_name}", //)
@@ -565,7 +570,7 @@ class More
end
context "when not on Cedar" do
- subject { Kumade::Deployer.new('staging', false, cedar = false) }
+ subject { Kumade::Deployer.new(:cedar => false) }
it "runs commands without `run`" do
subject.should_receive(:run_or_error).with("bundle exec heroku rake --app #{app_name}", //)
View
2 spec/kumade/runner_spec.rb
@@ -30,7 +30,7 @@
it "uses cedar when run with #{cedar_arg}" do
deployer = double("deployer").as_null_object
Kumade::Deployer.should_receive(:new).
- with(anything, anything, true).
+ with(hash_including(:cedar => true)).
and_return(deployer)
subject.run([environment, cedar_arg], out)

0 comments on commit 4f68702

Please sign in to comment.