Permalink
Browse files

Tweaks.

  • Loading branch information...
1 parent 949bf96 commit 7184cd0ea4452f1facf2038cd16635028d5f911d @jbarnette committed Jan 28, 2009
Showing with 49 additions and 9 deletions.
  1. +1 −1 Rakefile
  2. +11 −5 lib/lather/cli.rb
  3. +2 −2 test/helper.rb
  4. +24 −1 test/lather/cli_test.rb
  5. +11 −0 test/lather/watcher_test.rb
View
@@ -12,7 +12,7 @@ task :lather do
end
def testify
- sh "ruby -Ilib:test #{Dir['test/**/*_test.rb'].join(' ')}"
+ puts `ruby -Ilib:test #{Dir['test/**/*_test.rb'].join(' ')}`
end
task :default => :test
View
@@ -1,10 +1,13 @@
require "optparse"
+require "lather/watcher"
+require "lather/version"
+
module Lather
class Cli
def initialize
- @globs = []
@command = nil
+ @globs = []
@verbose = false
@options = OptionParser.new do |o|
@@ -32,17 +35,20 @@ def initialize
end
end
- def go! args
- @options.parse!
-
+ def parse! args
+ @options.parse! args
@globs.concat args
exit help! if @globs.empty?
+ end
+
+ def go! args
+ parse! args
watcher = Lather::Watcher.new @globs do |files|
if @command
system @command
else
- @out.puts "Changed: #{files.join(" ")}"
+ puts "Changed: #{files.join(" ")}"
end
end
View
@@ -1,4 +1,4 @@
require "rubygems"
-require "minitest/unit"
+require "minitest/autorun"
-MiniTest::Unit.autorun
+require "lather"
@@ -1,6 +1,29 @@
require "helper"
+require "lather/cli"
module Lather
- class CliTest < MiniTest::Unit
+ class CliTest < MiniTest::Unit::TestCase
+ def setup
+ @cli = Lather::Cli.new
+ def @cli.exit *args; throw :exit end
+ end
+
+ def parse! *args
+ capture_io do
+ catch(:exit) { @cli.parse! args }
+ end
+ end
+
+ def test_empty_invocation_prints_help
+ out, err = parse!
+ assert_match /Shows help/, out
+ end
+
+ def test_V_option_prints_version
+ %w(-V --version).each do |flag|
+ out, err = parse! flag
+ assert_equal Lather::VERSION, out.chomp
+ end
+ end
end
end
@@ -0,0 +1,11 @@
+require "helper"
+
+module Lather
+ class WatcherTest < MiniTest::Unit::TestCase
+ def test_initialize_complains_without_a_callback
+ assert_raise ArgumentError do
+ Lather::Watcher.new
+ end
+ end
+ end
+end

0 comments on commit 7184cd0

Please sign in to comment.