harmon-autowatchr 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +80 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/harmon-autowatchr.gemspec +73 -0
- data/lib/autowatchr.rb +246 -0
- data/test.watchr +6 -0
- data/test/fixtures/lib/bar.rb +2 -0
- data/test/fixtures/lib/foo.rb +2 -0
- data/test/fixtures/results/all.txt +14 -0
- data/test/fixtures/results/bar_flunk.txt +10 -0
- data/test/fixtures/results/bar_pass.txt +6 -0
- data/test/fixtures/results/foo.txt +10 -0
- data/test/fixtures/results/foo_flunk.txt +10 -0
- data/test/fixtures/results/foo_pass.txt +6 -0
- data/test/fixtures/test.watchr +4 -0
- data/test/fixtures/test/helper.rb +1 -0
- data/test/fixtures/test/test_bar.rb +11 -0
- data/test/fixtures/test/test_foo.rb +11 -0
- data/test/helper.rb +49 -0
- data/test/test_autowatchr.rb +271 -0
- metadata +123 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jeremy Stephens
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
= autowatchr
|
2
|
+
|
3
|
+
Provides some autotest-like behavior for watchr (http://github.com/mynyml/watchr).
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem install autowatchr --source http://gemcutter.org
|
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
|
+
* Traps INT signal (Control-C) and re-runs all tests.
|
15
|
+
|
16
|
+
== Todo
|
17
|
+
|
18
|
+
* Cucumber support
|
19
|
+
* Expose algorithm to map test classes to test files
|
20
|
+
|
21
|
+
== Example use
|
22
|
+
|
23
|
+
test.watchr
|
24
|
+
require 'autowatchr'
|
25
|
+
|
26
|
+
Autowatchr.new(self) do |config|
|
27
|
+
config.ruby = 'jruby'
|
28
|
+
config.lib_dir = 'leet_lib'
|
29
|
+
config.test_dir = 'leet_test'
|
30
|
+
end
|
31
|
+
|
32
|
+
=== Configuration options
|
33
|
+
* command
|
34
|
+
* An ERB template for the command
|
35
|
+
* Default: <tt>"<%= ruby %> -I<%= include %> <% list_of_requires.each { |lib| %>-r<%= lib %> <% } %><%= predicate %>"</tt>
|
36
|
+
* ruby
|
37
|
+
* The ruby executable to use
|
38
|
+
* Default: <tt>"ruby"</tt>
|
39
|
+
* run_method
|
40
|
+
* The way the ruby files are "require"-ed.
|
41
|
+
* Two options:
|
42
|
+
* <tt>:default => ruby -e "%w[test/first_test.rb test/second_test.rb].each do |f| require f end"</tt>
|
43
|
+
* <tt>:individual => ruby "test/first_test.rb" "test/second_test.rb"</tt>
|
44
|
+
* include
|
45
|
+
* Paths to include (with -I)
|
46
|
+
* Default: <tt>".:#{self.lib_dir}:#{self.test_dir}"</tt>
|
47
|
+
* require
|
48
|
+
* Libraries to include (with -r)
|
49
|
+
* Can either be a string or an array (Ex: <tt>config.require = %w{rubygems active_support}</tt>)
|
50
|
+
* Default: <tt>nil</tt>
|
51
|
+
* lib_dir
|
52
|
+
* The lib path, where your library lives
|
53
|
+
* Default: <tt>"lib"</tt>
|
54
|
+
* test_dir
|
55
|
+
* The test path, where your tests live
|
56
|
+
* Default: <tt>"test"</tt>
|
57
|
+
* lib_re
|
58
|
+
* The regexp to use for discovering library files
|
59
|
+
* Default: <tt>'^%s.*/.*\.rb$' % self.lib_dir</tt>
|
60
|
+
* test_re
|
61
|
+
* The regexp to use for discovering library files
|
62
|
+
* Default: <tt>'^%s.*/test_.*\.rb$' % self.test_dir</tt>
|
63
|
+
* failing_only
|
64
|
+
* Run only failing tests the next time a test file is run
|
65
|
+
* Default: <tt>true</tt>
|
66
|
+
* run_suite
|
67
|
+
* Run entire test suite after failing tests pass
|
68
|
+
* Default: <tt>true</tt>
|
69
|
+
|
70
|
+
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].
|
71
|
+
|
72
|
+
== Copyright
|
73
|
+
|
74
|
+
Copyright (c) 2009 Jeremy Stephens. See LICENSE for details.
|
75
|
+
|
76
|
+
Many snippets were taken from ZenTest[http://github.com/seattlerb/ZenTest].
|
77
|
+
|
78
|
+
== Contributors
|
79
|
+
|
80
|
+
* Adam Grant (harmon)
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "harmon-autowatchr"
|
8
|
+
gem.summary = %Q{Provides some autotest-like behavior for watchr}
|
9
|
+
gem.description = %Q{Fork of viking's autowatchr library to fix some issues and add some features. Provides some autotest-like behavior for watchr (http://github.com/mynyml/watchr).}
|
10
|
+
gem.email = "harmon@harmonius.net"
|
11
|
+
gem.homepage = "http://github.com/harmon/autowatchr"
|
12
|
+
gem.authors = ["Jeremy Stephens", "Adam Grant"]
|
13
|
+
gem.add_dependency "watchr"
|
14
|
+
gem.add_development_dependency "mocha"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
if File.exist?('VERSION')
|
49
|
+
version = File.read('VERSION')
|
50
|
+
else
|
51
|
+
version = ""
|
52
|
+
end
|
53
|
+
|
54
|
+
rdoc.rdoc_dir = 'rdoc'
|
55
|
+
rdoc.title = "autowatchr #{version}"
|
56
|
+
rdoc.rdoc_files.include('README*')
|
57
|
+
rdoc.rdoc_files.include('lib/*.rb')
|
58
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.5
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{harmon-autowatchr}
|
8
|
+
s.version = "0.1.5"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jeremy Stephens", "Adam Grant"]
|
12
|
+
s.date = %q{2010-12-14}
|
13
|
+
s.description = %q{Fork of viking's autowatchr library to fix some issues and add some features. Provides some autotest-like behavior for watchr (http://github.com/mynyml/watchr).}
|
14
|
+
s.email = %q{harmon@harmonius.net}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"autowatchr.gemspec",
|
26
|
+
"lib/autowatchr.rb",
|
27
|
+
"test.watchr",
|
28
|
+
"test/fixtures/lib/bar.rb",
|
29
|
+
"test/fixtures/lib/foo.rb",
|
30
|
+
"test/fixtures/results/all.txt",
|
31
|
+
"test/fixtures/results/bar_flunk.txt",
|
32
|
+
"test/fixtures/results/bar_pass.txt",
|
33
|
+
"test/fixtures/results/foo.txt",
|
34
|
+
"test/fixtures/results/foo_flunk.txt",
|
35
|
+
"test/fixtures/results/foo_pass.txt",
|
36
|
+
"test/fixtures/test.watchr",
|
37
|
+
"test/fixtures/test/helper.rb",
|
38
|
+
"test/fixtures/test/test_bar.rb",
|
39
|
+
"test/fixtures/test/test_foo.rb",
|
40
|
+
"test/helper.rb",
|
41
|
+
"test/test_autowatchr.rb"
|
42
|
+
]
|
43
|
+
s.homepage = %q{http://github.com/harmon/autowatchr}
|
44
|
+
s.require_paths = ["lib"]
|
45
|
+
s.rubygems_version = %q{1.3.7}
|
46
|
+
s.summary = %q{Provides some autotest-like behavior for watchr}
|
47
|
+
s.test_files = [
|
48
|
+
"test/fixtures/lib/bar.rb",
|
49
|
+
"test/fixtures/lib/foo.rb",
|
50
|
+
"test/fixtures/test/helper.rb",
|
51
|
+
"test/fixtures/test/test_bar.rb",
|
52
|
+
"test/fixtures/test/test_foo.rb",
|
53
|
+
"test/helper.rb",
|
54
|
+
"test/test_autowatchr.rb"
|
55
|
+
]
|
56
|
+
|
57
|
+
if s.respond_to? :specification_version then
|
58
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
59
|
+
s.specification_version = 3
|
60
|
+
|
61
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
62
|
+
s.add_runtime_dependency(%q<watchr>, [">= 0"])
|
63
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<watchr>, [">= 0"])
|
66
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<watchr>, [">= 0"])
|
70
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
data/lib/autowatchr.rb
ADDED
@@ -0,0 +1,246 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
class Autowatchr
|
5
|
+
class Config
|
6
|
+
attr_writer :command, :ruby, :include, :require, :lib_dir, :test_dir,
|
7
|
+
:lib_re, :test_re, :failed_results_re, :completed_re, :failing_only,
|
8
|
+
:run_suite, :run_method
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@failing_only = @run_suite = true
|
12
|
+
|
13
|
+
options.each_pair do |key, value|
|
14
|
+
method = "#{key}="
|
15
|
+
if self.respond_to?(method)
|
16
|
+
self.send(method, value)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_method
|
22
|
+
@run_method ||= :require
|
23
|
+
end
|
24
|
+
|
25
|
+
def command
|
26
|
+
@command ||= "<%= ruby %> -I<%= include %> <% list_of_requires.each { |lib| %>-r<%= lib %> <% } %><%= predicate %>"
|
27
|
+
end
|
28
|
+
|
29
|
+
def ruby
|
30
|
+
@ruby ||= "ruby"
|
31
|
+
end
|
32
|
+
|
33
|
+
def include
|
34
|
+
@include ||= ".:#{self.lib_dir}:#{self.test_dir}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def require
|
38
|
+
@require
|
39
|
+
end
|
40
|
+
|
41
|
+
def list_of_requires
|
42
|
+
if @require.nil? || @require.empty?
|
43
|
+
[]
|
44
|
+
elsif @require.is_a?(Array)
|
45
|
+
@require
|
46
|
+
else
|
47
|
+
[@require]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def lib_dir
|
52
|
+
@lib_dir ||= "lib"
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_dir
|
56
|
+
@test_dir ||= "test"
|
57
|
+
end
|
58
|
+
|
59
|
+
def lib_re
|
60
|
+
@lib_re ||= '^%s.*/.*\.rb$' % self.lib_dir
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_re
|
64
|
+
@test_re ||= '^%s.*/test_.*\.rb$' % self.test_dir
|
65
|
+
end
|
66
|
+
|
67
|
+
def failed_results_re
|
68
|
+
@failed_results_re ||= /^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?)\)/
|
69
|
+
end
|
70
|
+
|
71
|
+
def completed_re
|
72
|
+
@completed_re ||= /\d+ tests, \d+ assertions, \d+ failures, \d+ errors/
|
73
|
+
end
|
74
|
+
|
75
|
+
def failing_only
|
76
|
+
@failing_only
|
77
|
+
end
|
78
|
+
|
79
|
+
def run_suite
|
80
|
+
@run_suite
|
81
|
+
end
|
82
|
+
|
83
|
+
def eval_command(predicate)
|
84
|
+
ERB.new(self.command).result(binding)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
class Tee < StringIO
|
89
|
+
attr_reader :io
|
90
|
+
def initialize(io)
|
91
|
+
super("")
|
92
|
+
@io = io
|
93
|
+
end
|
94
|
+
|
95
|
+
def write(string)
|
96
|
+
super
|
97
|
+
@io.write(string)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
attr_reader :config
|
102
|
+
attr_accessor :interrupt_received
|
103
|
+
|
104
|
+
def initialize(script, options = {})
|
105
|
+
@config = Config.new(options)
|
106
|
+
yield @config if block_given?
|
107
|
+
@script = script
|
108
|
+
@test_files = []
|
109
|
+
@failed_tests = {}
|
110
|
+
|
111
|
+
discover_files
|
112
|
+
run_all_tests
|
113
|
+
start_watching_files
|
114
|
+
start_sigint_handler
|
115
|
+
end
|
116
|
+
|
117
|
+
# Traps any INT signals (like Control-C) and re-runs all
|
118
|
+
# the tests, unless the user sends the INT signal again within
|
119
|
+
# 2 seconds.
|
120
|
+
def start_sigint_handler
|
121
|
+
Signal.trap 'INT' do
|
122
|
+
if self.interrupt_received
|
123
|
+
exit 0
|
124
|
+
else
|
125
|
+
self.interrupt_received = true
|
126
|
+
puts "\nInterrupt a second time to quit"
|
127
|
+
Kernel.sleep 2
|
128
|
+
self.interrupt_received = false
|
129
|
+
puts "Running all tests..."
|
130
|
+
run_all_tests
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def run_lib_file(file)
|
136
|
+
md = file.match(%r{^#{@config.lib_dir}#{File::SEPARATOR}?(.+)$})
|
137
|
+
parts = md[1].split(File::SEPARATOR)
|
138
|
+
parts[-1] = "test_#{parts[-1]}"
|
139
|
+
file = "#{@config.test_dir}/" + File.join(parts)
|
140
|
+
run_test_file(file)
|
141
|
+
end
|
142
|
+
|
143
|
+
def run_test_file(files)
|
144
|
+
files = [files] unless files.is_a?(Array)
|
145
|
+
|
146
|
+
passing = []
|
147
|
+
commands = []
|
148
|
+
files.each do |file|
|
149
|
+
tests = @failed_tests[file]
|
150
|
+
if tests && !tests.empty?
|
151
|
+
predicate = %!#{file} -n "/^(#{tests.join("|")})$/"!
|
152
|
+
commands << @config.eval_command(predicate)
|
153
|
+
else
|
154
|
+
passing << file
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
if !passing.empty?
|
159
|
+
if passing.length > 1
|
160
|
+
if @config.run_method == :individual
|
161
|
+
predicate = "'#{passing.join("' '")}'"
|
162
|
+
else
|
163
|
+
predicate = "-e \"%w[#{passing.join(" ")}].each do |f| require f end\""
|
164
|
+
end
|
165
|
+
else
|
166
|
+
predicate = passing[0]
|
167
|
+
end
|
168
|
+
commands.unshift(@config.eval_command(predicate))
|
169
|
+
end
|
170
|
+
|
171
|
+
cmd = commands.join("; ")
|
172
|
+
puts cmd
|
173
|
+
|
174
|
+
results = execute_cmd(cmd)
|
175
|
+
handle_results(results, files)
|
176
|
+
end
|
177
|
+
|
178
|
+
def classname_to_path(s)
|
179
|
+
File.join(@config.test_dir, underscore(s)+".rb")
|
180
|
+
end
|
181
|
+
|
182
|
+
private
|
183
|
+
def discover_files
|
184
|
+
@test_files = Dir.glob("#{@config.test_dir}/**/*").grep(/#{@config.test_re}/)
|
185
|
+
end
|
186
|
+
|
187
|
+
def run_all_tests
|
188
|
+
run_test_file(@test_files)
|
189
|
+
end
|
190
|
+
|
191
|
+
def start_watching_files
|
192
|
+
@script.watch(@config.test_re) { |md| run_test_file(md[0]) }
|
193
|
+
@script.watch(@config.lib_re) { |md| run_lib_file(md[0]) }
|
194
|
+
end
|
195
|
+
|
196
|
+
def execute_cmd(cmd)
|
197
|
+
tee = Tee.new($stdout)
|
198
|
+
$stdout = tee
|
199
|
+
|
200
|
+
system(cmd)
|
201
|
+
|
202
|
+
$stdout = tee.io
|
203
|
+
tee.rewind
|
204
|
+
results = tee.read
|
205
|
+
tee.close
|
206
|
+
|
207
|
+
results
|
208
|
+
end
|
209
|
+
|
210
|
+
def handle_results(results, files_ran)
|
211
|
+
return if !@config.failing_only
|
212
|
+
num_previously_failed = @failed_tests.length
|
213
|
+
|
214
|
+
failed = results.scan(@config.failed_results_re)
|
215
|
+
completed = results =~ @config.completed_re
|
216
|
+
|
217
|
+
previously_failed = @failed_tests.keys & files_ran
|
218
|
+
failed.each do |(test_name, class_name)|
|
219
|
+
key = classname_to_path(class_name)
|
220
|
+
if files_ran.include?(key)
|
221
|
+
@failed_tests[key] ||= []
|
222
|
+
@failed_tests[key] |= [test_name]
|
223
|
+
previously_failed.delete(key)
|
224
|
+
else
|
225
|
+
puts "Couldn't map class to file: #{class_name}"
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
previously_failed.each do |file|
|
230
|
+
@failed_tests.delete(file)
|
231
|
+
end
|
232
|
+
|
233
|
+
if @config.run_suite && @failed_tests.empty? && num_previously_failed > 0
|
234
|
+
run_all_tests
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
# File vendor/rails/activesupport/lib/active_support/inflector.rb, line 206
|
239
|
+
def underscore(camel_cased_word)
|
240
|
+
camel_cased_word.to_s.gsub(/::/, '/').
|
241
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
242
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
243
|
+
tr("-", "_").
|
244
|
+
downcase
|
245
|
+
end
|
246
|
+
end
|
data/test.watchr
ADDED
@@ -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 @@
|
|
1
|
+
require 'test/unit'
|
data/test/helper.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'mocha'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
+
require 'autowatchr'
|
8
|
+
|
9
|
+
class Test::Unit::TestCase
|
10
|
+
end
|
11
|
+
|
12
|
+
module Mocha::ObjectMethods
|
13
|
+
def stubs_system_call(result_name = nil)
|
14
|
+
self.stubs(:system).with() do |_|
|
15
|
+
$stdout.print(result_name ? fake_result(result_name) : "")
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def expects_system_call(expected_command, result_name = nil)
|
21
|
+
self.expects(:system).with() do |actual_command|
|
22
|
+
if expected_command == actual_command
|
23
|
+
$stdout.print(result_name ? fake_result(result_name) : "")
|
24
|
+
true
|
25
|
+
else
|
26
|
+
false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def fake_result(name)
|
33
|
+
open(File.dirname(__FILE__) + "/fixtures/results/#{name}.txt").read
|
34
|
+
end
|
35
|
+
|
36
|
+
# File vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 36
|
37
|
+
def silence_stream(stream)
|
38
|
+
old_stream = stream.dup
|
39
|
+
stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
|
40
|
+
stream.sync = true
|
41
|
+
yield
|
42
|
+
ensure
|
43
|
+
stream.reopen(old_stream)
|
44
|
+
end
|
45
|
+
|
46
|
+
def debug_p(obj, label = nil)
|
47
|
+
$stderr.print "#{label}: " if label
|
48
|
+
$stderr.puts obj.inspect
|
49
|
+
end
|
@@ -0,0 +1,271 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestAutowatchr < Test::Unit::TestCase
|
4
|
+
def new_autowatchr(options = {})
|
5
|
+
Autowatchr.new(@script, {
|
6
|
+
:ruby => "/usr/local/bin/ruby",
|
7
|
+
:lib_dir => @lib_dir,
|
8
|
+
:test_dir => @test_dir
|
9
|
+
}.merge(options))
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@script = stub("fake watchr script", :watch => nil)
|
14
|
+
@lib_dir = File.dirname(__FILE__) + "/fixtures/lib"
|
15
|
+
@test_dir = File.dirname(__FILE__) + "/fixtures/test"
|
16
|
+
Autowatchr.any_instance.stubs_system_call
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_new_with_hash
|
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
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_new_with_block
|
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
|
40
|
+
end
|
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
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_auto_includes
|
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
|
55
|
+
end
|
56
|
+
assert_equal ".:#{@lib_dir}:#{@test_dir}", aw.config.include
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_defaults
|
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 nil, aw.config.require
|
67
|
+
assert_equal "lib", aw.config.lib_dir
|
68
|
+
assert_equal "test", aw.config.test_dir
|
69
|
+
assert_equal '^lib.*/.*\.rb$', aw.config.lib_re
|
70
|
+
assert_equal '^test.*/test_.*\.rb$', aw.config.test_re
|
71
|
+
assert_equal /^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?)\)/, aw.config.failed_results_re
|
72
|
+
assert_equal /\d+ tests, \d+ assertions, \d+ failures, \d+ errors/, aw.config.completed_re
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_watches_test_files
|
76
|
+
@script.expects(:watch).with('^%s.*/test_.*\.rb$' % @test_dir)
|
77
|
+
silence_stream(STDOUT) do
|
78
|
+
new_autowatchr
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_watches_lib_files
|
83
|
+
@script.expects(:watch).with('^%s.*/.*\.rb$' % @lib_dir)
|
84
|
+
silence_stream(STDOUT) do
|
85
|
+
new_autowatchr
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_run_lib_file
|
90
|
+
expected_cmd = "/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb"
|
91
|
+
Autowatchr.any_instance.expects_system_call(expected_cmd, "foo")
|
92
|
+
|
93
|
+
silence_stream(STDOUT) do
|
94
|
+
aw = new_autowatchr
|
95
|
+
aw.run_lib_file("#{@lib_dir}/foo.rb")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_run_lib_file_with_require
|
100
|
+
expected_cmd = "/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -rrubygems #{@test_dir}/test_foo.rb"
|
101
|
+
Autowatchr.any_instance.expects_system_call(expected_cmd, "foo")
|
102
|
+
|
103
|
+
silence_stream(STDOUT) do
|
104
|
+
aw = new_autowatchr(:require => 'rubygems')
|
105
|
+
aw.run_lib_file("#{@lib_dir}/foo.rb")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_run_lib_file_with_mulitple_requires
|
110
|
+
expected_cmd = "/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -rrubygems -rblah #{@test_dir}/test_foo.rb"
|
111
|
+
Autowatchr.any_instance.expects_system_call(expected_cmd, "foo")
|
112
|
+
|
113
|
+
silence_stream(STDOUT) do
|
114
|
+
aw = new_autowatchr(:require => %w{rubygems blah})
|
115
|
+
aw.run_lib_file("#{@lib_dir}/foo.rb")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_running_multiple_test_files_with_require_run_method
|
120
|
+
expected_cmd = "/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -e \"%w[#{@test_dir}/test_bar.rb #{@test_dir}/test_foo.rb].each do |f| require f end\""
|
121
|
+
Autowatchr.any_instance.expects_system_call(expected_cmd, "all")
|
122
|
+
|
123
|
+
silence_stream(STDOUT) do
|
124
|
+
aw = new_autowatchr
|
125
|
+
aw.run_test_file(["#{@test_dir}/test_bar.rb", "#{@test_dir}/test_foo.rb"])
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_running_multiple_test_files_with_individual_run_method
|
130
|
+
expected_cmd = "/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} '#{@test_dir}/test_bar.rb' '#{@test_dir}/test_foo.rb'"
|
131
|
+
Autowatchr.any_instance.expects_system_call(expected_cmd, "all")
|
132
|
+
|
133
|
+
silence_stream(STDOUT) do
|
134
|
+
aw = new_autowatchr(:run_method => :individual)
|
135
|
+
aw.run_test_file(["#{@test_dir}/test_bar.rb", "#{@test_dir}/test_foo.rb"])
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_runs_all_test_files_on_start
|
140
|
+
files = Dir.glob("#{@test_dir}/**/test_*.rb").join(" ")
|
141
|
+
expected_cmd = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -e "%w[#{files}].each do |f| require f end"!
|
142
|
+
Autowatchr.any_instance.expects_system_call(expected_cmd, "all")
|
143
|
+
|
144
|
+
silence_stream(STDOUT) do
|
145
|
+
new_autowatchr
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_mapping_test_classes_to_test_files
|
150
|
+
aw = nil
|
151
|
+
silence_stream(STDOUT) do
|
152
|
+
aw = new_autowatchr
|
153
|
+
end
|
154
|
+
assert_equal "#{@test_dir}/test_foo.rb", aw.classname_to_path("TestFoo")
|
155
|
+
assert_equal "#{@test_dir}/test_foo/test_baz.rb", aw.classname_to_path("TestFoo::TestBaz")
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_only_runs_failing_tests
|
159
|
+
Autowatchr.any_instance.stubs_system_call("all")
|
160
|
+
aw = nil
|
161
|
+
silence_stream(STDOUT) do
|
162
|
+
aw = new_autowatchr
|
163
|
+
end
|
164
|
+
|
165
|
+
expected_cmd = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
|
166
|
+
aw.expects_system_call(expected_cmd, "foo_flunk")
|
167
|
+
|
168
|
+
silence_stream(STDOUT) do
|
169
|
+
aw.run_test_file("#{@test_dir}/test_foo.rb")
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_only_registers_failing_test_once
|
174
|
+
Autowatchr.any_instance.stubs_system_call("all")
|
175
|
+
aw = nil
|
176
|
+
silence_stream(STDOUT) do
|
177
|
+
aw = new_autowatchr
|
178
|
+
end
|
179
|
+
|
180
|
+
expected_cmd = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
|
181
|
+
aw.expects_system_call(expected_cmd, "foo_flunk")
|
182
|
+
silence_stream(STDOUT) do
|
183
|
+
aw.run_test_file("#{@test_dir}/test_foo.rb")
|
184
|
+
end
|
185
|
+
|
186
|
+
expected_cmd = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
|
187
|
+
aw.expects_system_call(expected_cmd, "foo_flunk")
|
188
|
+
silence_stream(STDOUT) do
|
189
|
+
aw.run_test_file("#{@test_dir}/test_foo.rb")
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_clears_failing_test_when_it_passes
|
194
|
+
Autowatchr.any_instance.stubs_system_call("all")
|
195
|
+
aw = nil
|
196
|
+
silence_stream(STDOUT) do
|
197
|
+
aw = new_autowatchr
|
198
|
+
end
|
199
|
+
|
200
|
+
aw.stubs_system_call("foo_pass")
|
201
|
+
silence_stream(STDOUT) do
|
202
|
+
aw.run_test_file("#{@test_dir}/test_foo.rb")
|
203
|
+
end
|
204
|
+
|
205
|
+
expected_cmd = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb!
|
206
|
+
aw.expects_system_call(expected_cmd, "foo")
|
207
|
+
silence_stream(STDOUT) do
|
208
|
+
aw.run_test_file("#{@test_dir}/test_foo.rb")
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_not_only_running_failing_tests
|
213
|
+
Autowatchr.any_instance.stubs_system_call("all")
|
214
|
+
aw = nil
|
215
|
+
silence_stream(STDOUT) do
|
216
|
+
aw = new_autowatchr(:failing_only => false)
|
217
|
+
end
|
218
|
+
|
219
|
+
expected_cmd = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb!
|
220
|
+
aw.expects_system_call(expected_cmd, "foo")
|
221
|
+
silence_stream(STDOUT) do
|
222
|
+
aw.run_test_file("#{@test_dir}/test_foo.rb")
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_running_entire_suite_after_green
|
227
|
+
Autowatchr.any_instance.stubs_system_call("all")
|
228
|
+
aw = nil
|
229
|
+
silence_stream(STDOUT) do
|
230
|
+
aw = new_autowatchr
|
231
|
+
end
|
232
|
+
|
233
|
+
expected_cmd_2 = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
|
234
|
+
aw.expects_system_call(expected_cmd_2, "foo_pass")
|
235
|
+
silence_stream(STDOUT) do
|
236
|
+
aw.run_test_file("#{@test_dir}/test_foo.rb")
|
237
|
+
end
|
238
|
+
|
239
|
+
expected_cmd_3 = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_bar.rb -n "/^(test_flunk)$/"!
|
240
|
+
aw.expects_system_call(expected_cmd_3, "bar_pass")
|
241
|
+
|
242
|
+
files = Dir.glob("#{@test_dir}/**/test_*.rb").join(" ")
|
243
|
+
expected_cmd_4 = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} -e "%w[#{files}].each do |f| require f end"!
|
244
|
+
aw.expects_system_call(expected_cmd_4, "all")
|
245
|
+
|
246
|
+
silence_stream(STDOUT) do
|
247
|
+
aw.run_test_file("#{@test_dir}/test_bar.rb")
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def test_not_running_entire_suite_after_green
|
252
|
+
Autowatchr.any_instance.stubs_system_call("all")
|
253
|
+
aw = nil
|
254
|
+
silence_stream(STDOUT) do
|
255
|
+
aw = new_autowatchr(:run_suite => false)
|
256
|
+
end
|
257
|
+
|
258
|
+
expected_cmd_2 = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_foo.rb -n "/^(test_flunk)$/"!
|
259
|
+
aw.expects_system_call(expected_cmd_2, "foo_pass")
|
260
|
+
silence_stream(STDOUT) do
|
261
|
+
aw.run_test_file("#{@test_dir}/test_foo.rb")
|
262
|
+
end
|
263
|
+
|
264
|
+
expected_cmd_3 = %!/usr/local/bin/ruby -I.:#{@lib_dir}:#{@test_dir} #{@test_dir}/test_bar.rb -n "/^(test_flunk)$/"!
|
265
|
+
aw.expects_system_call(expected_cmd_3, "bar_pass")
|
266
|
+
|
267
|
+
silence_stream(STDOUT) do
|
268
|
+
aw.run_test_file("#{@test_dir}/test_bar.rb")
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: harmon-autowatchr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jeremy Stephens
|
14
|
+
- Adam Grant
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-12-14 00:00:00 -08:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: watchr
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mocha
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
description: Fork of viking's autowatchr library to fix some issues and add some features. Provides some autotest-like behavior for watchr (http://github.com/mynyml/watchr).
|
51
|
+
email: harmon@harmonius.net
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files:
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
files:
|
60
|
+
- .document
|
61
|
+
- LICENSE
|
62
|
+
- README.rdoc
|
63
|
+
- Rakefile
|
64
|
+
- VERSION
|
65
|
+
- harmon-autowatchr.gemspec
|
66
|
+
- lib/autowatchr.rb
|
67
|
+
- test.watchr
|
68
|
+
- test/fixtures/lib/bar.rb
|
69
|
+
- test/fixtures/lib/foo.rb
|
70
|
+
- test/fixtures/results/all.txt
|
71
|
+
- test/fixtures/results/bar_flunk.txt
|
72
|
+
- test/fixtures/results/bar_pass.txt
|
73
|
+
- test/fixtures/results/foo.txt
|
74
|
+
- test/fixtures/results/foo_flunk.txt
|
75
|
+
- test/fixtures/results/foo_pass.txt
|
76
|
+
- test/fixtures/test.watchr
|
77
|
+
- test/fixtures/test/helper.rb
|
78
|
+
- test/fixtures/test/test_bar.rb
|
79
|
+
- test/fixtures/test/test_foo.rb
|
80
|
+
- test/helper.rb
|
81
|
+
- test/test_autowatchr.rb
|
82
|
+
has_rdoc: true
|
83
|
+
homepage: http://github.com/harmon/autowatchr
|
84
|
+
licenses: []
|
85
|
+
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
requirements: []
|
110
|
+
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 1.3.7
|
113
|
+
signing_key:
|
114
|
+
specification_version: 3
|
115
|
+
summary: Provides some autotest-like behavior for watchr
|
116
|
+
test_files:
|
117
|
+
- test/fixtures/lib/bar.rb
|
118
|
+
- test/fixtures/lib/foo.rb
|
119
|
+
- test/fixtures/test/helper.rb
|
120
|
+
- test/fixtures/test/test_bar.rb
|
121
|
+
- test/fixtures/test/test_foo.rb
|
122
|
+
- test/helper.rb
|
123
|
+
- test/test_autowatchr.rb
|