From 1c3ba8d126f0b6fb6695c3961d33b33829587371 Mon Sep 17 00:00:00 2001 From: Michael Schaefermeyer Date: Sun, 28 Apr 2013 11:43:18 +0200 Subject: [PATCH 1/7] Add Guard --- Guardfile | 24 ++++++++++++++++++++++++ stasis.gemspec | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 Guardfile diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..f547850 --- /dev/null +++ b/Guardfile @@ -0,0 +1,24 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +guard 'rspec' do + watch(%r{^spec/.+_spec\.rb$}) + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch('spec/spec_helper.rb') { "spec" } + + # Rails example + watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } + watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } + watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } + watch(%r{^spec/support/(.+)\.rb$}) { "spec" } + watch('config/routes.rb') { "spec/routing" } + watch('app/controllers/application_controller.rb') { "spec/controllers" } + + # Capybara features specs + watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" } + + # Turnip features and steps + watch(%r{^spec/acceptance/(.+)\.feature$}) + watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } +end + diff --git a/stasis.gemspec b/stasis.gemspec index 4932a40..417b070 100644 --- a/stasis.gemspec +++ b/stasis.gemspec @@ -21,11 +21,12 @@ Gem::Specification.new do |s| s.add_development_dependency "albino" s.add_development_dependency "coffee-script" + s.add_development_dependency "guard-rspec" s.add_development_dependency "haml" s.add_development_dependency "nokogiri" s.add_development_dependency "rake" s.add_development_dependency "rocco" - s.add_development_dependency "rspec", "~> 1.0" + s.add_development_dependency "rspec", "~> 2.0" s.add_development_dependency "sass" s.add_dependency "directory_watcher", "1.4.1" From 313fd2345f80246702e38ca04a83cb6f384ba83a Mon Sep 17 00:00:00 2001 From: Michael Schaefermeyer Date: Sun, 28 Apr 2013 15:14:56 +0200 Subject: [PATCH 2/7] Switch to listener gem --- .gitignore | 4 +++- lib/stasis/dev_mode.rb | 41 ++++++++++++++++------------------------- stasis.gemspec | 4 ++-- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index b0a0b5f..92814d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .bundle .DS_Store *.gem +*.swp docs dump.rdb Gemfile.lock @@ -9,4 +10,5 @@ site/.sass-cache site/public spec/fixtures/project/.sass-cache spec/fixtures/project/public -tmp \ No newline at end of file +tmp +vendor/bundle diff --git a/lib/stasis/dev_mode.rb b/lib/stasis/dev_mode.rb index a2dacbc..b77052d 100644 --- a/lib/stasis/dev_mode.rb +++ b/lib/stasis/dev_mode.rb @@ -1,11 +1,11 @@ -gem 'directory_watcher', '1.4.1' -require 'directory_watcher' +require 'listen' require 'logger' require 'webrick' class Stasis class DevMode + attr_reader :listener def initialize(dir, options={}) trap("INT") { exit } @@ -18,33 +18,24 @@ def initialize(dir, options={}) @stasis = Stasis.new(*[ dir, @options[:public], @options ].compact) - glob = - Dir.chdir(@stasis.root) do - # If destination is within root - if @stasis.destination[0..@stasis.root.length] == "#{@stasis.root}/" - relative = @stasis.destination[@stasis.root.length+1..-1] rescue nil - Dir["*"].inject(["*"]) do |array, path| - if File.directory?(path) && path != relative - array.push("#{path}/**/*") - end - array - end - else - [ "*", "**/*" ] - end - end + #relative_destination_path = @stasis.destination. + @listener = Listen.to(@stasis.root) + .change {render} - dw = DirectoryWatcher.new(@stasis.root) - dw.add_observer { render } - dw.glob = glob - dw.interval = 0.1 - dw.start + if @stasis.destination.include?(@stasis.root) + relative_destination_path = @stasis.destination.gsub(@stasis.root + '/', '') + @listener.ignore Regexp.new(relative_destination_path) + end + end + def run if @options[:development].is_a?(::Integer) + @listener.start + mime_types = WEBrick::HTTPUtils::DefaultMimeTypes additional_mime_types = @options[:mime_types] - + additional_mime_types.each do |extension, mimetype| mime_types.store extension, mimetype puts "add mime type #{mimetype} with extension .#{extension}" @@ -61,14 +52,14 @@ def initialize(dir, options={}) :MimeTypes => mime_types, :Port => @options[:development] ) - + ['INT', 'TERM'].each do |signal| trap(signal) { server.shutdown } end server.start else - loop { sleep 1 } + @listener.start! end end diff --git a/stasis.gemspec b/stasis.gemspec index 417b070..8aa043d 100644 --- a/stasis.gemspec +++ b/stasis.gemspec @@ -29,7 +29,7 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec", "~> 2.0" s.add_development_dependency "sass" - s.add_dependency "directory_watcher", "1.4.1" - s.add_dependency "slop", "3.3.2" + s.add_dependency "listen", "1.0.2" + s.add_dependency "slop", "3.4.4" s.add_dependency "tilt", "1.3.3" end From 61765b14ac5a48fc243649f58b6fbce712a99883 Mon Sep 17 00:00:00 2001 From: Michael Schaefermeyer Date: Sun, 28 Apr 2013 15:15:04 +0200 Subject: [PATCH 3/7] Add listener spec --- spec/stasis/dev_mode_spec.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 spec/stasis/dev_mode_spec.rb diff --git a/spec/stasis/dev_mode_spec.rb b/spec/stasis/dev_mode_spec.rb new file mode 100644 index 0000000..a75a47b --- /dev/null +++ b/spec/stasis/dev_mode_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' +require 'stasis/dev_mode' + +describe Stasis::DevMode do + let(:sample_app_dir) { File.expand_path(File.join(File.path(__FILE__), '..', '..', 'sample_app')) } + let(:public_dir) { 'custom_public' } + let(:stasis) { Stasis::DevMode.new(sample_app_dir, :public => public_dir) } + + after(:each) do + FileUtils.rm_r Dir.glob(File.join(sample_app_dir, '*')) + end + + context 'watching directory changes' do + it 'ignores changes in the destination directory' do + stasis.listener.directories_records.first.ignoring_patterns.should include Regexp.new(public_dir) + end + + it 'detects chagnes in the destingation directory' do + thread = Thread.new { stasis.run } + sleep 1 + `echo 'Hello, world!' >> #{File.join sample_app_dir, 'test.txt'}` + sleep 1 + File.exists?(File.join(sample_app_dir, public_dir, 'test.txt')).should be_true + thread.kill + end + end + +end From 7ccb46dd3e7664e5d11d95193b540a4ca1412f0e Mon Sep 17 00:00:00 2001 From: Michael Schaefermeyer Date: Sun, 28 Apr 2013 15:21:34 +0200 Subject: [PATCH 4/7] Finalize migration to rspec 2 --- Rakefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 09fbee4..b6f2ac8 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,6 @@ require 'bundler' require 'bundler/gem_tasks' -require 'spec/rake/spectask' +require 'rspec/core/rake_task' Bundler.setup(:development) @@ -24,7 +24,8 @@ end desc "Build Rocco Docs" Rocco::make 'docs/' -Spec::Rake::SpecTask.new(:spec) do |t| - t.spec_files = FileList['spec/**/*_spec.rb'] +RSpec::Rake::SpecTask.new(:spec) do |t| + t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default. + # Put spec opts in a file named .rspec in root end -task :default => :spec \ No newline at end of file +task :default => :spec From 1dd41e4ee50a5921787067616bc344ccdb346f86 Mon Sep 17 00:00:00 2001 From: Michael Schaefermeyer Date: Sun, 28 Apr 2013 15:24:13 +0200 Subject: [PATCH 5/7] Add sample app dir --- spec/sample_app/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 spec/sample_app/.gitkeep diff --git a/spec/sample_app/.gitkeep b/spec/sample_app/.gitkeep new file mode 100644 index 0000000..e69de29 From 7fa11ce6e2bff8912aaab98d8eaa4232460698ab Mon Sep 17 00:00:00 2001 From: Michael Schaefermeyer Date: Sun, 28 Apr 2013 15:24:34 +0200 Subject: [PATCH 6/7] Preserve 1.8.7 compatibility --- lib/stasis/dev_mode.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/stasis/dev_mode.rb b/lib/stasis/dev_mode.rb index b77052d..b0df790 100644 --- a/lib/stasis/dev_mode.rb +++ b/lib/stasis/dev_mode.rb @@ -19,8 +19,7 @@ def initialize(dir, options={}) @stasis = Stasis.new(*[ dir, @options[:public], @options ].compact) #relative_destination_path = @stasis.destination. - @listener = Listen.to(@stasis.root) - .change {render} + @listener = Listen.to(@stasis.root).change {render} if @stasis.destination.include?(@stasis.root) relative_destination_path = @stasis.destination.gsub(@stasis.root + '/', '') From 209c7e85271b365f6fc0ec8532b11e66d476d036 Mon Sep 17 00:00:00 2001 From: Michael Schaefermeyer Date: Sun, 28 Apr 2013 15:32:19 +0200 Subject: [PATCH 7/7] Preserve more 1.8.7 compatibility, don't use File#path --- spec/stasis/dev_mode_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/stasis/dev_mode_spec.rb b/spec/stasis/dev_mode_spec.rb index a75a47b..df10897 100644 --- a/spec/stasis/dev_mode_spec.rb +++ b/spec/stasis/dev_mode_spec.rb @@ -2,7 +2,7 @@ require 'stasis/dev_mode' describe Stasis::DevMode do - let(:sample_app_dir) { File.expand_path(File.join(File.path(__FILE__), '..', '..', 'sample_app')) } + let(:sample_app_dir) { File.expand_path(File.join(File.dirname(__FILE__), '..', 'sample_app')) } let(:public_dir) { 'custom_public' } let(:stasis) { Stasis::DevMode.new(sample_app_dir, :public => public_dir) }