jbarnette-lather 1.1.0 → 1.2.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
@@ -20,7 +20,6 @@ You can also run a command every time something changes:
20
20
 
21
21
  ## From Code
22
22
 
23
- require "rubygems"
24
23
  require "lather"
25
24
 
26
25
  watcher = Lather::Watcher.new "**/*.rb" do |changed|
@@ -39,12 +38,32 @@ If you want to mess with the polling interval:
39
38
  require "rake/lathertask"
40
39
 
41
40
  Rake::LatherTask.new "lib/**/*.rb" do |task|
42
- task.target = :test # the default
41
+ task.target = :test # default
43
42
  task.globs << "test/**/*_test.rb"
44
43
  end
45
44
 
46
- This will call the `target` task any time the `globs` change. The
47
- block is optional.
45
+ This creates a `lather` task, which will call the `target` task any
46
+ time the `globs` change. The block is optional.
47
+
48
+ You can also use Lather's replacement for Rake's `TestTask` for even
49
+ nicer integration:
50
+
51
+ require "rake/lathertesttask"
52
+
53
+ Rake::LatherTestTask.new do |test|
54
+
55
+ # These are the defaults, you don't need to specify 'em.
56
+
57
+ test.files = %w(lib/**/*.rb)
58
+ test.flags = %w(-w)
59
+ test.libs = %w(lib test)
60
+ test.options = { :force => true }
61
+ test.tests = %w(test/**/*_test.rb)
62
+ test.verbose = false
63
+ end
64
+
65
+ This creates `test` and `test:lather` tasks. The block is
66
+ optional. See Lather's `Rakefile` for a working example.
48
67
 
49
68
  ## Installing
50
69
 
@@ -56,10 +75,8 @@ block is optional.
56
75
  something changes. If you're looking for something to work on, chew on
57
76
  these:
58
77
 
59
- * A `:force => true` option for `Lather::Watcher` so it'll call the
60
- change proc with all matched files when it first starts.
61
-
62
- * A way to get at the list of changed files in a `-r` command.
78
+ * A way to get at the list of changed files in a `-r` command and
79
+ the Rake task.
63
80
 
64
81
  * Some default exclude (like backup/editor files, `.svn`, `.git`)
65
82
  patterns, and an easy way to add new ones.
@@ -71,7 +88,7 @@ these:
71
88
 
72
89
  Lather owes a huge debt to Ryan Davis' ZenTest library, specifically
73
90
  `autotest`. Use it. It'll change your life. See also Mike Clark and
74
- Geoff Grossenbach's `rstakeout`.
91
+ Geoffrey Grosenbach's `rstakeout`.
75
92
 
76
93
  ## License
77
94
 
data/Rakefile CHANGED
@@ -1,9 +1,8 @@
1
- require "rubygems"
2
1
  require "rubygems/specification"
3
2
  require "rake/testtask"
4
3
 
5
4
  require "./lib/lather"
6
- require "./lib/rake/lathertask"
5
+ require "./lib/rake/lathertesttask"
7
6
 
8
7
  namespace :gem do
9
8
  LATHER = Gem::Specification.new do |s|
@@ -39,13 +38,8 @@ namespace :gem do
39
38
  end
40
39
  end
41
40
 
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
41
+ Rake::LatherTestTask.new do |test|
42
+ test.flags << "-rhelper"
47
43
  end
48
44
 
49
45
  task :default => :test
50
-
51
- Rake::LatherTask.new "{lib,test}/**/*.rb"
@@ -1,3 +1,3 @@
1
1
  module Lather
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -1,12 +1,13 @@
1
1
  module Lather
2
2
  class Watcher
3
3
  attr_reader :files
4
+ attr_reader :options
4
5
 
5
6
  def initialize *globs, &callback
6
7
  raise ArgumentError, "need a callback" unless block_given?
7
8
  @callback = callback
8
9
 
9
- @options = { :sleep => 1 }
10
+ @options = { :force => false, :sleep => 1 }
10
11
  @options.merge!(globs.pop) if globs.last.is_a? Hash
11
12
 
12
13
  @globs = globs.flatten
@@ -16,6 +17,8 @@ module Lather
16
17
  def go!
17
18
  @timestamp = Time.now
18
19
 
20
+ @callback[@files.keys] if @options[:force]
21
+
19
22
  loop do
20
23
  unless (changed = update_files_and_timestamp).empty?
21
24
  @callback[changed]
@@ -3,8 +3,19 @@ require "rake/tasklib"
3
3
  require "lather/watcher"
4
4
 
5
5
  module Rake
6
+
7
+ # Runs the <tt>target</tt> task any time a file matching one of the
8
+ # <tt>globs</tt> changes.
9
+
6
10
  class LatherTask < TaskLib
7
- attr_accessor :globs, :target
11
+
12
+ # An array of globs to watch.
13
+
14
+ attr_accessor :globs
15
+
16
+ # The task to run when things change. Default is <tt>:test</tt>.
17
+
18
+ attr_accessor :target
8
19
 
