Narnach-minitest 0.2.1 → 0.2.2
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/bin/minitest +4 -1
- data/lib/dir_monitor.rb +45 -1
- data/spec/dir_monitor_spec.rb +155 -44
- metadata +2 -2
data/bin/minitest
CHANGED
@@ -4,5 +4,8 @@ require 'minitest'
|
|
4
4
|
|
5
5
|
minitest = Minitest.new
|
6
6
|
minitest.recent = (ARGV.include? "recent")
|
7
|
-
|
7
|
+
custom_spec_opts = ''
|
8
|
+
custom_spec_opts << " --drb" if ARGV.include? "drb"
|
9
|
+
custom_spec_opts << " --format profile --colour --diff unified" if ARGV.include? "profile"
|
10
|
+
minitest.spec_opts = custom_spec_opts if custom_spec_opts.size > 0
|
8
11
|
minitest.start
|
data/lib/dir_monitor.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# - Keep track of changed files in monitored directories.
|
5
5
|
# - Link these files to their specs, so Minitest can run the specs.
|
6
6
|
class DirMonitor
|
7
|
-
attr_reader :known_files, :dirs
|
7
|
+
attr_reader :known_files, :dirs, :last_mtime
|
8
8
|
|
9
9
|
# Setup a new DirMonitor.
|
10
10
|
# Directories can be provided in a number of ways:
|
@@ -15,6 +15,7 @@ class DirMonitor
|
|
15
15
|
def initialize(*dirs)
|
16
16
|
@dirs = dirs.flatten.map{|dir| dir.to_s}
|
17
17
|
@known_files = []
|
18
|
+
@last_mtime = {}
|
18
19
|
end
|
19
20
|
|
20
21
|
# Scan for all files in the directories and their sub-directories.
|
@@ -28,6 +29,29 @@ class DirMonitor
|
|
28
29
|
@known_files = results
|
29
30
|
end
|
30
31
|
|
32
|
+
# Scan for changes in the known files.
|
33
|
+
# Yields the name of the changed files.
|
34
|
+
# Stores the mtime for all changed files.
|
35
|
+
def scan_changed(&block) # :yields: file
|
36
|
+
known_files.each do |known_file|
|
37
|
+
new_mtime = mtime_for(known_file)
|
38
|
+
if new_mtime != last_mtime[known_file]
|
39
|
+
block.call(known_file)
|
40
|
+
last_mtime[known_file]= new_mtime
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Scans for changed known files, using #scan_changed. Yields the name of both the file and its associated spec.
|
46
|
+
# spec_for is used to determine what the name of the file's spec _should_ be.
|
47
|
+
# Does not yield a file/spec name when the spec does not exist.
|
48
|
+
def scan_changed_with_spec(&block) # :yields: file, spec
|
49
|
+
scan_changed do |file|
|
50
|
+
spec = spec_for(file)
|
51
|
+
block.call(file, spec) if File.exists?(spec)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
31
55
|
# Scan for new files.
|
32
56
|
# All new file names are yielded.
|
33
57
|
def scan_new(&block) # :yields: file
|
@@ -39,6 +63,19 @@ class DirMonitor
|
|
39
63
|
end
|
40
64
|
end
|
41
65
|
|
66
|
+
# Scan for new files and check for changed known files.
|
67
|
+
# Only yields a file once per call.
|
68
|
+
def scan_new_or_changed_with_spec(&block) # :yields: file, spec
|
69
|
+
yielded_files = {}
|
70
|
+
yield_once_block = Proc.new do |file, spec|
|
71
|
+
next if yielded_files.has_key? file
|
72
|
+
block.call(file, spec)
|
73
|
+
yielded_files[file]=nil
|
74
|
+
end
|
75
|
+
scan_new_with_spec(&yield_once_block)
|
76
|
+
scan_changed_with_spec(&yield_once_block)
|
77
|
+
end
|
78
|
+
|
42
79
|
# Scans for new files, like scan_new does, but yields the name of both the file and spec.
|
43
80
|
# spec_for is used to determine what the name of the file's spec _should_ be.
|
44
81
|
# Does not yield a file/spec name when the spec does not exist.
|
@@ -73,4 +110,11 @@ class DirMonitor
|
|
73
110
|
spec_dir = dir_array.join('/')
|
74
111
|
return File.join(spec_dir, spec_file)
|
75
112
|
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
# Get the modification time for a file.
|
117
|
+
def mtime_for(file)
|
118
|
+
File.mtime(file)
|
119
|
+
end
|
76
120
|
end
|
data/spec/dir_monitor_spec.rb
CHANGED
@@ -31,77 +31,188 @@ describe DirMonitor, "#scan" do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
describe DirMonitor, "#scan_new" do
|
34
|
+
before(:each) do
|
35
|
+
@known_files = %w[lib/minitest.rb lib/dir_monitor.rb]
|
36
|
+
Dir.stub!(:glob).with('lib/**/*').and_return(@known_files)
|
37
|
+
@dm = DirMonitor.new 'lib'
|
38
|
+
end
|
39
|
+
|
34
40
|
it "should yield the names of all new files" do
|
35
|
-
known_files = %w[lib/minitest.rb lib/dir_monitor.rb]
|
36
|
-
Dir.should_receive(:glob).with('lib/**/*').and_return(known_files)
|
37
|
-
dm = DirMonitor.new('lib')
|
38
41
|
yield_results = []
|
39
|
-
dm.scan_new do |file|
|
42
|
+
@dm.scan_new do |file|
|
40
43
|
yield_results << file
|
41
44
|
end
|
42
|
-
yield_results.should == known_files
|
45
|
+
yield_results.should == @known_files
|
43
46
|
end
|
44
47
|
|
45
48
|
it "should not yield known file names" do
|
46
|
-
known_files = %w[lib/minitest.rb lib/dir_monitor.rb]
|
47
49
|
known_files2 = %w[lib/minitest.rb lib/dir_monitor2.rb]
|
48
|
-
Dir.
|
49
|
-
dm
|
50
|
-
dm.scan
|
50
|
+
Dir.stub!(:glob).with('lib/**/*').and_return(@known_files, known_files2)
|
51
|
+
@dm.scan
|
51
52
|
yield_results = []
|
52
|
-
dm.scan_new do |file|
|
53
|
+
@dm.scan_new do |file|
|
53
54
|
yield_results << file
|
54
55
|
end
|
55
|
-
yield_results.should == known_files2 - known_files
|
56
|
+
yield_results.should == known_files2 - @known_files
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
59
|
-
describe DirMonitor, "#
|
60
|
-
|
61
|
-
file = 'lib/dir_monitor.rb'
|
62
|
-
spec = 'spec/dir_monitor_spec.rb'
|
63
|
-
|
64
|
-
dm.
|
60
|
+
describe DirMonitor, "#scan_new_with_spec" do
|
61
|
+
before :each do
|
62
|
+
@file = 'lib/dir_monitor.rb'
|
63
|
+
@spec = 'spec/dir_monitor_spec.rb'
|
64
|
+
Dir.stub!(:glob).with('lib/**/*').and_return([@file])
|
65
|
+
@dm = DirMonitor.new 'lib'
|
65
66
|
end
|
66
67
|
|
67
|
-
it "should
|
68
|
-
|
69
|
-
|
70
|
-
dm
|
71
|
-
|
68
|
+
it "should yield new files and their specs" do
|
69
|
+
File.should_receive(:exists?).with(@spec).and_return(true)
|
70
|
+
results = []
|
71
|
+
@dm.scan_new_with_spec do |new_file, new_spec|
|
72
|
+
results << {new_file => new_spec}
|
73
|
+
end
|
74
|
+
results.should == [{@file=>@spec}]
|
72
75
|
end
|
73
76
|
|
74
|
-
it "should
|
75
|
-
spec
|
76
|
-
|
77
|
-
dm.
|
77
|
+
it "should not yield files with non-existent specs" do
|
78
|
+
File.should_receive(:exists?).with(@spec).and_return(false)
|
79
|
+
results = []
|
80
|
+
@dm.scan_new_with_spec do |new_file, new_spec|
|
81
|
+
results << {new_file => new_spec}
|
82
|
+
end
|
83
|
+
results.should == []
|
78
84
|
end
|
79
85
|
end
|
80
86
|
|
81
|
-
describe DirMonitor, "#
|
82
|
-
|
83
|
-
file = 'lib/dir_monitor.rb'
|
84
|
-
|
85
|
-
Dir.
|
86
|
-
File.
|
87
|
-
dm = DirMonitor.new 'lib'
|
87
|
+
describe DirMonitor, "#scan_changed" do
|
88
|
+
before(:each) do
|
89
|
+
@file = 'lib/dir_monitor.rb'
|
90
|
+
@time = Time.now
|
91
|
+
Dir.stub!(:glob).with('lib/**/*').and_return([@file])
|
92
|
+
File.stub!(:mtime).with(@file).and_return(@time)
|
93
|
+
@dm = DirMonitor.new 'lib'
|
94
|
+
@dm.scan
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should yield the names of changed known files" do
|
98
|
+
changes = []
|
99
|
+
@dm.scan_changed do |changed_file|
|
100
|
+
changes << changed_file
|
101
|
+
end
|
102
|
+
changes.should == [@file]
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should not yield the names of files which did not change since last scan" do
|
106
|
+
@dm.scan_changed { |f| }
|
107
|
+
changes = []
|
108
|
+
@dm.scan_changed do |changed_file|
|
109
|
+
changes << changed_file
|
110
|
+
end
|
111
|
+
changes.should == []
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should yield for every change in a file" do
|
115
|
+
# Every scan should find the file changed:
|
116
|
+
File.should_receive(:mtime).with(@file).and_return(@time-3,@time-2,@time-1)
|
117
|
+
3.times do
|
118
|
+
changes = []
|
119
|
+
@dm.scan_changed do |changed_file|
|
120
|
+
changes << changed_file
|
121
|
+
end
|
122
|
+
changes.should == [@file]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe DirMonitor, "scan_changed_with_spec" do
|
128
|
+
before(:each) do
|
129
|
+
@file = 'lib/dir_monitor.rb'
|
130
|
+
@spec = 'spec/dir_monitor_spec.rb'
|
131
|
+
@time = Time.now
|
132
|
+
Dir.stub!(:glob).with('lib/**/*').and_return([@file])
|
133
|
+
File.stub!(:mtime).with(@file).and_return(@time)
|
134
|
+
@dm = DirMonitor.new 'lib'
|
135
|
+
@dm.scan
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should yield the file name and spec name of changed files with an existing spec" do
|
139
|
+
File.should_receive(:exists?).with(@spec).and_return(true)
|
140
|
+
changes = []
|
141
|
+
@dm.scan_changed_with_spec do |changed_file, spec_file|
|
142
|
+
changes << { changed_file => spec_file }
|
143
|
+
end
|
144
|
+
changes.should == [{@file=>@spec}]
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should not yield the file name and spec name of changed files without an existing spec" do
|
148
|
+
File.should_receive(:exists?).with(@spec).and_return(false)
|
149
|
+
changes = []
|
150
|
+
@dm.scan_changed_with_spec do |changed_file, spec_file|
|
151
|
+
changes << { changed_file => spec_file }
|
152
|
+
end
|
153
|
+
changes.should == []
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe DirMonitor, "scan_new_or_changed_with_spec" do
|
158
|
+
before(:each) do
|
159
|
+
@file = 'lib/dir_monitor.rb'
|
160
|
+
@spec = 'spec/dir_monitor_spec.rb'
|
161
|
+
@time = Time.now
|
162
|
+
Dir.stub!(:glob).with('lib/**/*').and_return([@file])
|
163
|
+
File.stub!(:mtime).with(@file).and_return(@time)
|
164
|
+
@dm = DirMonitor.new 'lib'
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should yield a file and spec when a file is new" do
|
88
168
|
results = []
|
89
|
-
dm.
|
90
|
-
results << {
|
169
|
+
@dm.scan_new_or_changed_with_spec do |file, spec|
|
170
|
+
results << {file => spec}
|
91
171
|
end
|
92
|
-
results.should == [{file
|
172
|
+
results.should == [{@file=>@spec}]
|
93
173
|
end
|
94
174
|
|
95
|
-
it "should not
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
File.should_receive(:exists?).with(spec).and_return(false)
|
100
|
-
dm = DirMonitor.new 'lib'
|
175
|
+
it "should yield a file and spec when a file is not new but has changed" do
|
176
|
+
@dm.scan
|
177
|
+
@dm.scan_changed {|f|}
|
178
|
+
File.should_receive(:mtime).with(@file).and_return(@time+1)
|
101
179
|
results = []
|
102
|
-
dm.
|
103
|
-
results << {
|
180
|
+
@dm.scan_new_or_changed_with_spec do |file, spec|
|
181
|
+
results << {file => spec}
|
182
|
+
end
|
183
|
+
results.should == [{@file=>@spec}]
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should not yield a file and spec when a file is not new and has not changed" do
|
187
|
+
@dm.scan
|
188
|
+
@dm.scan_changed {|f|}
|
189
|
+
results = []
|
190
|
+
@dm.scan_new_or_changed_with_spec do |file, spec|
|
191
|
+
results << {file => spec}
|
104
192
|
end
|
105
193
|
results.should == []
|
106
194
|
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe DirMonitor, "#spec_for" do
|
198
|
+
before(:each) do
|
199
|
+
@dm = DirMonitor.new
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should find the spec for a given file" do
|
203
|
+
file = 'lib/dir_monitor.rb'
|
204
|
+
spec = 'spec/dir_monitor_spec.rb'
|
205
|
+
@dm.spec_for(file).should == spec
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should find the spec for non-ruby files" do
|
209
|
+
file = 'app/views/posts/post.html.haml'
|
210
|
+
spec = 'spec/views/posts/post.html.haml_spec.rb'
|
211
|
+
@dm.spec_for(file).should == spec
|
212
|
+
end
|
213
|
+
|
214
|
+
it "should map specs to themselves" do
|
215
|
+
spec = 'spec/dir_monitor_spec.rb'
|
216
|
+
@dm.spec_for(spec).should == spec
|
217
|
+
end
|
107
218
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Narnach-minitest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wes Oldenbeuving
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
requirements: []
|
75
75
|
|
76
76
|
rubyforge_project:
|
77
|
-
rubygems_version: 1.0
|
77
|
+
rubygems_version: 1.2.0
|
78
78
|
signing_key:
|
79
79
|
specification_version: 2
|
80
80
|
summary: Minitest is a simple autotester tool.
|