jbarnette-lather 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -34,16 +34,27 @@ If you want to mess with the polling interval:
34
34
  # :sleep is in seconds
35
35
  Lather::Watcher.new "*.rb", :sleep => 5
36
36
 
37
+ ## From a Rakefile
38
+
39
+ require "rake/lathertask"
40
+
41
+ Rake::LatherTask.new "lib/**/*.rb" do |task|
42
+ task.target = :test # the default
43
+ task.globs << "test/**/*_test.rb"
44
+ end
45
+
46
+ This will call the `target` task any time the `globs` change. The
47
+ block is optional.
48
+
37
49
  ## Installing
38
50
 
39
51
  $ [sudo] gem install jbarnette-lather -s http://gems.github.com
40
52
 
41
53
  ## Hacking
42
54
 
43
- **The tests aren't working right this second. Check back in a bit.**
44
- Make sure you have minitest installed. `rake lather` will watch `lib`
45
- and `test` and re-run the tests when something changes. If you're
46
- looking for something to work on, think about these:
55
+ `rake lather` will watch `lib` and `test` and re-run the tests when
56
+ something changes. If you're looking for something to work on, chew on
57
+ these:
47
58
 
48
59
  * A `:force => true` option for `Lather::Watcher` so it'll call the
49
60
  change proc with all matched files when it first starts.
@@ -53,15 +64,14 @@ looking for something to work on, think about these:
53
64
  * Some default exclude (like backup/editor files, `.svn`, `.git`)
54
65
  patterns, and an easy way to add new ones.
55
66
 
56
- * A `--sleep <secs>` switch for the command-line tool.
67
+ * A `--sleep <secs>` switch for the command-line tool and the Rake
68
+ task.
57
69
 
58
70
  ## Thanks
59
71
 
