Permalink
Browse files

Added cucumber tests for the deploy tasks

Started adding test coverage as I build the gem and refactor some
of the tasks. Incomplete at present but will expand over the next few commits.
  • Loading branch information...
1 parent 20808b4 commit b3f9ec0fa700410014a9937fc6985e140c60098e @alistairstead committed Mar 8, 2012
View
@@ -0,0 +1,9 @@
+Feature: Deployment
+ In order to deploy Magento
+ As a developer
+ I want my release to be uploaded and symlinks to shared resources created
+
+ Scenario: User runs $ cap deploy
+ Given an app
+ When I execute deploy
+ Then the PEOPLE_LIKE_YOU file should be written to shared
View
@@ -0,0 +1,14 @@
+Feature: Magentify
+ In order to deploy Magento with Capistrano
+ As a developer
+ I want my project to be configured to use Magento specific deploy tasks
+
+ Scenario: User runs $ magentify .
+ Given an app
+ When I execute magentify .
+ Then deploy.rb should load mage.rb
+
+ Scenario: User runs $ cap -T
+ Given an app
+ When I execute cap -T
+ Then cap -T should list mage
View
@@ -0,0 +1,9 @@
+Feature: Setup
+ In order to deploy Magento
+ As a developer
+ I want the correct folder structure created on the remote server
+
+ Scenario: User runs $ cap deploy:setup
+ Given an app
+ When I execute deploy:setup
+ Then the shared folder structure should be created
@@ -0,0 +1,38 @@
+Given /^an app$/ do
+ # Create the git repo
+ FileUtils.mkdir_p @repo_dir
+ Dir.chdir(@repo_dir) do
+ system "git --bare init > /dev/null 2>&1"
+ end
+
+ # Create and capify the dummy app, and push it to the local repo
+ FileUtils.mkdir_p @app_dir
+ Dir.chdir(@app_dir) do
+ [
+ %Q{git init > /dev/null 2>&1} ,
+ %Q{mkdir config > /dev/null 2>&1},
+ %Q{magentify . > /dev/null 2>&1},
+ %Q{git add . > /dev/null 2>&1},
+ %Q{git commit -m "first commit" > /dev/null 2>&1},
+ %Q{git remote add origin file://#{@repo_dir} > /dev/null 2>&1},
+ %Q{git push origin master > /dev/null 2>&1}
+ ].each do |command|
+ system command
+ end
+ end
+
+ # Write a custom deploy file to the app, using an ERB template
+ deploy_variables = {
+ :deploy_to => File.join(@test_files_dir, "deployed"),
+ :repository => @repo_dir,
+ :git_executable => `which git`.strip,
+ :logged_in_user => Etc.getlogin
+ }
+
+ template_path = File.expand_path(File.join(__FILE__, "..", "..", "templates", "deploy.erb"))
+ compiled_template = ERB.new(File.read(template_path)).result(binding)
+
+ File.open(File.join(@app_dir, "config", "deploy.rb"), 'w') {|f|
+ f.write compiled_template
+ }
+end
@@ -0,0 +1,10 @@
+When /^I execute deploy$/ do
+ Dir.chdir(@app_dir) do
+ system "cap deploy:setup > /dev/null"
+ system "cap deploy > /dev/null"
+ end
+end
+
+Then /^the PEOPLE_LIKE_YOU file should be written to shared$/ do
+ File.exists?(File.join(@test_files_dir, "deployed", "shared", "PEOPLE_LIKE_YOU")).should be_true
+end
@@ -0,0 +1,19 @@
+When /^I execute magentify \.$/ do
+ Dir.chdir(@app_dir) do
+ system "magentify . > /dev/null"
+ end
+end
+
+Then /^deploy\.rb should load mage\.rb$/ do
+ pending # express the regexp above with the code you wish you had
+end
+
+When /^I execute cap \-T$/ do
+ Dir.chdir(@app_dir) do
+ system "cap -T > /dev/null"
+ end
+end
+
+Then /^cap \-T should list mage$/ do
+ pending # express the regexp above with the code you wish you had
+end
@@ -0,0 +1,9 @@
+When /^I execute deploy:setup$/ do
+ Dir.chdir(@app_dir) do
+ system "cap deploy:setup > /dev/null"
+ end
+end
+
+Then /^the shared folder structure should be created$/ do
+ pending # express the regexp above with the code you wish you had
+end
View
@@ -0,0 +1,12 @@
+# require 'spec'
+require 'erb'
+require 'etc'
+
+Before do
+ @test_files_dir = File.join(Dir.pwd, "_files")
+ @app_dir = File.join(@test_files_dir, "app")
+ @repo_dir = File.join(@test_files_dir, "repo")
+
+ FileUtils.rm_r(@test_files_dir) if File.exists?(@test_files_dir)
+ FileUtils.mkdir_p(@test_files_dir)
+end
@@ -0,0 +1,19 @@
+set :application, "magento"
+set :domain, "#{application}.com"
+set :deploy_to, "<%= deploy_variables[:deploy_to] %>"
+
+set :user, "<%= deploy_variables[:logged_in_user] %>"
+set :repository, "file://<%= deploy_variables[:repository] %>"
+set :scm, :git
+# Or: `accurev`, `bzr`, `cvs`, `darcs`, `subversion`, `mercurial`, `perforce`, `subversion` or `none`
+set :scm_command, "<%= deploy_variables[:git_executable] %>"
+
+role :web, "localhost" # Your HTTP server, Apache/etc
+role :app, "localhost" # This may be the same as your `Web` server
+role :db, "localhost", :primary => true # This is where Rails migrations will run
+
+set :keep_releases, 3
+
+set :app_symlinks, ["/media", "/var", "/sitemaps", "/staging"]
+set :app_shared_dirs, ["/app/etc", "/sitemaps", "/media", "/var", "/staging"]
+set :app_shared_files, ["/app/etc/local.xml"]

0 comments on commit b3f9ec0

Please sign in to comment.