autowatchr 0.0.0 → 0.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.rdoc CHANGED
@@ -6,19 +6,61 @@ Provides some autotest-like behavior for watchr (http://github.com/mynyml/watchr
6
6
 
7
7
  gem install autowatchr --source http://gemcutter.org
8
8
 
9
+ == Current features
10
+
11
+ * Auto-watches test and lib files using the autotest layout
12
+ * Optionally run only failing-tests
13
+ * Optionally run entire suite after all tests pass
14
+
15
+ == Todo
16
+
17
+ * Cucumber support
18
+ * Expose algorithm to map test classes to test files
19
+
9
20
  == Example use
10
21
 
11
22
  test.watchr
12
23
  require 'autowatchr'
13
24
 
14
25
  Autowatchr.new(self) do |config|
15
- config.ruby = "jruby" # default: "ruby"
16
- config.lib_dir = "leet_lib" # default: "lib"
17
- config.test_dir = "leet_test" # default: "test"
26
+ config.ruby = 'jruby'
27
+ config.lib_dir = 'leet_lib'
28
+ config.test_dir = 'leet_test'
18
29
  end
19
30
 
20
- Also see: test.watchr[http://github.com/viking/autowatchr/blob/master/test.watchr].
31
+ === Configuration options
32
+ * command
33
+ * An ERB template for the command
34
+ * Default: <tt>"<%= ruby %> -I<%= include %> <%= predicate %>"</tt>
35
+ * ruby
36
+ * The ruby executable to use
37
+ * Default: <tt>"ruby"</tt>
38
+ * include
39
+ * Paths to include (with -I)
40
+ * Default: <tt>".:#{self.lib_dir}:#{self.test_dir}"</tt>
41
+ * lib_dir
42
+ * The lib path, where your library lives
43
+ * Default: <tt>"lib"</tt>
44
+ * test_dir
45
+ * The test path, where your tests live
46
+ * Default: <tt>"test"</tt>
47
+ * lib_re
48
+ * The regexp to use for discovering library files
49
+ * Default: <tt>'^%s.*/.*\.rb$' % self.lib_dir</tt>
50
+ * test_re
51
+ * The regexp to use for discovering library files
52
+ * Default: <tt>'^%s.*/test_.*\.rb$' % self.test_dir</tt>
53
+ * failing_only
54
+ * Run only failing tests the next time a test file is run
55
+ * Default: <tt>true</tt>
56
+ * run_suite
57
+ * Run entire test suite after failing tests pass
58
+ * Default: <tt>true</tt>
59
+
60
+ All of the config options are optional. You can also pass in a hash instead of a block. Also see: test.watchr[http://github.com/viking/autowatchr/blob/master/test.watchr].
21
61
 
22
62
  == Copyright
23
63
 
24
64
  Copyright (c) 2009 Jeremy Stephens. See LICENSE for details.
65
+
66
+ Many snippets were taken from ZenTest[http://github.com/seattlerb/ZenTest].
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
data/autowatchr.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{autowatchr}
8
- s.version = "0.0.0"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremy Stephens"]
12
- s.date = %q{2009-09-30}
12
+ s.date = %q{2009-10-02}
13
13
  s.description = %q{Provides some autotest-like behavior for watchr (http://github.com/mynyml/watchr).}
14
14
  s.email = %q{viking415@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -26,9 +26,17 @@ Gem::Specification.new do |s|
26
26
  "autowatchr.gemspec",
27
27
  "lib/autowatchr.rb",
28
28
  "test.watchr",
29
+ "test/fixtures/lib/bar.rb",
29
30
  "test/fixtures/lib/foo.rb",
31
+ "test/fixtures/results/all.txt",
32
+ "test/fixtures/results/bar_flunk.txt",
33
+ "test/fixtures/results/bar_pass.txt",
30
34
  "test/fixtures/results/foo.txt",
35
+ "test/fixtures/results/foo_flunk.txt",
36
+ "test/fixtures/results/foo_pass.txt",
37
+ "test/fixtures/test.watchr",
31
38
  "test/fixtures/test/helper.rb",
39
+ "test/fixtures/test/test_bar.rb",
32
40
  "test/fixtures/test/test_foo.rb",
33
41
  "test/helper.rb",
34
42
  "test/test_autowatchr.rb"
@@ -40,7 +48,9 @@ Gem::Specification.new do |s|
40
48
  s.summary = %q{Provides some autotest-like behavior for watchr}
41
49
  s.test_files = [
42
50
  "test/fixtures/test/test_foo.rb",
51
+ "test/fixtures/test/test_bar.rb",
43
52
  "test/fixtures/test/helper.rb",
53
+ "test/fixtures/lib/bar.rb",
44
54
  "test/fixtures/lib/foo.rb",
45
55
  "test/test_autowatchr.rb",
46
56
  "test/helper.rb"
data/lib/autowatchr.rb CHANGED
@@ -1,45 +1,118 @@
1
+ require 'erb'
2
+
1
3
  class Autowatchr
2
- attr_writer :ruby, :include, :lib_dir, :test_dir
4
+ class Config
5
+ attr_writer :command, :ruby, :include, :lib_dir, :test_dir, :lib_re,
6
+ :test_re, :failed_results_re, :completed_re, :failing_only, :run_suite
3
7
 
4
- def initialize(script, options = {})
5
- options.each_pair do |key, value|
6
- method = "#{key}="
7
- if self.respond_to?(method)
8
- self.send(method, value)
8
+ def initialize(options = {})
9
+ @failing_only = @run_suite = true
10
+
11
+ options.each_pair do |key, value|
12
+ method = "#{key}="
13
+ if self.respond_to?(method)
14
+ self.send(method, value)
15
+ end
9
16
  end
10
17
  end
11
- yield self if block_given?
12
18
 
13
- @script = script
14
- start_watching_files
15
- end
19
+ def command
20
+ @command ||= "<%= ruby %> -I<%= include %> <%= predicate %>"
21
+ end
16
22
 
17
- def ruby
18
- @ruby ||= "ruby"
19
- end
23
+ def ruby
24
+ @ruby ||= "ruby"
25
+ end
20
26
 
21
- def include
22
- @include ||= ".:#{self.lib_dir}:#{self.test_dir}"
23
- end
27
+ def include
28
+ @include ||= ".:#{self.lib_dir}:#{self.test_dir}"
29
+ end
24
30
 
25
- def lib_dir
26
- @lib_dir ||= "lib"
31
+ def lib_dir
32
+ @lib_dir ||= "lib"
33
+ end
34
+
35
+ def test_dir
36
+ @test_dir ||= "test"
37
+ end
38
+
39
+ def lib_re
40
+ @lib_re ||= '^%s.*/.*\.rb$' % self.lib_dir
41
+ end
42
+
43
+ def test_re
44
+ @test_re ||= '^%s.*/test_.*\.rb$' % self.test_dir
45
+ end
46
+
47
+ def failed_results_re
48
+ @failed_results_re ||= /^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?)\)/
49
+ end
50
+
51
+ def completed_re
52
+ @completed_re ||= /\d+ tests, \d+ assertions, \d+ failures, \d+ errors/
53
+ end
54
+
55
+ def failing_only
56
+ @failing_only
57
+ end
58
+
59
+ def run_suite
60
+ @run_suite
61
+ end
62
+
63
+ def eval_command(predicate)
64
+ ERB.new(self.command).result(binding)
65
+ end
27
66
  end
28
67
 
29
- def test_dir
30
- @test_dir ||= "test"
68
+ attr_reader :config
69
+
70
+ def initialize(script, options = {})
71
+ @config = Config.new(options)
72
+ yield @config if block_given?
73
+ @script = script
74
+ @test_files = []
75
+ @failed_tests = {}
76
+
77
+ discover_files
78
+ run_all_tests
79
+ start_watching_files
31
80
  end
32
81
 
33
82
  def run_lib_file(file)
34
- md = file.match(%r{^#{@lib_dir}#{File::SEPARATOR}?(.+)$})
83
+ md = file.match(%r{^#{@config.lib_dir}#{File::SEPARATOR}?(.+)$})
35
84
  parts = md[1].split(File::SEPARATOR)
36
85
  parts[-1] = "test_#{parts[-1]}"
37
- file = "#{@test_dir}/" + File.join(parts)
86
+ file = "#{@config.test_dir}/" + File.join(parts)
38
87
  run_test_file(file)
39
88
  end
40
89
 
41
- def run_test_file(file)
42
- cmd = "%s -I%s %s" % [ self.ruby, self.include, file ]
90
+ def run_test_file(files)
91
+ files = [files] unless files.is_a?(Array)
92
+
93
+ passing = []
94
+ commands = []
95
+ files.each do |file|
96
+ tests = @failed_tests[file]
97
+ if tests && !tests.empty?
98
+ predicate = %!#{file} -n "/^(#{tests.join("|")})$/"!
99
+ commands << @config.eval_command(predicate)
100
+ else
101
+ passing << file
102
+ end
103
+ end
104
+
105
+ if !passing.empty?
106
+ predicate = if passing.length > 1
107
+ "-e \"%w[#{passing.join(" ")}].each { |f| require f }\""
108
+ else
109
+ passing[0]
110
+ end
111
+ commands.unshift(@config.eval_command(predicate))
112
+ end
113
+
114
+ cmd = commands.join("; ")
115
+ puts cmd
43
116
 
44
117
  # straight outta autotest
45
118
  results = []
@@ -52,18 +125,68 @@ class Autowatchr
52
125
  if c == ?\n then
53
126
  results << if RUBY_VERSION >= "1.9" then
54
127
  line.join
55
- else
56
- line.pack "c*"
57
- end
128
+ else
129
+ line.pack "c*"
130
+ end
58
131
  line.clear
59
132
  end
60
133
  end
61
134
  end
135
+ handle_results(results.join, files)
136
+ end
137
+
138
+ def classname_to_path(s)
139
+ File.join(@config.test_dir, underscore(s)+".rb")
62
140
  end
63
141
 
64
142
  private
143
+ def discover_files
144
+ @test_files = Dir.glob("#{@config.test_dir}/**/*").grep(/#{@config.test_re}/)
145
+ end
146
+
147
+ def run_all_tests
148
+ run_test_file(@test_files)
149
+ end
150
+
65
151
  def start_watching_files
66
- @script.watch("^#{self.test_dir}.*/test_.*\.rb") { |md| run_test_file(md[0]) }
67
- @script.watch("^#{self.lib_dir}.*/.*\.rb") { |md| run_lib_file(md[0]) }
152
+ @script.watch(@config.test_re) { |md| run_test_file(md[0]) }
153
+ @script.watch(@config.lib_re) { |md| run_lib_file(md[0]) }
154
+ end
155
+
156
+ def handle_results(results, files_ran)
157
+ return if !@config.failing_only
158
+ num_previously_failed = @failed_tests.length
159
+
160
+ failed = results.scan(@config.failed_results_re)
161
+ completed = results =~ @config.completed_re
162
+
163
+ previously_failed = @failed_tests.keys & files_ran
164
+ failed.each do |(test_name, class_name)|
165
+ key = classname_to_path(class_name)
166
+ if files_ran.include?(key)
167
+ @failed_tests[key] ||= []
168
+ @failed_tests[key] << test_name
169
+ previously_failed.delete(key)
170
+ else
171
+ puts "Couldn't map class to file: #{class_name}"
172
+ end
173
+ end
174
+
175
+ previously_failed.each do |file|
176
+ @failed_tests.delete(file)
177
+ end
178
+
179
+ if @config.run_suite && @failed_tests.empty? && num_previously_failed > 0
180
+ run_all_tests
181
+ end
182
+ end
183
+
184
+ # File vendor/rails/activesupport/lib/active_support/inflector.rb, line 206
185
+ def underscore(camel_cased_word)
186
+ camel_cased_word.to_s.gsub(/::/, '/').
187
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
188
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
189
+ tr("-", "_").
190
+ downcase
68
191
  end
69
192
  end
@@ -0,0 +1,2 @@
1
+ class Bar
2
+ end
@@ -0,0 +1,14 @@
1
+ Loaded suite -e
2
+ Started
3
+ F.F.
4
+ Finished in 0.001231 seconds.
5
+
6
+ 1) Failure:
7
+ test_flunk(TestBar) [./test/test_bar.rb:9]:
8
+ Flunked.
9
+
10
+ 2) Failure:
11
+ test_flunk(TestFoo) [./test/test_foo.rb:9]:
12
+ Flunked.
13
+
14
+ 4 tests, 4 assertions, 2 failures, 0 errors
@@ -0,0 +1,10 @@
1
+ Loaded suite test/test_bar
2
+ Started
3
+ F.
4
+ Finished in 0.0007 seconds.
5
+
6
+ 1) Failure:
7
+ test_flunk(TestBar) [test/test_bar.rb:9]:
8
+ Flunked.
9
+
10
+ 2 tests, 2 assertions, 1 failures, 0 errors
@@ -0,0 +1,6 @@
1
+ Loaded suite test/test_bar
2
+ Started
3
+ ..
4
+ Finished in 0.000306 seconds.
5
+
6
+ 2 tests, 1 assertions, 0 failures, 0 errors
@@ -0,0 +1,10 @@
1
+ Loaded suite test/test_foo
2
+ Started
3
+ F
4
+ Finished in 0.000645 seconds.
5
+
6
+ 1) Failure:
7
+ test_flunk(TestFoo) [test/test_foo.rb:9]:
8
+ Flunked.
9
+
10
+ 1 tests, 1 assertions, 1 failures, 0 errors
@@ -0,0 +1,6 @@
1
+ Loaded suite test/test_foo
2
+ Started
3
+ .
4
+ Finished in 0.000219 seconds.
5
+
6
+ 1 tests, 0 assertions, 0 failures, 0 errors
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + "/helper"
2
+
3
+ class TestBar < Test::Unit::TestCase
4
+ def test_pass
5
+ assert true
6
+ end
7
+
8
+ def test_flunk
9
+ flunk
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ require '../../lib/autowatchr'
2
+
3
+ Autowatchr.new(self) do |config|
4
+ end
data/test/helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'mocha'
4
+ require 'pp'
5
+ require 'ruby-debug'
4
6
 
5
7
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
8
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -21,3 +23,8 @@ class Test::Unit::TestCase
21
23
  stream.reopen(old_stream)
22
24
  end
23
25
  end
26
+
27
+ def debug_p(obj, label = nil)
28
+ $stderr.print "#{label}: " if label
29
+ $stderr.puts obj.inspect
30
+ end
@@ -17,67 +17,219 @@ class TestAutowatchr < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  def test_new_with_hash
20
- aw = Autowatchr.new(@script, {
21
- :ruby => "/usr/local/bin/ruby",
22
- :include => ".:lib:test"
23
- })
24
- assert_equal "/usr/local/bin/ruby", aw.ruby
25
- assert_equal ".:lib:test", aw.include
20
+ aw = nil
21
+ silence_stream(STDOUT) do
22
+ aw = Autowatchr.new(@script, {
23
+ :ruby => "/usr/local/bin/ruby",
24
+ :include => ".:lib:test"
25
+ })
26
+ end
27
+ assert_equal "/usr/local/bin/ruby", aw.config.ruby
28
+ assert_equal ".:lib:test", aw.config.include
26
29
  end
27
30
 
28
31
  def test_new_with_block
29
- aw = Autowatchr.new(@script) do |config|
30
- config.ruby = "/usr/local/bin/ruby"
31
- config.include = ".:lib:test"
32
- config.lib_dir = @lib_dir
33
- config.test_dir = @test_dir
32
+ aw = nil
33
+ silence_stream(STDOUT) do
34
+ aw = Autowatchr.new(@script) do |config|
35
+ config.ruby = "/usr/local/bin/ruby"
36
+ config.include = ".:lib:test"
37
+ config.lib_dir = @lib_dir
38
+ config.test_dir = @test_dir
39
+ end
34
40
  end
35
- assert_equal "/usr/local/bin/ruby", aw.ruby
36
- assert_equal ".:lib:test", aw.include
37
- assert_equal @lib_dir, aw.lib_dir
38
- assert_equal @test_dir, aw.test_dir
41
+ assert_equal "/usr/local/bin/ruby", aw.config.ruby
42
+ assert_equal ".:lib:test", aw.config.include
43
+ assert_equal @lib_dir, aw.config.lib_dir
44
+ assert_equal @test_dir, aw.config.test_dir
39
45
  end
40
46
 
41
47
  def test_auto_includes
42
- aw = Autowatchr.new(@script) do |config|
43
- config.ruby = "/usr/local/bin/ruby"
44
- config.lib_dir = @lib_dir
45
- config.test_dir = @test_dir
48
+ aw = nil
49
+ silence_stream(STDOUT) do
50
+ aw = Autowatchr.new(@script) do |config|
51
+ config.ruby = "/usr/local/bin/ruby"
52
+ config.lib_dir = @lib_dir
53
+ config.test_dir = @test_dir
54
+ end
46
55
  end
47
- assert_equal ".:#{@lib_dir}:#{@test_dir}", aw.include
56
+ assert_equal ".:#{@lib_dir}:#{@test_dir}", aw.config.include
48
57
  end
49
58
 
50
59
  def test_defaults
51
- aw = Autowatchr.new(@script)
52
- assert_equal "ruby", aw.ruby
53
- assert_equal ".:lib:test", aw.include
54
- assert_equal "lib", aw.lib_dir
55
- assert_equal "test", aw.test_dir
60
+ aw = nil
61
+ silence_stream(STDOUT) do
62
+ aw = Autowatchr.new(@script)
63
+ end
64
+ assert_equal "ruby", aw.config.ruby
65
+ assert_equal ".:lib:test", aw.config.include
66
+ assert_equal "lib", aw.config.lib_dir
67
+ assert_equal "test", aw.config.test_dir
68
+ assert_equal '^lib.*/.*\.rb$', aw.config.lib_re
69
+ assert_equal '^test.*/test_.*\.rb$', aw.config.test_re
70
+ assert_equal /^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?)\)/, aw.config.failed_results_re
71
+ assert_equal /\d+ tests, \d+ assertions, \d+ failures, \d+ errors/, aw.config.completed_re
56
72
  end
57
73
 
58
74
  def test_watches_test_files
59
- md = ["#{@test_dir}/test_foo.rb"]
60
- Autowatchr.any_instance.expects(:run_test_file).with("#{@test_dir}/test_foo.rb")
61
- @script.expects(:watch).with("^#{@test_dir}.*/test_.*\.rb").yields(md)
62
- new_autowatchr
75
+ @script.expects(:watch).with('^%s.*/test_.*\.rb$' % @test_dir)
76
+ silence_stream(STDOUT) do
77
+ new_autowatchr
78
+ end
63
79
  end
64
80
 
65
81
  def test_watches_lib_files
66
- md = ["#{@lib_dir}/foo.rb"]
67
- Autowatchr.any_instance.expects(:run_lib_file).with("#{@lib_dir}/foo.rb")
68
- @script.expects(:watch).with("^#{@lib_dir}.*/.*\.rb").yields(md)
69
- new_autowatchr
82
+ @script.expects(:watch).with('^%s.*/.*\.rb$' % @lib_dir)
83
+ silence_stream(STDOUT) do
84
+ new_autowatchr
85
+ end
70
86
  end
71
87
 
72
88
  def test_run_lib_file
73
- aw = new_autowatchr
74
89
  result = fake_result("foo")
75
- aw.expects(:open).with(
76
- "| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb", "r"
77
- ).yields(result)
90
+ expected_cmd = "| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb"
91
+ Autowatchr.any_instance.expects(:open).with(expected_cmd, "r").yields(result)
78
92
 
79
93
  silence_stream(STDOUT) do
94
+ aw = new_autowatchr
80
95
  aw.run_lib_file("#{@lib_dir}/foo.rb")
81
96
  end
82
97
  end
98
+
99
+ def test_running_multiple_test_files
100
+ result = fake_result("all")
101
+ expected_cmd = "| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -e \"%w[#{@test_dir}/test_bar.rb #{@test_dir}/test_foo.rb].each { |f| require f }\""
102
+ Autowatchr.any_instance.expects(:open).with(expected_cmd, "r").yields(result)
103
+
104
+ silence_stream(STDOUT) do
105
+ aw = new_autowatchr
106
+ aw.run_test_file(["#{@test_dir}/test_bar.rb", "#{@test_dir}/test_foo.rb"])
107
+ end
108
+ end
109
+
110
+ def test_runs_all_test_files_on_start
111
+ result = fake_result("all")
112
+ files = Dir.glob("#{@test_dir}/**/test_*.rb").join(" ")
113
+ expected_cmd = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -e "%w[#{files}].each { |f| require f }"!
114
+ Autowatchr.any_instance.expects(:open).with(expected_cmd, "r").yields(result)
115
+
116
+ silence_stream(STDOUT) do
117
+ new_autowatchr
118
+ end
119
+ end
120
+
121
+ def test_mapping_test_classes_to_test_files
122
+ aw = nil
123
+ silence_stream(STDOUT) do
124
+ aw = new_autowatchr
125
+ end
126
+ assert_equal "#{@test_dir}/test_foo.rb", aw.classname_to_path("TestFoo")
127
+ end
128
+
129
+ def test_only_runs_failing_tests
130
+ result = fake_result("all")
131
+ Autowatchr.any_instance.stubs(:open).yields(result)
132
+ aw = nil
133
+ silence_stream(STDOUT) do
134
+ aw = new_autowatchr
135
+ end
136
+
137
+ result = fake_result("foo_flunk")
138
+ expected_cmd = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
139
+ aw.expects(:open).with(expected_cmd, "r").yields(result)
140
+
141
+ silence_stream(STDOUT) do
142
+ aw.run_test_file("#{@test_dir}/test_foo.rb")
143
+ end
144
+ end
145
+
146
+ def test_clears_failing_test_when_it_passes
147
+ result = fake_result("all")
148
+ Autowatchr.any_instance.stubs(:open).yields(result)
149
+ aw = nil
150
+ silence_stream(STDOUT) do
151
+ aw = new_autowatchr
152
+ end
153
+
154
+ result = fake_result("foo_pass")
155
+ silence_stream(STDOUT) do
156
+ aw.run_test_file("#{@test_dir}/test_foo.rb")
157
+ end
158
+
159
+ result = fake_result("foo")
160
+ expected_cmd = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb!
161
+ aw.expects(:open).with(expected_cmd, "r").yields(result)
162
+ silence_stream(STDOUT) do
163
+ aw.run_test_file("#{@test_dir}/test_foo.rb")
164
+ end
165
+ end
166
+
167
+ def test_not_only_running_failing_tests
168
+ result = fake_result("all")
169
+ Autowatchr.any_instance.stubs(:open).yields(result)
170
+ aw = nil
171
+ silence_stream(STDOUT) do
172
+ aw = new_autowatchr(:failing_only => false)
173
+ end
174
+
175
+ result = fake_result("foo")
176
+ expected_cmd = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb!
177
+ aw.expects(:open).with(expected_cmd, "r").yields(result)
178
+ silence_stream(STDOUT) do
179
+ aw.run_test_file("#{@test_dir}/test_foo.rb")
180
+ end
181
+ end
182
+
183
+ def test_running_entire_suite_after_green
184
+ result_1 = fake_result("all")
185
+ Autowatchr.any_instance.stubs(:open).yields(result_1)
186
+ aw = nil
187
+ silence_stream(STDOUT) do
188
+ aw = new_autowatchr
189
+ end
190
+
191
+ result_2 = fake_result("foo_pass")
192
+ expected_cmd_2 = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
193
+ aw.expects(:open).with(expected_cmd_2, "r").yields(result_2)
194
+ silence_stream(STDOUT) do
195
+ aw.run_test_file("#{@test_dir}/test_foo.rb")
196
+ end
197
+
198
+ result_3 = fake_result("bar_pass")
199
+ expected_cmd_3 = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_bar.rb -n "/^(test_flunk)$/"!
200
+ aw.expects(:open).with(expected_cmd_3, "r").yields(result_3)
201
+
202
+ files = Dir.glob("#{@test_dir}/**/test_*.rb").join(" ")
203
+ result_4 = fake_result("all")
204
+ expected_cmd_4 = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -e "%w[#{files}].each { |f| require f }"!
205
+ aw.expects(:open).with(expected_cmd_4, "r").yields(result_4)
206
+
207
+ silence_stream(STDOUT) do
208
+ aw.run_test_file("#{@test_dir}/test_bar.rb")
209
+ end
210
+ end
211
+
212
+ def test_not_running_entire_suite_after_green
213
+ result_1 = fake_result("all")
214
+ Autowatchr.any_instance.stubs(:open).yields(result_1)
215
+ aw = nil
216
+ silence_stream(STDOUT) do
217
+ aw = new_autowatchr(:run_suite => false)
218
+ end
219
+
220
+ result_2 = fake_result("foo_pass")
221
+ expected_cmd_2 = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
222
+ aw.expects(:open).with(expected_cmd_2, "r").yields(result_2)
223
+ silence_stream(STDOUT) do
224
+ aw.run_test_file("#{@test_dir}/test_foo.rb")
225
+ end
226
+
227
+ result_3 = fake_result("bar_pass")
228
+ expected_cmd_3 = %!| /usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_bar.rb -n "/^(test_flunk)$/"!
229
+ aw.expects(:open).with(expected_cmd_3, "r").yields(result_3)
230
+
231
+ silence_stream(STDOUT) do
232
+ aw.run_test_file("#{@test_dir}/test_bar.rb")
233
+ end
234
+ end
83
235
  end
data/test.watchr CHANGED
@@ -1,3 +1,5 @@
1
1
  require 'lib/autowatchr'
2
2
 
3
- Autowatchr.new(self)
3
+ Autowatchr.new(self) do |config|
4
+ config.test_re = "^#{config.test_dir}/test_\\w+.rb"
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autowatchr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Stephens
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-30 00:00:00 -05:00
12
+ date: 2009-10-02 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -51,9 +51,17 @@ files:
51
51
  - autowatchr.gemspec
52
52
  - lib/autowatchr.rb
53
53
  - test.watchr
54
+ - test/fixtures/lib/bar.rb
54
55
  - test/fixtures/lib/foo.rb
56
+ - test/fixtures/results/all.txt
57
+ - test/fixtures/results/bar_flunk.txt
58
+ - test/fixtures/results/bar_pass.txt
55
59
  - test/fixtures/results/foo.txt
60
+ - test/fixtures/results/foo_flunk.txt
61
+ - test/fixtures/results/foo_pass.txt
62
+ - test/fixtures/test.watchr
56
63
  - test/fixtures/test/helper.rb
64
+ - test/fixtures/test/test_bar.rb
57
65
  - test/fixtures/test/test_foo.rb
58
66
  - test/helper.rb
59
67
  - test/test_autowatchr.rb
@@ -87,7 +95,9 @@ specification_version: 3
87
95
  summary: Provides some autotest-like behavior for watchr
88
96
  test_files:
89
97
  - test/fixtures/test/test_foo.rb
98
+ - test/fixtures/test/test_bar.rb
90
99
  - test/fixtures/test/helper.rb
100
+ - test/fixtures/lib/bar.rb
91
101
  - test/fixtures/lib/foo.rb
92
102
  - test/test_autowatchr.rb
93
103
  - test/helper.rb