Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote branch 'tsigo/cucumber' into specing

  • Loading branch information...
commit cec9d1f0b33379e8784199a6b1ebc14563c3ac4b 2 parents 696d607 + beb69c1
@pepe pepe authored
View
3  README.markdown
@@ -64,6 +64,5 @@ Gitploy is super alpha - don't use it yet, unless you're just that baller. Are y
### Known issues
-* No tests :(
* Not enough documentation
-* DSL implementation is pretty dumb and needs refactoring
+* DSL implementation is pretty dumb and needs refactoring
View
63 features/gitploy.feature
@@ -0,0 +1,63 @@
+Feature: gitploy
+
+ Scenario Outline: Missing options
+ Given an invalid configuration file
+ When I run "gitploy <arguments>"
+ Then the output should contain:
+ """
+ The following configuration options are missing for the 'staging' stage: path, user, host
+ """
+ Examples:
+ | arguments |
+ | staging setup |
+ | staging |
+
+ Scenario Outline: Pretend execution
+ Given a valid configuration file
+ When I run "gitploy <arguments>"
+ Then the output should contain "(pretend)"
+ Examples:
+ | arguments |
+ | staging setup --pretend |
+ | staging setup -p |
+ | staging --pretend |
+ | staging -p |
+
+ Scenario: Setup on staging
+ Given a valid configuration file
+ When I run "gitploy staging setup --pretend"
+ Then the output should contain "Setup local"
+ And the output should contain "ssh staging@staging.gitploy.foo"
+ And the output should contain "mkdir -p /var/www/fooapp"
+ And the output should contain "cd /var/www/fooapp && git init"
+ But the output should not contain "Deploy local"
+ And the output should not contain "ssh production@gitploy.foo"
+ And the output should not contain "bundle install"
+
+ Scenario: Deploy on staging
+ Given a valid configuration file
+ When I run "gitploy staging --pretend"
+ Then the output should contain "git push"
+ And the output should contain "Deploy local"
+ And the output should contain "cd /var/www/fooapp"
+ And the output should contain "git reset --hard"
+ But the output should not contain "Setup local"
+ And the output should not contain "ssh production@gitploy.foo"
+
+ Scenario: Setup on production
+ Given a valid configuration file
+ When I run "gitploy production setup --pretend"
+ Then the output should contain "Setup local"
+ And the output should contain "production@gitploy.foo"
+ But the output should not contain "Deploy local"
+ And the output should not contain "staging@staging.gitploy.foo"
+ And the output should not contain "git push"
+
+ Scenario: Deploy on production
+ Given a valid configuration file
+ When I run "gitploy production --pretend"
+ Then the output should contain "Deploy local"
+ And the output should contain "production@gitploy.foo"
+ And the output should contain "git push"
+ But the output should not contain "Setup local"
+ And the output should not contain "staging@staging.gitploy.foo"
View
58 features/step_definitions/gitploy_steps.rb
@@ -0,0 +1,58 @@
+Given /^an invalid configuration file$/ do
+ Given %{a file named "config/deploy.rb" with:},
+ """
+ require 'gitploy/script'
+ configure do |c|
+ stage :staging do
+ end
+ end
+ """
+end
+
+Given /^a valid configuration file$/ do
+ Given %{a file named "config/deploy.rb" with:},
+ <<-CODE
+ require 'gitploy/script'
+
+ configure do |c|
+ c.path = '/var/www/fooapp'
+ c.local_branch = 'master'
+ c.remote_branch = 'master'
+
+ stage :staging do
+ c.host = 'staging.gitploy.foo'
+ c.user = 'staging'
+ end
+
+ stage :production do
+ c.host = 'gitploy.foo'
+ c.user = 'production'
+ end
+ end
+
+ setup do
+ local do
+ run "echo 'Setup local'"
+ end
+ remote do
+ run "mkdir -p /var/www/fooapp"
+ run "cd /var/www/fooapp && git init"
+ run "git config --bool receive.denyNonFastForwards false"
+ run "git config receive.denyCurrentBranch ignore"
+ end
+ end
+
+ deploy do
+ push!
+ local do
+ run "echo 'Deploy local'"
+ end
+ remote do
+ run "cd /var/www/fooapp"
+ run "git reset --hard"
+ run "bundle install --deployment"
+ run "touch tmp/restart.txt"
+ end
+ end
+ CODE
+end
View
15 features/support/env.rb
@@ -0,0 +1,15 @@
+require 'rubygems'
+require 'aruba'
+require 'fileutils'
+
+Before do
+ FileUtils.rm_rf("tmp")
+ FileUtils.mkdir("tmp")
+end
+
+PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')).freeze
+BIN_PATH = File.join(PROJECT_ROOT, 'bin').freeze
+LIB_PATH = File.join(PROJECT_ROOT, 'lib').freeze
+
+ENV['PATH'] = [BIN_PATH, ENV['PATH']].join(':')
+ENV['RUBYLIB'] = LIB_PATH
View
10 lib/gitploy.rb
@@ -41,7 +41,7 @@ def stage(name)
end
def deploy
- yield if action.nil? || action == 'deploy'
+ yield unless action == 'setup'
end
def setup
@@ -82,13 +82,14 @@ def pretty_run(title, cmd)
print_bar(100, title)
puts "> #{cmd}"
puts
- Kernel.system(cmd)
+ Kernel.system(cmd) unless pretend?
print_bar(100)
end
#FIXME move to representation class
def print_bar(width, title=nil)
if title
+ title += " (pretend)" if pretend?
half_width = (width / 2) - (title.length / 2) - 2
left_bar = '=' * half_width
right_bar = '=' * (title.length % 2 == 0 ? half_width : half_width - 1) # TODO: lame.
@@ -115,4 +116,9 @@ def current_branch
'master'
end
end
+
+ def pretend?
+ pretend = %w(-p --pretend)
+ ARGV.any? { |v| pretend.include? v }
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.