Permalink
Browse files

first cut

  • Loading branch information...
1 parent 32b093c commit 44c66f6a2f48560fa9c41077d94474c9bb5055f1 @marcisme committed May 15, 2012
View
@@ -0,0 +1,7 @@
+language: ruby
+rvm:
+ - 1.8.7
+ - 1.9.2
+ - 1.9.3
+ - jruby-18mode
+ - jruby-19mode
View
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in guard-copy-on-change.gemspec
+gemspec
View
@@ -0,0 +1,6 @@
+guard 'cucumber' do
+ watch(%r{^lib/.+\.rb$}) { 'features' }
+ watch(%r{^features/.+\.feature$})
+ watch(%r{^features/support/.+$}) { 'features' }
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
+end
View
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Marc Schwieterman
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,78 @@
+# Guard::Copy [![Build Status](https://secure.travis-ci.org/marcisme/guard-copy.png?branch=master)](http://travis-ci.org/marcisme/guard-copy)
+
+Copy guard copies files to one or more locations whenever files are
+created or modified.
+
+* Tested against Ruby 1.8.7, 1.9.2, 1.9.3, and the latest versions of JRuby
+
+## Installation
+
+Please be sure to have [Guard](https://github.com/guard/guard)
+installed.
+
+Install the gem:
+
+ $ gem install guard-copy
+
+Add guard definition to your Guardfile by running this command:
+
+ $ guard init copy
+
+## Usage
+
+Please read [Guard usage doc](https://github.com/guard/guard#readme)
+
+## Guardfile
+
+Copy guard can copy files from one source directory to one or more
+target directories identified either explicitly or with wildcards.
+
+### Single Target
+
+``` ruby
+guard :copy, :from => 'source', :to => 'target'
+```
+
+### Multiple Targets
+
+``` ruby
+guard :copy, :from => 'source', :to => ['t1', 't2']
+```
+
+### Newest Wildcard Target
+
+``` ruby
+guard :copy, :from => 'source', :to => 'target*', :glob => :newest
+```
+
+This guard will copy files from the source directory to the newest
+directory starting with 'target'.
+
+## Author
+
+[Marc Schwieterman](https://github.com/marcisme)
+
+## License
+
+Copyright (c) 2012 Marc Schwieterman
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,8 @@
+require 'bundler/gem_tasks'
+require 'cucumber/rake/task'
+
+Cucumber::Rake::Task.new do |t|
+ t.cucumber_opts = '--format progress'
+end
+
+task :default => :cucumber
View
@@ -0,0 +1,49 @@
+Feature: Copy files
+
+ In order to copy files to another location when I change them
+ As a developer
+ I want to use guard-copy
+
+ Scenario: Single target startup message
+ When I have run guard with this Guardfile:
+ """
+ guard :copy, :from => 'source', :to => 'target'
+ """
+ Then guard should report that "Guard::Copy will copy files from 'source' to 'target'"
+
+ Scenario: Copy a new file
+ Given a directory named "target"
+ And I have run guard with this Guardfile:
+ """
+ guard :copy, :from => 'source', :to => 'target'
+ """
+ When I create a file named "source/foo"
+ Then "source/foo" should be copied to "target/foo"
+
+ Scenario: Copy an updated file
+ Given a directory named "target"
+ And an empty file named "source/foo"
+ And I have run guard with this Guardfile:
+ """
+ guard :copy, :from => 'source', :to => 'target'
+ """
+ When I append to "source/foo" with "xyz"
+ Then "source/foo" should be copied to "target/foo"
+
+ Scenario: Non-existent target directory
+ Given a directory named "target" should not exist
+ And I have run guard with this Guardfile:
+ """
+ guard :copy, :from => 'source', :to => 'target'
+ """
+ When I create a file named "source/foo"
+ Then guard should report that "'target' does not match any directories"
+
+ Scenario: Target directory is a file
+ Given an empty file named "target"
+ And I have run guard with this Guardfile:
+ """
+ guard :copy, :from => 'source', :to => 'target'
+ """
+ When I create a file named "source/foo"
+ Then guard should report that "'target' is not a directory"
@@ -0,0 +1,16 @@
+Feature: Copy files to multiple targets
+
+ In order to copy files to multiple locations when I change them
+ As a developer
+ I want to use guard-copy
+
+ Scenario: Copy a file to two targets
+ Given a directory named "target_one"
+ And a directory named "target_two"
+ And I have run guard with this Guardfile:
+ """
+ guard :copy, :from => 'source', :to => ['target_one', 'target_two']
+ """
+ When I create a file named "source/foo"
+ Then "source/foo" should be copied to "target_one/foo"
+ And "source/foo" should be copied to "target_two/foo"
@@ -0,0 +1,39 @@
+Given /^I have run guard with this Guardfile:$/ do |guardfile_contents|
+ start_guard(guardfile_contents)
+end
+
+When /^I create a file named "([^"]*)"$/ do |file_name|
+ write_file(file_name, '23908afs3wja038wj3wff3wa')
+end
+
+Then /^"([^"]*)" should be copied to "([^"]*)"$/ do |from_path, to_path|
+ verify_guard_behavior do
+ File.should be_file(to_path)
+ IO.read(to_path).should == IO.read(from_path)
+ end
+end
+
+# This step should be used after the affirmative version to make sure guard
+# has processed the file system changes.
+Then /^"([^"]*)" should not be copied to "([^"]*)"$/ do |from_path, to_path|
+ verify_guard_behavior do
+ File.should_not be_file(to_path)
+ end
+end
+
+Then /^guard should report that "([^"]*)"$/ do |output|
+ verify_guard_behavior do
+ guard_output.should include(output)
+ end
+end
+
+Then /^the file "([^"]*)" should contain:$/ do |file, partial_content|
+ check_file_content(file, partial_content, true)
+end
+
+Given /^a directory named "([^"]*)" created in (\d+)$/ do |dir, year|
+ create_dir(dir)
+ in_current_dir do
+ FileUtils.touch(dir, :mtime => Time.utc(year))
+ end
+end
View
@@ -0,0 +1,5 @@
+require 'bundler/setup'
+require 'aruba/cucumber'
+require 'guard/copy'
+
+After { terminate_processes! }
@@ -0,0 +1,33 @@
+require 'aruba/api'
+
+module GuardHelper
+
+ GUARD_CMD = 'guard start'
+
+ def start_guard(guardfile_contents)
+ write_file('Guardfile', guardfile_contents)
+ run_interactive(unescape(GUARD_CMD))
+ sleep 0.1 until output_from(GUARD_CMD).include?('Guard is now watching')
+ end
+
+ def verify_guard_behavior(max_tries = 10)
+ tries = 0
+ begin
+ in_current_dir { yield }
+ rescue => e
+ if (tries += 1) < max_tries
+ sleep 0.1
+ retry
+ else
+ raise e
+ end
+ end
+ end
+
+ def guard_output
+ output_from(GUARD_CMD)
+ end
+
+end
+
+World(GuardHelper)
View
@@ -0,0 +1,16 @@
+Feature: Configure guard-copy
+
+ In order to have a default configuration added to my Guardfile
+ As a developer
+ I want to initialize guard-copy
+
+ Scenario: Guardfile template
+ When I run `guard init copy`
+ Then the file "Guardfile" should contain:
+ """
+ # Any files created or modified in the 'source' directory
+ # will be copied to the 'target' directory. Update the
+ # guard as appropriate for your needs.
+
+ guard :copy, :from => 'source', :to => 'target'
+ """
View
@@ -0,0 +1,27 @@
+Feature: Wildcard target directories
+
+ In order to copy files to directories identified by wildcards
+ As a developer
+ I want to use guard-copy
+
+ Scenario: Wildcard target
+ Given a directory named "target_one"
+ And a directory named "target_two"
+ And I have run guard with this Guardfile:
+ """
+ guard :copy, :from => 'source', :to => 'target*'
+ """
+ When I create a file named "source/foo"
+ Then "source/foo" should be copied to "target_one/foo"
+ And "source/foo" should be copied to "target_two/foo"
+
+ Scenario: Newest duplicate option
+ Given a directory named "target_older" created in 1978
+ And a directory named "target_newer" created in 2012
+ And I have run guard with this Guardfile:
+ """
+ guard :copy, :from => 'source', :to => 'target*', :glob => :newest
+ """
+ When I create a file named "source/foo"
+ Then "source/foo" should be copied to "target_newer/foo"
+ And "source/foo" should not be copied to "target_older/foo"
View
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path('../lib', __FILE__)
+require 'guard/copy/version'
+
+Gem::Specification.new do |gem|
+ gem.name = 'guard-copy'
+ gem.version = Guard::CopyVersion::VERSION
+ gem.authors = ['Marc Schwieterman']
+ gem.email = ['marc.schwieterman@gmail.com']
+ gem.homepage = 'https://github.com/marcisme/guard-copy'
+ gem.summary = 'Guard gem for copy'
+ gem.description = 'Guard::Copy automatically copies files.'
+
+ gem.add_dependency 'guard', '~> 1.0'
+
+ gem.add_development_dependency 'bundler', '>= 1.1.0'
+ gem.add_development_dependency 'aruba', '~> 0.4'
+ gem.add_development_dependency 'guard-cucumber', '>= 0.8'
+
+ gem.files = Dir.glob('{lib}/**/*') + %w[LICENSE README.md]
+ gem.require_path = 'lib'
+end
Oops, something went wrong.

0 comments on commit 44c66f6

Please sign in to comment.