Skip to content
This repository has been archived by the owner on Jul 4, 2022. It is now read-only.

Cucumber features #2

Merged
11 commits merged into from Nov 13, 2010
Merged
4 changes: 1 addition & 3 deletions README.markdown
Expand Up @@ -19,7 +19,6 @@ strategy. No hooks, very little behind-the-scenes magic - it just does what you
require 'gitploy/script'

configure do |c|
c.repo = 'git@github.com:myuser/fooapp.git'
c.path = '/var/www/fooapp'

stage :staging do
Expand Down Expand Up @@ -65,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
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.2.0
0.2.1
63 changes: 63 additions & 0 deletions 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"
58 changes: 58 additions & 0 deletions 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
15 changes: 15 additions & 0 deletions 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
4 changes: 2 additions & 2 deletions gitploy.gemspec
Expand Up @@ -5,11 +5,11 @@

Gem::Specification.new do |s|
s.name = %q{gitploy}
s.version = "0.2.0"
s.version = "0.2.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Brent Dillingham"]
s.date = %q{2010-09-14}
s.date = %q{2010-09-29}
s.default_executable = %q{gitploy}
s.description = %q{Dead-simple deployments. No, for real this time.}
s.email = %q{brentdillingham@gmail.com}
Expand Down
12 changes: 9 additions & 3 deletions lib/gitploy.rb
Expand Up @@ -3,7 +3,7 @@ module Gitploy
attr_accessor :config

class Config
REQUIRED_OPTIONS = [:repo, :path, :user, :host]
REQUIRED_OPTIONS = [:path, :user, :host]
attr_accessor *REQUIRED_OPTIONS
attr_accessor :local_branch, :remote_branch

Expand Down Expand Up @@ -41,7 +41,7 @@ def stage(name)
end

def deploy
yield if action.nil? || action == 'deploy'
yield unless action == 'setup'
end

def setup
Expand Down Expand Up @@ -81,12 +81,13 @@ def pretty_run(title, cmd)
print_bar(100, title)
puts "> #{cmd}"
puts
Kernel.system(cmd)
Kernel.system(cmd) unless pretend?
print_bar(100)
end

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.
Expand All @@ -113,4 +114,9 @@ def current_branch
'master'
end
end

def pretend?
pretend = %w(-p --pretend)
ARGV.any? { |v| pretend.include? v }
end
end