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/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/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 diff --git a/lib/stasis/dev_mode.rb b/lib/stasis/dev_mode.rb index a2dacbc..b0df790 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,23 @@ 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 +51,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/spec/sample_app/.gitkeep b/spec/sample_app/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/spec/stasis/dev_mode_spec.rb b/spec/stasis/dev_mode_spec.rb new file mode 100644 index 0000000..df10897 --- /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.dirname(__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 diff --git a/stasis.gemspec b/stasis.gemspec index 4932a40..8aa043d 100644 --- a/stasis.gemspec +++ b/stasis.gemspec @@ -21,14 +21,15 @@ 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" - 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