Permalink
Browse files

Basic setup of shoulda macros for setting up a structure

of bare git origin and two checkouts for unit tests
  • Loading branch information...
colszowka committed Jan 26, 2011
1 parent a18abe5 commit 81d17b8374d450687533f1f47ce3bb3b5dda3394
Showing with 85 additions and 2 deletions.
  1. +2 −1 .gitignore
  2. +2 −0 Gemfile.lock
  3. +1 −1 Rakefile
  4. +1 −0 capita_git.gemspec
  5. +7 −0 test/cli_test.rb
  6. +61 −0 test/shoulda_macros.rb
  7. +11 −0 test/test_helper.rb
View
@@ -2,4 +2,5 @@ pkg/*
*.gem
.bundle
.idea
-lib/capita_git/man
+lib/capita_git/man
+tmp/*
View
@@ -11,6 +11,7 @@ GEM
git (1.2.5)
hpricot (0.8.3)
mustache (0.12.0)
+ open4 (1.0.1)
rdiscount (1.6.5)
ronn (0.7.3)
hpricot (>= 0.8.2)
@@ -24,5 +25,6 @@ PLATFORMS
DEPENDENCIES
capita_git!
+ open4
ronn (>= 0.7.3)
shoulda (>= 2.11.0)
View
@@ -5,7 +5,7 @@ Bundler::GemHelper.install_tasks
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
- test.pattern = 'test/**/test_*.rb'
+ test.pattern = 'test/**/*_test.rb'
test.verbose = true
end
View
@@ -23,4 +23,5 @@ Gem::Specification.new do |s|
s.add_dependency('thor', '>= 0.14.6')
s.add_development_dependency('ronn', ">= 0.7.3")
s.add_development_dependency('shoulda', ">= 2.11.0")
+ s.add_development_dependency('open4')
end
View
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CliTest < Test::Unit::TestCase
+ with_a_repo_setup do
+
+ end
+end
View
@@ -0,0 +1,61 @@
+module ShouldaMacros
+ TEMP_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp'))
+
+ # Test method level helpers
+ module InstanceMethods
+ # Returns the path to the temporary directory, with the optional subdirectory
+ # Creates the directory if it's missing
+ def temp_dir(subdirectory = nil)
+ path = ShouldaMacros::TEMP_DIR
+ path = File.join(path, subdirectory) if subdirectory
+ FileUtils.mkdir_p(path)
+ path
+ end
+
+ # Switches current working directory to the temp_dir subdirectory of given
+ # name for the given block, switching back after execution
+ def in_dir(name)
+ Dir.chdir(temp_dir(name)) do
+ yield
+ end
+ end
+
+ # Runs the specified command and asserts it's exit status should be 0
+ def assert_command(cmd)
+ Open4.popen4(cmd) { |stdin, stdout, stderr| 'nothing to do' }
+ puts cmd, $?.inspect
+ assert_equal 0, $?.exitstatus, "Expected exit status of 0!"
+ end
+ end
+
+ # Context and should block helpers
+ module ClassMethods
+
+ #
+ # Creates a repository with a remote in temp_dir
+ #
+ def with_a_repo_setup
+ context "With a basic repo setup" do
+ setup do
+ in_dir 'origin' do
+ assert_command 'git init --bare'
+ end
+
+ in_dir "local_checkout_1" do
+ assert_command 'git init'
+ assert_command "echo 'foo bar commit' > README"
+ assert_command "git add . && git commit -m 'Initial commit'"
+ assert_command "git remote add origin #{temp_dir('origin')}"
+ assert_command 'git push origin master'
+ end
+
+ in_dir "local_checkout_2" do
+ assert_command "git clone #{temp_dir('origin')}"
+ end
+ end
+
+ should("do something...") { assert true }
+ end
+ end
+ end
+end
View
@@ -5,5 +5,16 @@
require 'test/unit'
require 'shoulda'
+require 'fileutils'
+require "open4" # See http://tech.natemurray.com/2007/03/ruby-shell-commands.html
+require 'shoulda_macros'
+
class Test::Unit::TestCase
+ include ShouldaMacros::InstanceMethods
+ extend ShouldaMacros::ClassMethods
+
+ # Make sure the temporary directory is purged after every run
+ def teardown
+ #FileUtils.rm_rf(temp_dir)
+ end
end

0 comments on commit 81d17b8

Please sign in to comment.