9
20
  def initialize *globs, &block
10
21
  @target = :test
@@ -0,0 +1,108 @@
1
+ require "rake"
2
+ require "rake/tasklib"
3
+ require "lather/watcher"
4
+
5
+ module Rake
6
+
7
+ # A simplified version of <tt>Rake::TestTask</tt> with support for
8
+ # Lather. It creates <tt>test</tt> and <tt>test:lather</tt>
9
+ # tasks. It's more opinionated and less configurable than
10
+ # <tt>Rake::TestTask</tt>: Test file load order is random.
11
+ #
12
+ # When lathering, a very stupid heuristic is used to decide which
13
+ # test files to run: Any test file whose path contains the basename
14
+ # (without extension) of the file that changed. If no test files
15
+ # match, everything gets run. No tracking of failures, no specific
16
+ # tests. If you want more than this, you should be using Autotest.
17
+
18
+ class LatherTestTask < TaskLib
19
+
20
+ # An optional array of stuff to tack on to the end of the Ruby
21
+ # command-line. Default is <tt>[]</tt>.
22
+
23
+ attr_accessor :extras
24
+
25
+ # An array of glob patterns to match implementation files. Default
26
+ # is <tt>%w(lib/**/*.rb)</tt>.
27
+
28
+ attr_accessor :files
29
+
30
+ # An array of command-line flags to pass on to Ruby. Default is
31
+ # <tt>%w(-w)</tt>.
32
+
33
+ attr_accessor :flags
34
+
35
+ # An array of directories to add to the load path. Default is
36
+ # <tt>%w(lib test)</tt>.
37
+
38
+ attr_accessor :libs
39
+
40
+ # A hash of options to pass on to <tt>Lather::Watcher.new</tt>.
41
+ # Default is <tt>{ :force => true }</tt>.
42
+
43
+ attr_accessor :options
44
+
45
+ # An array of glob patterns to match test files. Default is
46
+ # <tt>%w(test/**/*_test.rb)</tt>.
47
+
48
+ attr_accessor :tests
49
+
50
+ # Be chatty? Default is <tt>false</tt>.
51
+
52
+ attr_accessor :verbose
53
+
54
+ def initialize
55
+ @extras = []
56
+ @files = %w(lib/**/*.rb)
57
+ @flags = %w(-w)
58
+ @libs = %w(lib test)
59
+ @options = { :force => true }
60
+ @tests = %w(test/**/*_test.rb)
61
+ @verbose = false
62
+
63
+ yield self if block_given?
64
+
65
+ desc "Run the tests"
66
+ task(:test) { testify FileList[@tests] }
67
+
68
+ namespace :test do
69
+
70
+ desc "Test, rinse, repeat"
71
+ task :lather do
72
+ watcher = Lather::Watcher.new @files, @tests, @options do |changed|
73
+ all_tests = FileList[@tests]
74
+ tests = all_tests & changed
75
+
76
+ basenames = (changed - tests).collect do |f|
77
+ File.basename(f).split(".").first
78
+ end
79
+
80
+ tests.concat all_tests.
81
+ select { |t| basenames.any? { |b| t =~ /#{b}/ } }
82
+
83
+ begin
84
+ testify tests.empty? ? all_tests : tests.uniq
85
+ rescue StandardError => e
86
+ raise e unless e.to_s =~ /^Command failed/
87
+ end
88
+ end
89
+
90
+ watcher.go!
91
+ end
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ def testify tests
98
+ cmd = @flags.dup
99
+ cmd << "-I#{@libs.join(':')}"
100
+ cmd << "-e 'ARGV.each { |f| load f }'"
101
+
102
+ cmd.concat tests.collect { |f| "'#{f}'" }.sort_by { rand }
103
+ cmd.concat @extras
104
+
105
+ RakeFileUtils.verbose(@verbose) { ruby cmd.join(" ") }
106
+ end
107
+ end
108
+ end
@@ -15,7 +15,7 @@ module Lather
15
15
 
16
16
  def test_empty_invocation_prints_help
17
17
  out, err = parse!
18
- assert_match /Shows help/, out
18
+ assert_match(/Shows help/, out)
19
19
  end
20
20
 
21
21
  def test_V_option_prints_version
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.1.0
4
+ version: 1.2.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-02-05 00:00:00 -08:00
12
+ date: 2009-02-06 00:00:00 -08:00
13
13
  default_executable: lather
14
14
  dependencies: []
15
15
 
@@ -32,6 +32,7 @@ files:
32
32
  - lib/lather.rb
33
33
  - lib/rake
34
34
  - lib/rake/lathertask.rb
35
+ - lib/rake/lathertesttask.rb
35
36
  - test/helper.rb
36
37
  - test/lather
37
38
  - test/lather/cli_test.rb