60
- Lather owes a huge debt to [Ryan Davis'][ryan] [ZenTest][zt],
61
- specifically `autotest`. Use it. It'll change your life.
62
-
63
- [ryan]: http://blog.zenspider.com
64
- [zt]: http://www.zenspider.com/ZSS/Products/ZenTest
72
+ Lather owes a huge debt to Ryan Davis' ZenTest library, specifically
73
+ `autotest`. Use it. It'll change your life. See also Mike Clark and
74
+ Geoff Grossenbach's `rstakeout`.
65
75
 
66
76
  ## License
67
77
 
data/Rakefile CHANGED
@@ -1,46 +1,51 @@
1
1
  require "rubygems"
2
2
  require "rubygems/specification"
3
+ require "rake/testtask"
3
4
 
4
5
  require "./lib/lather"
6
+ require "./lib/rake/lathertask"
5
7
 
6
8
  namespace :gem do
7
- desc "Update the gemspec."
8
- task :spec do
9
- spec = Gem::Specification.new do |s|
10
- s.name = "lather"
11
- s.version = Lather::VERSION
12
- s.platform = Gem::Platform::RUBY
13
- s.has_rdoc = false
14
- s.summary = "Lather rinses and repeats."
15
- s.description = s.summary
16
- s.author = "John Barnette"
17
- s.email = "jbarnette@gmail.com"
18
- s.homepage = "http://github.com/jbarnette/lather"
19
- s.require_path = "lib"
20
- s.bindir = "bin"
21
- s.executables = %w(lather)
22
-
23
- s.files = %w(Rakefile README.markdown) + Dir["{bin,lib,test}/**/*"]
24
- end
9
+ LATHER = Gem::Specification.new do |s|
10
+ s.name = "lather"
11
+ s.version = Lather::VERSION
12
+ s.platform = Gem::Platform::RUBY
13
+ s.has_rdoc = false
14
+ s.summary = "Lather rinses and repeats."
15
+ s.description = s.summary
16
+ s.author = "John Barnette"
17
+ s.email = "jbarnette@gmail.com"
18
+ s.homepage = "http://github.com/jbarnette/lather"
19
+ s.require_path = "lib"
20
+ s.bindir = "bin"
21
+ s.executables = %w(lather)
22
+
23
+ s.files = %w(Rakefile README.markdown) + Dir["{bin,lib,test}/**/*"]
24
+ end
25
25
 
26
- File.open("#{spec.name}.gemspec", "w") do |f|
27
- f.puts spec.to_ruby
26
+ gemspec = file "#{LATHER.name}.gemspec" => LATHER.files do |file|
27
+ File.open(file.name, "w") do |f|
28
+ f.puts LATHER.to_ruby
28
29
  end
29
30
  end
30
- end
31
31
 
32
- desc "Run tests."
33
- task :test do
34
- testify
35
- end
32
+ gemfile = file "#{LATHER.name}-#{LATHER.version}.gem" => gemspec do |file|
33
+ sh "gem build #{file.prerequisites.first}"
34
+ end
36
35
 
37
- desc "Rinse, repeat."
38
- task :lather do
39
- Lather::Watcher.new("{lib,test}/**/*.rb") { testify }.go!
36
+ desc "Build and install the gem"
37
+ task :install => gemfile do
38
+ sh "sudo gem install #{LATHER.name}-#{LATHER.version}.gem"
39
+ end
40
40
  end
41
41
 
42
- def testify
43
- puts `ruby -Ilib:test #{Dir['test/**/*_test.rb'].join(' ')}`
42
+ Rake::TestTask.new do |test|
43
+ test.libs << "test"
44
+ test.ruby_opts << "-rhelper"
45
+ test.test_files = FileList["test/**/*_test.rb"]
46
+ test.verbose = false
44
47
  end
45
48
 
46
49
  task :default => :test
50
+
51
+ Rake::LatherTask.new "{lib,test}/**/*.rb"
@@ -1,3 +1,3 @@
1
1
  module Lather
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -9,7 +9,7 @@ module Lather
9
9
  @options = { :sleep => 1 }
10
10
  @options.merge!(globs.pop) if globs.last.is_a? Hash
11
11
 
12
- @globs = globs
12
+ @globs = globs.flatten
13
13
  @files = find_files
14
14
  end
15
15
 
@@ -38,7 +38,7 @@ module Lather
38
38
  def find_files
39
39
  files = {}
40
40
 
41
- @globs.flatten.collect { |g| Dir[g] }.flatten.each do |file|
41
+ @globs.collect { |g| Dir[g] }.flatten.each do |file|
42
42
  # silently skip stat failures: file deleted, etc.
43
43
  files[file] = File.stat(file).mtime rescue next
44
44
  end
@@ -0,0 +1,33 @@
1
+ require "rake"
2
+ require "rake/tasklib"
3
+ require "lather/watcher"
4
+
5
+ module Rake
6
+ class LatherTask < TaskLib
7
+ attr_accessor :globs, :target
8
+
9
+ def initialize *globs, &block
10
+ @target = :test
11
+ @globs = globs
12
+
13
+ yield self if block_given?
14
+
15
+ desc "Rinse and repeat"
16
+ Rake::Task.define_task :lather do
17
+ watcher = Lather::Watcher.new @globs do
18
+ target = Rake::Task[@target]
19
+
20
+ begin
21
+ target.invoke
22
+ rescue StandardError => e
23
+ raise e unless e.to_s =~ /^Command failed/
24
+ ensure
25
+ target.reenable
26
+ end
27
+ end
28
+
29
+ watcher.go!
30
+ end
31
+ end
32
+ end
33
+ end
data/test/helper.rb CHANGED
@@ -1,4 +1,22 @@
1
- require "rubygems"
2
- require "minitest/autorun"
3
-
1
+ require "test/unit"
4
2
  require "lather"
3
+
4
+ class Test::Unit::TestCase
5
+
6
+ # Grabbed from Minitest for the moment.
7
+
8
+ def capture_io
9
+ require 'stringio'
10
+
11
+ orig_stdout, orig_stderr = $stdout, $stderr
12
+ captured_stdout, captured_stderr = StringIO.new, StringIO.new
13
+ $stdout, $stderr = captured_stdout, captured_stderr
14
+
15
+ yield
16
+
17
+ return captured_stdout.string, captured_stderr.string
18
+ ensure
19
+ $stdout = orig_stdout
20
+ $stderr = orig_stderr
21
+ end
22
+ end
@@ -1,8 +1,7 @@
1
- require "helper"
2
1
  require "lather/cli"
3
2
 
4
3
  module Lather
5
- class CliTest < MiniTest::Unit::TestCase
4
+ class CliTest < Test::Unit::TestCase
6
5
  def setup
7
6
  @cli = Lather::Cli.new
8
7
  def @cli.exit *args; throw :exit end
@@ -1,7 +1,5 @@
1
- require "helper"
2
-
3
1
  module Lather
4
- class WatcherTest < MiniTest::Unit::TestCase
2
+ class WatcherTest < Test::Unit::TestCase
5
3
  def test_initialize_complains_without_a_callback
6
4
  assert_raise ArgumentError do
7
5
  Lather::Watcher.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jbarnette-lather
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Barnette
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-28 00:00:00 -08:00
12
+ date: 2009-02-05 00:00:00 -08:00
13
13
  default_executable: lather
14
14
  dependencies: []
15
15
 
@@ -30,6 +30,8 @@ files:
30
30
  - lib/lather/version.rb
31
31
  - lib/lather/watcher.rb
32
32
  - lib/lather.rb
33
+ - lib/rake
34
+ - lib/rake/lathertask.rb
33
35
  - test/helper.rb
34
36
  - test/lather
35
37
  - test/lather/cli_test.rb