Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to rspec2, listen gem #85

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.bundle
.DS_Store
*.gem
*.swp
docs
dump.rdb
Gemfile.lock
Expand All @@ -9,4 +10,5 @@ site/.sass-cache
site/public
spec/fixtures/project/.sass-cache
spec/fixtures/project/public
tmp
tmp
vendor/bundle
24 changes: 24 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -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

9 changes: 5 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'bundler'
require 'bundler/gem_tasks'
require 'spec/rake/spectask'
require 'rspec/core/rake_task'

Bundler.setup(:development)

Expand All @@ -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
task :default => :spec
40 changes: 15 additions & 25 deletions lib/stasis/dev_mode.rb
Original file line number Diff line number Diff line change
@@ -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 }
Expand All @@ -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[[email protected]] == "#{@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}"
Expand All @@ -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

Expand Down
Empty file added spec/sample_app/.gitkeep
Empty file.
28 changes: 28 additions & 0 deletions spec/stasis/dev_mode_spec.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions stasis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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