From 76bee65475eae3e56005c245c4b172656183f777 Mon Sep 17 00:00:00 2001 From: Jeremy Cook Date: Sun, 5 Jan 2014 10:44:46 -0500 Subject: [PATCH 1/7] Updated gems to use test_construct, removing warning message. --- Gemfile | 2 +- spec/spec_helper.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index c4e733d..c93af3b 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ group :development do gem "jeweler", ">= 1.6.2" gem "rcov", :platforms => :mri_18 gem "simplecov", :platforms => :mri_19 - gem "test-construct" + gem "test_construct" gem "capture-output", "~> 1.0.0" if RUBY_VERSION >= '1.9.2' gem "rubocop" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 22fd155..e594897 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,11 +3,11 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'homesick' require 'rspec' require 'rspec/autorun' -require 'construct' +require 'test_construct' require 'tempfile' RSpec.configure do |config| - config.include Construct::Helpers + config.include TestConstruct::Helpers config.before { ENV['HOME'] = home.to_s } From 264d5868635818af7ced1e40b5cd920d6cb4d448 Mon Sep 17 00:00:00 2001 From: Jeremy Cook Date: Sun, 5 Jan 2014 10:53:39 -0500 Subject: [PATCH 2/7] Updated tests to remove shell output from test results. --- spec/homesick_spec.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 830f2ca..0c3084c 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -23,6 +23,7 @@ describe 'homesick' do expect($stdout).to receive(:print) expect($stdin).to receive(:gets).and_return('y') + expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval', kind_of(Pathname)) homesick.clone local_repo castles.join('some_repo').join('testing').should exist @@ -55,8 +56,10 @@ describe 'homesick' do it 'should clone git repo like file:///path/to.git' do bare_repo = File.join(create_construct.to_s, 'dotfiles.git') system "git init --bare #{bare_repo} >/dev/null 2>&1" - - homesick.clone "file://#{bare_repo}" + # Capture stderr to suppress message about cloning an empty repo. + Capture.stderr do + homesick.clone "file://#{bare_repo}" + end File.directory?(File.join(home.to_s, '.homesick/repos/dotfiles')).should be_true end @@ -116,6 +119,7 @@ describe 'homesick' do file << "File.open(Dir.pwd + '/testing', 'w') { |f| f.print 'testing' }" end + expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval', kind_of(Pathname)) homesick.rc castle castle.join('testing').should exist @@ -133,6 +137,7 @@ describe 'homesick' do file << "File.open(Dir.pwd + '/testing', 'w') { |f| f.print 'testing' }" end + expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval skip', /not evaling.+/, :blue) homesick.rc castle castle.join('testing').should_not exist From 148d18565fa23ae568f82b56ee77b05718a9af46 Mon Sep 17 00:00:00 2001 From: Jeremy Cook Date: Thu, 2 Jan 2014 10:27:11 -0500 Subject: [PATCH 3/7] Added tests for untested methods. --- spec/homesick_spec.rb | 55 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 0c3084c..c5dad79 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -363,9 +363,26 @@ describe 'homesick' do end describe 'diff' do + it 'should output an empty message when there are no changes to commit' do + given_castle('castle_repo') + some_rc_file = home.file '.some_rc_file' + homesick.track(some_rc_file.to_s, 'castle_repo') + Capture.stdout { homesick.commit 'castle_repo', 'Adding a file to the test' } + text = Capture.stdout { homesick.diff('castle_repo') } + text.should eq('') + end - xit 'needs testing' - + it 'should output a diff message when there are changes to commit' do + given_castle('castle_repo') + some_rc_file = home.file '.some_rc_file' + homesick.track(some_rc_file.to_s, 'castle_repo') + Capture.stdout { homesick.commit 'castle_repo', 'Adding a file to the test' } + File.open(some_rc_file.to_s, 'w') do |file| + file.puts "Some test text" + end + text = Capture.stdout { homesick.diff('castle_repo') } + text.should =~ /diff --git.+Some test text$/m + end end describe 'show_path' do @@ -379,19 +396,43 @@ describe 'homesick' do end describe 'pull' do + it 'should perform a pull, submodule init and update when the given castle exists' do + given_castle('castle_repo') + homesick.stub(:system).once.with('git pull --quiet') + homesick.stub(:system).once.with('git submodule --quiet init') + homesick.stub(:system).once.with('git submodule --quiet update --init --recursive >/dev/null 2>&1') + homesick.pull 'castle_repo' + end - xit 'needs testing' + it 'should print an error message when trying to pull a non-existant castle' do + homesick.should_receive("say_status").once.with(:error, /Could not pull castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red) + expect { homesick.pull "castle_repo" }.to raise_error(SystemExit) + end describe '--all' do - xit 'needs testing' + it 'should pull each castle when invoked with --all' do + given_castle('castle_repo') + given_castle('glencairn') + homesick.stub(:system).exactly(2).times.with('git pull --quiet') + homesick.stub(:system).exactly(2).times.with('git submodule --quiet init') + homesick.stub(:system).exactly(2).times.with('git submodule --quiet update --init --recursive >/dev/null 2>&1') + Capture.stdout { Capture.stderr { homesick.invoke 'pull', [], all: true } } + end end end describe 'push' do + it 'should perform a git push on the given castle' do + given_castle('castle_repo') + homesick.stub(:system).once.with('git push') + homesick.push 'castle_repo' + end - xit 'needs testing' - + it 'should print an error message when trying to push a non-existant castle' do + homesick.should_receive("say_status").once.with(:error, /Could not push castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red) + expect { homesick.push "castle_repo" }.to raise_error(SystemExit) + end end describe 'track' do @@ -560,7 +601,7 @@ describe 'homesick' do it "returns an error message when the $EDITOR environment variable is not set" do ENV.stub(:[]).with('EDITOR').and_return(nil) # Set the default editor to make sure it fails. - homesick.should_receive("say_status").once.with(:error,"The $EDITOR environment variable must be set to use this command", :red) + homesick.should_receive("say_status").once.with(:error, "The $EDITOR environment variable must be set to use this command", :red) expect { homesick.open "castle_repo" }.to raise_error(SystemExit) end From df8f6b1cb0281bbc6ca755b0b39e26e0dd01c5d8 Mon Sep 17 00:00:00 2001 From: Jeremy Cook Date: Sun, 5 Jan 2014 14:27:52 -0500 Subject: [PATCH 4/7] Added command to display current version of homesick. --- Rakefile | 3 ++- lib/homesick.rb | 10 ++++++++++ lib/homesick/version.rb | 10 ++++++++++ spec/homesick_spec.rb | 7 +++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 lib/homesick/version.rb diff --git a/Rakefile b/Rakefile index 996e98e..b55731d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,6 @@ require 'rubygems' require 'bundler' +require_relative 'lib/homesick/version' begin Bundler.setup(:default, :development) rescue Bundler::BundlerError => e @@ -23,7 +24,7 @@ Jeweler::Tasks.new do |gem| gem.email = ["josh@technicalpickles.com", "info@muratayusuke.com"] gem.homepage = "http://github.com/technicalpickles/homesick" gem.authors = ["Joshua Nichols", "Yusuke Murata"] - gem.version = "0.9.7" + gem.version = Homesick::Version::STRING gem.license = "MIT" # Have dependencies? Add them to Gemfile diff --git a/lib/homesick.rb b/lib/homesick.rb index eb19073..039de4a 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -4,9 +4,11 @@ require 'thor' class Homesick < Thor autoload :Shell, 'homesick/shell' autoload :Actions, 'homesick/actions' + autoload :Version, 'homesick/version' include Thor::Actions include Homesick::Actions + include Homesick::Version add_runtime_options! @@ -15,6 +17,9 @@ class Homesick < Thor DEFAULT_CASTLE_NAME = 'dotfiles' + map '-v' => :version + map '--version' => :version + def initialize(args = [], options = {}, config = {}) super self.shell = Homesick::Shell.new @@ -264,6 +269,11 @@ class Homesick < Thor end end + desc 'version', 'Display the current version of homesick' + def version + say Homesick::Version::STRING + end + protected def home_dir diff --git a/lib/homesick/version.rb b/lib/homesick/version.rb new file mode 100644 index 0000000..8e372a2 --- /dev/null +++ b/lib/homesick/version.rb @@ -0,0 +1,10 @@ +# -*- encoding : utf-8 -*- +class Homesick + module Version + MAJOR = 0 + MINOR = 9 + PATCH = 8 + + STRING = "#{MAJOR}.#{MINOR}.#{PATCH}" + end +end diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index c5dad79..91a132a 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -611,4 +611,11 @@ describe 'homesick' do expect { homesick.open "castle_repo" }.to raise_error(SystemExit) end end + + describe 'version' do + it 'should print the current version of homesick' do + text = Capture.stdout { homesick.version } + text.chomp.should =~ /\d+\.\d+\.\d+/ + end + end end From 6e25f13e06d234d633fe92a8e0a5cd774bf30c11 Mon Sep 17 00:00:00 2001 From: Jeremy Cook Date: Thu, 9 Jan 2014 17:45:05 -0500 Subject: [PATCH 5/7] Added libnotify Gem on *nix systems in case people want to use it for Guard notifications. --- Gemfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Gemfile b/Gemfile index c93af3b..e92684c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,4 @@ +require 'rbconfig' source 'https://rubygems.org' # Add dependencies required to use your gem here. @@ -16,6 +17,9 @@ group :development do gem "simplecov", :platforms => :mri_19 gem "test_construct" gem "capture-output", "~> 1.0.0" + if RbConfig::CONFIG['host_os'] =~ /linux|freebsd|openbsd|sunos|solaris/ + gem 'libnotify' + end if RUBY_VERSION >= '1.9.2' gem "rubocop" end From 8a537b8204ce7bc52cd21bc6fc8429eb38e46509 Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Mon, 6 Jan 2014 21:20:01 -0500 Subject: [PATCH 6/7] Add gem version, dependency status, and code quality badges to the readme --- README.markdown | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.markdown b/README.markdown index 48c8000..6aad8d0 100644 --- a/README.markdown +++ b/README.markdown @@ -1,6 +1,9 @@ # homesick +[![Gem Version](https://badge.fury.io/rb/homesick.png)](http://badge.fury.io/rb/homesick) [![Build Status](https://travis-ci.org/technicalpickles/homesick.png?branch=master)](https://travis-ci.org/technicalpickles/homesick) +[![Dependency Status](https://gemnasium.com/technicalpickles/homesick.png)](https://gemnasium.com/technicalpickles/homesick) +[![Code Climate](https://codeclimate.com/github/technicalpickles/homesick.png)](https://codeclimate.com/github/technicalpickles/homesick) Your home directory is your castle. Don't leave your dotfiles behind. From 5fa0fc037c618af1b35f31049f55caaa14125811 Mon Sep 17 00:00:00 2001 From: Jeremy Cook Date: Thu, 9 Jan 2014 22:38:47 -0500 Subject: [PATCH 7/7] Updated README for .homesickrc. --- README.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 6aad8d0..1069de3 100644 --- a/README.markdown +++ b/README.markdown @@ -34,11 +34,11 @@ You can remove symlinks anytime when you don't need them anymore homesick unlink pickled-vim -If you need to add further configuration steps you can add these in a file called '.homesickrc' in the root of a castle. Once you've cloned a castle with one of these files apply these steps with: +If you need to add further configuration steps you can add these in a file called '.homesickrc' in the root of a castle. Once you've cloned a castle with a .homesickrc run the configuration with: homesick rc CASTLE -The contents of the .homesickrc file must be valid Ruby code as the file will be executed with Ruby's eval construct. +The contents of the .homesickrc file must be valid Ruby code as the file will be executed with Ruby's eval construct. The .homesickrc is also passed the current homesick object during its execution and this is available within the .homesickrc file as the 'self' variable. If you're not sure what castles you have around, you can easily list them: