From b018a7776a1f7fda9278b36a99febf0d595ab8bf Mon Sep 17 00:00:00 2001 From: Rob Aldred Date: Mon, 17 Nov 2014 15:57:24 +0000 Subject: [PATCH 1/3] guard::guard deprecated, using guard::plugin --- guard-coffeescript.gemspec | 3 ++- lib/guard/coffeescript.rb | 15 ++++++++------- lib/guard/coffeescript/runner.rb | 15 +++++++-------- spec/guard/coffeescript_spec.rb | 25 +++++++++++++++++++------ spec/spec_helper.rb | 2 +- 5 files changed, 37 insertions(+), 23 deletions(-) diff --git a/guard-coffeescript.gemspec b/guard-coffeescript.gemspec index 18de441..2558fc2 100644 --- a/guard-coffeescript.gemspec +++ b/guard-coffeescript.gemspec @@ -21,7 +21,8 @@ Gem::Specification.new do |s| s.add_development_dependency 'bundler' s.add_development_dependency 'guard-rspec' - s.add_development_dependency 'rspec' + s.add_development_dependency 'rspec', '2.99.0' + s.add_development_dependency 'byebug' s.files = Dir.glob('{lib}/**/*') + %w[LICENSE README.md] s.require_path = 'lib' diff --git a/lib/guard/coffeescript.rb b/lib/guard/coffeescript.rb index a1b9cff..a1bdbd6 100644 --- a/lib/guard/coffeescript.rb +++ b/lib/guard/coffeescript.rb @@ -1,5 +1,5 @@ require 'guard' -require 'guard/guard' +require 'guard/plugin' require 'guard/watcher' module Guard @@ -7,7 +7,7 @@ module Guard # The CoffeeScript guard that gets notifications about the following # Guard events: `start`, `stop`, `reload`, `run_all` and `run_on_change`. # - class CoffeeScript < Guard + class CoffeeScript < Plugin autoload :Formatter, 'guard/coffeescript/formatter' autoload :Inspector, 'guard/coffeescript/inspector' @@ -25,10 +25,11 @@ class CoffeeScript < Guard # Initialize Guard::CoffeeScript. # - # @param [Array] watchers the watchers in the Guard block + # @param [Hash] options the options for the Guard # @option options [String] :input the input directory # @option options [String] :output the output directory + # @option options [Array] :watchers the watchers in the Guard block # @option options [Boolean] :bare do not wrap the output in a top level function # @option options [Boolean] :shallow do not create nested directories # @option options [Boolean] :hide_success hide success message notification @@ -36,16 +37,16 @@ class CoffeeScript < Guard # @option options [Boolean] :noop do not generate an output file # @option options [Boolean] :source_map generate the source map files # - def initialize(watchers = [], options = {}) - watchers = [] if !watchers + def initialize(options = {}) defaults = DEFAULT_OPTIONS.clone if options[:input] defaults.merge!({ :output => options[:input] }) - watchers << ::Guard::Watcher.new(%r{^#{ options[:input] }/(.+\.(?:coffee|coffee\.md|litcoffee))$}) + options[:watchers] = [] unless options[:watchers] + options[:watchers] << ::Guard::Watcher.new(%r{^#{ options[:input] }/(.+\.(?:coffee|coffee\.md|litcoffee))$}) end - super(watchers, defaults.merge(options)) + super(defaults.merge(options)) end # Gets called once when Guard starts. diff --git a/lib/guard/coffeescript/runner.rb b/lib/guard/coffeescript/runner.rb index 3358df1..03aa6fe 100644 --- a/lib/guard/coffeescript/runner.rb +++ b/lib/guard/coffeescript/runner.rb @@ -42,7 +42,7 @@ def run(files, watchers, options = { }) # def remove(files, watchers, options = { }) removed_files = [] - directories = detect_nested_directories(watchers, files, options) + directories = detect_nested_directories(files, watchers, options) directories.each do |directory, scripts| scripts.each do |file| @@ -76,15 +76,14 @@ def notify_start(files, options) # Compiles all CoffeeScript files and writes the JavaScript files. # - # @param [Array] files the files to compile - # @param [Array] watchers the Guard watchers in the block + # @param [Array] files the files to compile # @param [Hash] options the options for the execution # @return [Array, Array] the result for the compilation run # def compile_files(files, watchers, options) errors = [] changed_files = [] - directories = detect_nested_directories(watchers, files, options) + directories = detect_nested_directories(files, watchers, options) directories.each do |directory, scripts| scripts.each do |file| @@ -217,14 +216,14 @@ def javascript_file_name(file, directory) # Detects the output directory for each CoffeeScript file. Builds # the product of all watchers and assigns to each directory # the files to which it belongs to. - # - # @param [Array] watchers the Guard watchers in the block + # # @param [Array] files the CoffeeScript files - # @param [Hash] options the options for the execution + # @param [Array] watchers the Guard watchers in the block + # @param [Hash] options the options for the execution # @option options [String] :output the output directory # @option options [Boolean] :shallow do not create nested directories # - def detect_nested_directories(watchers, files, options) + def detect_nested_directories(files, watchers, options) return { options[:output] => files } if options[:shallow] directories = { } diff --git a/spec/guard/coffeescript_spec.rb b/spec/guard/coffeescript_spec.rb index c7559fb..de9bfa8 100644 --- a/spec/guard/coffeescript_spec.rb +++ b/spec/guard/coffeescript_spec.rb @@ -17,6 +17,12 @@ describe '#initialize' do context 'when no options are provided' do + it 'sets a default :watchers option' do + puts guard.options + guard.watchers.should be_a Array + guard.watchers.should be_empty + end + it 'sets a default :wrap option' do guard.options[:bare].should be_false end @@ -44,15 +50,22 @@ end context 'with options besides the defaults' do - let(:guard) { Guard::CoffeeScript.new(nil, { :output => 'output_folder', + let(:watcher) { Guard::Watcher.new('^x/.+\.(?:coffee|coffee\.md|litcoffee)$') } + + let(:guard) { Guard::CoffeeScript.new( { :output => 'output_folder', :bare => true, :shallow => true, :hide_success => true, :all_on_start => true, :noop => true, - :source_map => true + :source_map => true, + :watchers => [watcher] }) } + it 'sets the provided :watchers option' do + guard.watchers.should == [watcher] + end + it 'sets the provided :bare option' do guard.options[:bare].should be_true end @@ -79,7 +92,7 @@ end context 'with a input option' do - let(:guard) { Guard::CoffeeScript.new(nil, { :input => 'app/coffeescripts' }) } + let(:guard) { Guard::CoffeeScript.new( { :input => 'app/coffeescripts' }) } it 'creates a watcher' do guard.should have(1).watchers @@ -96,7 +109,7 @@ end context 'with an output option' do - let(:guard) { Guard::CoffeeScript.new(nil, { :input => 'app/coffeescripts', + let(:guard) { Guard::CoffeeScript.new( { :input => 'app/coffeescripts', :output => 'public/javascripts' }) } it 'keeps the output directory' do @@ -113,7 +126,7 @@ end context 'with the :all_on_start option' do - let(:guard) { Guard::CoffeeScript.new(nil, :all_on_start => true) } + let(:guard) { Guard::CoffeeScript.new( :all_on_start => true) } it 'calls #run_all' do guard.should_receive(:run_all) @@ -123,7 +136,7 @@ end describe '#run_all' do - let(:guard) { Guard::CoffeeScript.new([Guard::Watcher.new('^x/.+\.(?:coffee|coffee\.md|litcoffee)$')]) } + let(:guard) { Guard::CoffeeScript.new( { :watchers => [Guard::Watcher.new('^x/.+\.(?:coffee|coffee\.md|litcoffee)$')] } ) } before do Dir.stub(:glob).and_return ['x/a.coffee', 'x/b.coffee', 'y/c.coffee', 'x/d.coffeeemd', 'x/e.litcoffee'] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cc5b992..4d81991 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,7 +3,7 @@ RSpec.configure do |config| - config.color_enabled = true + config.color = true config.filter_run :focus => true config.run_all_when_everything_filtered = true From 010db9f641b128024e962852fedbc10bc1c72c5c Mon Sep 17 00:00:00 2001 From: Rob Aldred Date: Mon, 17 Nov 2014 15:59:28 +0000 Subject: [PATCH 2/3] removing debug output --- spec/guard/coffeescript_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/guard/coffeescript_spec.rb b/spec/guard/coffeescript_spec.rb index de9bfa8..c4530fe 100644 --- a/spec/guard/coffeescript_spec.rb +++ b/spec/guard/coffeescript_spec.rb @@ -18,7 +18,6 @@ describe '#initialize' do context 'when no options are provided' do it 'sets a default :watchers option' do - puts guard.options guard.watchers.should be_a Array guard.watchers.should be_empty end From 6db0f0a50db5c598c8c49fde2818f275a91fdfc8 Mon Sep 17 00:00:00 2001 From: Rob Aldred Date: Mon, 17 Nov 2014 16:37:57 +0000 Subject: [PATCH 3/3] remove debugger --- guard-coffeescript.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/guard-coffeescript.gemspec b/guard-coffeescript.gemspec index 2558fc2..af3bf82 100644 --- a/guard-coffeescript.gemspec +++ b/guard-coffeescript.gemspec @@ -22,7 +22,6 @@ Gem::Specification.new do |s| s.add_development_dependency 'bundler' s.add_development_dependency 'guard-rspec' s.add_development_dependency 'rspec', '2.99.0' - s.add_development_dependency 'byebug' s.files = Dir.glob('{lib}/**/*') + %w[LICENSE README.md] s.require_path = 'lib'