diff --git a/Gemfile b/Gemfile index b1a1c2a..d4efc86 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,12 @@ source "http://rubygems.org" # Specify your gem's dependencies in guard-rocco.gemspec gemspec + +require 'rbconfig' +gem 'guard' +gem 'guard-rspec' + +if RbConfig::CONFIG['host_os'] =~ /darwin/ + gem 'growl' + gem 'rb-fsevent' +end diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..783f1ae --- /dev/null +++ b/Guardfile @@ -0,0 +1,8 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +guard 'rspec', :version => 2 do + watch(%r{^spec/.+_spec\.rb$}) + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } + watch('spec/spec_helper.rb') { "spec" } +end diff --git a/guard-rocco.gemspec b/guard-rocco.gemspec index 10fee82..ec78a2d 100644 --- a/guard-rocco.gemspec +++ b/guard-rocco.gemspec @@ -21,5 +21,7 @@ Gem::Specification.new do |s| s.add_dependency 'guard', '>= 0.4.0' s.add_dependency 'rocco' + s.add_development_dependency 'rspec', '~> 2.6.0' + s.add_development_dependency 'mocha' end diff --git a/lib/guard/rocco.rb b/lib/guard/rocco.rb index 5afc405..35e8181 100644 --- a/lib/guard/rocco.rb +++ b/lib/guard/rocco.rb @@ -1,5 +1,6 @@ require 'rocco' require 'guard/guard' +require 'fileutils' module Guard class Rocco < Guard @@ -23,8 +24,9 @@ module Guard private def build(path, target = nil) - target ||= self.filename_to_target(path) + target ||= filename_to_target(path) puts "rocco: #{path} -> #{target}" + FileUtils.mkdir_p File.split(target).first File.open(target, 'wb') { |fh| fh.print ::Rocco.new(path, all_paths).to_html } end @@ -32,7 +34,7 @@ module Guard Watcher.match_files(self, Dir['**/*']) end - def self.filename_to_target(path) + def filename_to_target(path) File.join(@options[:dir], path).gsub(%r{\.[^\.]+$}, '.html') end end diff --git a/spec/lib/guard/rocco_spec.rb b/spec/lib/guard/rocco_spec.rb new file mode 100644 index 0000000..cab5520 --- /dev/null +++ b/spec/lib/guard/rocco_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' +require 'guard/rocco' +require 'fileutils' + +describe Guard::Rocco do + let(:doc_dir) { 'spec/doc' } + + before do + FileUtils.rm_rf doc_dir + FileUtils.mkdir_p doc_dir + end + + after do + FileUtils.rm_rf doc_dir + end + + let(:guard) { Guard::Rocco.new([], :dir => doc_dir) } + let(:filename) { 'lib/guard/rocco.rb' } + + describe '#run_all' do + before do + guard.stubs(:all_paths).returns([filename]) + end + + it 'should generate the docs' do + guard.run_all + + File.file?(File.join(doc_dir, 'lib/guard/rocco.html')).should be_true + end + end + + describe '#run_on_change' do + it 'should generate the doc' do + guard.run_on_change([filename]) + + File.file?(File.join(doc_dir, 'lib/guard/rocco.html')).should be_true + end + end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..d472384 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,4 @@ +RSpec.configure do |c| + c.mock_with :mocha +end +