fix things, oops

This commit is contained in:
John Bintz 2011-06-18 15:33:21 -04:00
parent 246d64861f
commit 23d15910ac
6 changed files with 67 additions and 2 deletions

View File

@ -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

8
Guardfile Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

4
spec/spec_helper.rb Normal file
View File

@ -0,0 +1,4 @@
RSpec.configure do |c|
c.mock_with :mocha
end