Added new tests for status and commit

This commit is contained in:
Jeremy Cook
2013-12-27 17:04:34 -05:00
parent c432b27c92
commit 8f67188c19
5 changed files with 38 additions and 15 deletions

View File

@@ -15,6 +15,7 @@ group :development do
gem "rcov", :platforms => :mri_18
gem "simplecov", :platforms => :mri_19
gem "test-construct"
gem "capture-output", "~> 1.0.0"
if RUBY_VERSION >= '1.9.2'
gem "rubocop"
end

View File

@@ -90,9 +90,9 @@ class Homesick < Thor
end
desc 'commit CASTLE', "Commit the specified castle's changes"
def commit(name = DEFAULT_CASTLE_NAME)
commit_castle name
desc 'commit CASTLE MESSAGE', "Commit the specified castle's changes"
def commit(name = DEFAULT_CASTLE_NAME, message = nil)
commit_castle name, message
end
@@ -289,10 +289,10 @@ class Homesick < Thor
end
end
def commit_castle(castle)
def commit_castle(castle, message)
check_castle_existance(castle, 'commit')
inside repos_dir.join(castle) do
git_commit_all
git_commit_all :message => message
end
end
@@ -397,7 +397,7 @@ class Homesick < Thor
home_path = home_dir.join(relative_dir).join(path)
yield(absolute_path, home_path)
end
end
end
end

View File

@@ -64,7 +64,11 @@ class Homesick
def git_commit_all(config = {})
say_status 'git commit all', '', :green unless options[:quiet]
system 'git commit -v -a' unless options[:pretend]
if config[:message]
system "git commit -a -m '#{config[:message]}'" unless options[:pretend]
else
system 'git commit -v -a' unless options[:pretend]
end
end
def git_add(file, config = {})

View File

@@ -1,5 +1,6 @@
# -*- encoding : utf-8 -*-
require 'spec_helper'
require 'capture-output'
describe 'homesick' do
let(:home) { create_construct }
@@ -341,9 +342,19 @@ describe 'homesick' do
end
describe 'status' do
it 'should say "nothing to commit" when there are no changes' do
given_castle('castle_repo')
text = Capture.stdout { homesick.status('castle_repo') }
text.should =~ /nothing to commit \(create\/copy files and use "git add" to track\)$/
end
xit 'needs testing'
it 'should say "Changes to be committed" when there are changes' do
given_castle('castle_repo')
some_rc_file = home.file '.some_rc_file'
homesick.track(some_rc_file.to_s, 'castle_repo')
text = Capture.stdout { homesick.status('castle_repo') }
text.should =~ /Changes to be committed:.*new file:\s*home\/.some_rc_file/m
end
end
describe 'diff' do
@@ -372,12 +383,6 @@ describe 'homesick' do
end
describe 'commit' do
xit 'needs testing'
end
describe 'push' do
xit 'needs testing'
@@ -448,6 +453,16 @@ describe 'homesick' do
end
end
describe 'commit' do
it 'should have a commit message when the commit succeeds' do
given_castle('castle_repo')
some_rc_file = home.file '.a_random_rc_file'
homesick.track(some_rc_file.to_s, 'castle_repo')
text = Capture.stdout { homesick.commit('castle_repo', 'Test message') }
text.should =~ /^\[master \(root-commit\) \w+\] Test message/
end
end
describe 'subdir_file' do
it 'should add the nested files parent to the subdir_file' do

View File

@@ -4,6 +4,7 @@ require 'homesick'
require 'rspec'
require 'rspec/autorun'
require 'construct'
require 'tempfile'
RSpec.configure do |config|
config.include Construct::Helpers
@@ -21,6 +22,8 @@ RSpec.configure do |config|
castles.directory(path) do |castle|
Dir.chdir(castle) do
system 'git init >/dev/null 2>&1'
system 'git config user.email "test@test.com"'
system 'git config user.name "Test Name"'
system "git remote add origin git://github.com/technicalpickles/#{name}.git >/dev/null 2>&1"
if subdirs
subdir_file = castle.join(Homesick::SUBDIR_FILENAME)