Skip to content
Browse files

Add simple Rake support. Bump to 1.1.

  • Loading branch information...
1 parent 6c1b982 commit 8426ddb8a55f1d6144279130c3e86a68d909beed @jbarnette committed
Showing with 118 additions and 54 deletions.
  1. +1 −0 .gitignore
  2. +20 −10 README.markdown
  3. +35 −30 Rakefile
  4. +3 −3 lather.gemspec
  5. +1 −1 lib/lather/version.rb
  6. +2 −2 lib/lather/watcher.rb
  7. +33 −0 lib/rake/lathertask.rb
  8. +21 −3 test/helper.rb
  9. +1 −2 test/lather/cli_test.rb
  10. +1 −3 test/lather/watcher_test.rb
View
1 .gitignore
@@ -0,0 +1 @@
+*.gem
View
30 README.markdown
@@ -34,16 +34,27 @@ If you want to mess with the polling interval:
# :sleep is in seconds
Lather::Watcher.new "*.rb", :sleep => 5
+## From a Rakefile
+
+ require "rake/lathertask"
+
+ Rake::LatherTask.new "lib/**/*.rb" do |task|
+ task.target = :test # the default
+ task.globs << "test/**/*_test.rb"
+ end
+
+This will call the `target` task any time the `globs` change. The
+block is optional.
+
## Installing
$ [sudo] gem install jbarnette-lather -s http://gems.github.com
## Hacking
-**The tests aren't working right this second. Check back in a bit.**
-Make sure you have minitest installed. `rake lather` will watch `lib`
-and `test` and re-run the tests when something changes. If you're
-looking for something to work on, think about these:
+`rake lather` will watch `lib` and `test` and re-run the tests when
+something changes. If you're looking for something to work on, chew on
+these:
* A `:force => true` option for `Lather::Watcher` so it'll call the
change proc with all matched files when it first starts.
@@ -53,15 +64,14 @@ looking for something to work on, think about these:
* Some default exclude (like backup/editor files, `.svn`, `.git`)
patterns, and an easy way to add new ones.
- * A `--sleep <secs>` switch for the command-line tool.
+ * A `--sleep <secs>` switch for the command-line tool and the Rake
+ task.
## Thanks
-Lather owes a huge debt to [Ryan Davis'][ryan] [ZenTest][zt],
-specifically `autotest`. Use it. It'll change your life.
-
-[ryan]: http://blog.zenspider.com
-[zt]: http://www.zenspider.com/ZSS/Products/ZenTest
+Lather owes a huge debt to Ryan Davis' ZenTest library, specifically
+`autotest`. Use it. It'll change your life. See also Mike Clark and
+Geoff Grossenbach's `rstakeout`.
## License
View
65 Rakefile
@@ -1,46 +1,51 @@
require "rubygems"
require "rubygems/specification"
+require "rake/testtask"
require "./lib/lather"
+require "./lib/rake/lathertask"
namespace :gem do
- desc "Update the gemspec."
- task :spec do
- spec = Gem::Specification.new do |s|
- s.name = "lather"
- s.version = Lather::VERSION
- s.platform = Gem::Platform::RUBY
- s.has_rdoc = false
- s.summary = "Lather rinses and repeats."
- s.description = s.summary
- s.author = "John Barnette"
- s.email = "jbarnette@gmail.com"
- s.homepage = "http://github.com/jbarnette/lather"
- s.require_path = "lib"
- s.bindir = "bin"
- s.executables = %w(lather)
-
- s.files = %w(Rakefile README.markdown) + Dir["{bin,lib,test}/**/*"]
- end
+ LATHER = Gem::Specification.new do |s|
+ s.name = "lather"
+ s.version = Lather::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.has_rdoc = false
+ s.summary = "Lather rinses and repeats."
+ s.description = s.summary
+ s.author = "John Barnette"
+ s.email = "jbarnette@gmail.com"
+ s.homepage = "http://github.com/jbarnette/lather"
+ s.require_path = "lib"
+ s.bindir = "bin"
+ s.executables = %w(lather)
+
+ s.files = %w(Rakefile README.markdown) + Dir["{bin,lib,test}/**/*"]
+ end
- File.open("#{spec.name}.gemspec", "w") do |f|
- f.puts spec.to_ruby
+ gemspec = file "#{LATHER.name}.gemspec" => LATHER.files do |file|
+ File.open(file.name, "w") do |f|
+ f.puts LATHER.to_ruby
end
end
-end
-desc "Run tests."
-task :test do
- testify
-end
+ gemfile = file "#{LATHER.name}-#{LATHER.version}.gem" => gemspec do |file|
+ sh "gem build #{file.prerequisites.first}"
+ end
-desc "Rinse, repeat."
-task :lather do
- Lather::Watcher.new("{lib,test}/**/*.rb") { testify }.go!
+ desc "Build and install the gem"
+ task :install => gemfile do
+ sh "sudo gem install #{LATHER.name}-#{LATHER.version}.gem"
+ end
end
-def testify
- puts `ruby -Ilib:test #{Dir['test/**/*_test.rb'].join(' ')}`
+Rake::TestTask.new do |test|
+ test.libs << "test"
+ test.ruby_opts << "-rhelper"
+ test.test_files = FileList["test/**/*_test.rb"]
+ test.verbose = false
end
task :default => :test
+
+Rake::LatherTask.new "{lib,test}/**/*.rb"
View
6 lather.gemspec
@@ -2,16 +2,16 @@
Gem::Specification.new do |s|
s.name = %q{lather}
- s.version = "1.0.1"
+ s.version = "1.1.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["John Barnette"]
- s.date = %q{2009-01-28}
+ s.date = %q{2009-02-05}
s.default_executable = %q{lather}
s.description = %q{Lather rinses and repeats.}
s.email = %q{jbarnette@gmail.com}
s.executables = ["lather"]
- s.files = ["Rakefile", "README.markdown", "bin/lather", "lib/lather", "lib/lather/cli.rb", "lib/lather/version.rb", "lib/lather/watcher.rb", "lib/lather.rb", "test/helper.rb", "test/lather", "test/lather/cli_test.rb", "test/lather/watcher_test.rb"]
+ s.files = ["Rakefile", "README.markdown", "bin/lather", "lib/lather", "lib/lather/cli.rb", "lib/lather/version.rb", "lib/lather/watcher.rb", "lib/lather.rb", "lib/rake", "lib/rake/lathertask.rb", "test/helper.rb", "test/lather", "test/lather/cli_test.rb", "test/lather/watcher_test.rb"]
s.homepage = %q{http://github.com/jbarnette/lather}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.1}
View
2 lib/lather/version.rb
@@ -1,3 +1,3 @@
module Lather
- VERSION = "1.0.1"
+ VERSION = "1.1.0"
end
View
4 lib/lather/watcher.rb
@@ -9,7 +9,7 @@ def initialize *globs, &callback
@options = { :sleep => 1 }
@options.merge!(globs.pop) if globs.last.is_a? Hash
- @globs = globs
+ @globs = globs.flatten
@files = find_files
end
@@ -38,7 +38,7 @@ def update_files_and_timestamp
def find_files
files = {}
- @globs.flatten.collect { |g| Dir[g] }.flatten.each do |file|
+ @globs.collect { |g| Dir[g] }.flatten.each do |file|
# silently skip stat failures: file deleted, etc.
files[file] = File.stat(file).mtime rescue next
end
View
33 lib/rake/lathertask.rb
@@ -0,0 +1,33 @@
+require "rake"
+require "rake/tasklib"
+require "lather/watcher"
+
+module Rake
+ class LatherTask < TaskLib
+ attr_accessor :globs, :target
+
+ def initialize *globs, &block
+ @target = :test
+ @globs = globs
+
+ yield self if block_given?
+
+ desc "Rinse and repeat"
+ Rake::Task.define_task :lather do
+ watcher = Lather::Watcher.new @globs do
+ target = Rake::Task[@target]
+
+ begin
+ target.invoke
+ rescue StandardError => e
+ raise e unless e.to_s =~ /^Command failed/
+ ensure
+ target.reenable
+ end
+ end
+
+ watcher.go!
+ end
+ end
+ end
+end
View
24 test/helper.rb
@@ -1,4 +1,22 @@
-require "rubygems"
-require "minitest/autorun"
-
+require "test/unit"
require "lather"
+
+class Test::Unit::TestCase
+
+ # Grabbed from Minitest for the moment.
+
+ def capture_io
+ require 'stringio'
+
+ orig_stdout, orig_stderr = $stdout, $stderr
+ captured_stdout, captured_stderr = StringIO.new, StringIO.new
+ $stdout, $stderr = captured_stdout, captured_stderr
+
+ yield
+
+ return captured_stdout.string, captured_stderr.string
+ ensure
+ $stdout = orig_stdout
+ $stderr = orig_stderr
+ end
+end
View
3 test/lather/cli_test.rb
@@ -1,8 +1,7 @@
-require "helper"
require "lather/cli"
module Lather
- class CliTest < MiniTest::Unit::TestCase
+ class CliTest < Test::Unit::TestCase
def setup
@cli = Lather::Cli.new
def @cli.exit *args; throw :exit end
View
4 test/lather/watcher_test.rb
@@ -1,7 +1,5 @@
-require "helper"
-
module Lather
- class WatcherTest < MiniTest::Unit::TestCase
+ class WatcherTest < Test::Unit::TestCase
def test_initialize_complains_without_a_callback
assert_raise ArgumentError do
Lather::Watcher.new

0 comments on commit 8426ddb

Please sign in to comment.
Something went wrong with that request. Please try again.