Narnach-minitest 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +17 -5
- data/Rakefile +4 -4
- data/bin/minitest +0 -1
- data/lib/dir_monitor.rb +64 -27
- data/lib/minitest.rb +41 -39
- data/lib/set_ext.rb +12 -0
- data/minitest.gemspec +37 -0
- data/spec/dir_monitor_spec.rb +98 -61
- data/spec/minitest_spec.rb +1 -1
- data/spec/set_ext_spec.rb +11 -0
- data/spec/spec_helper.rb +1 -0
- metadata +11 -7
data/README.rdoc
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
== Minitest
|
2
|
-
Minitest is a simple autotester intended to be used with rSpec and rCov.
|
3
|
-
It can be used with 'plain'
|
2
|
+
Minitest is a simple autotester intended to be used with rSpec, Test::Unit and rCov.
|
3
|
+
It can be used with 'plain' Ruby projects and Ruby on Rails.
|
4
4
|
|
5
5
|
== Recent changes
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
=== Version 0.3.1
|
8
|
+
Minitest gained support to test Test::Unit tests and RSpec specs at the same time.
|
9
|
+
|
10
|
+
=== Version 0.3.0
|
11
|
+
Minitest switched to a new file monitoring backend: DirMonitor.
|
12
|
+
This makes it possible to track new files as they are created, without needing to restart minitest.
|
13
|
+
The 'recent' feature was removed because DirMonitor does not (yet?) have a way to only yield files
|
14
|
+
newer than some timestamp. This feature is likely to re-appear in a nearby future.
|
8
15
|
|
9
16
|
== Installation
|
10
17
|
=== From gem
|
@@ -28,7 +35,12 @@ When you start working on a codebase, it makes sense to run all specs:
|
|
28
35
|
When you want to see which specs are slow and could use optimizing:
|
29
36
|
minitest profile
|
30
37
|
You can also combine options:
|
31
|
-
minitest
|
38
|
+
minitest drb profile
|
39
|
+
|
40
|
+
== Todo / ideas / plans
|
41
|
+
* Figure out how to get RCov to run specs and tests at the same time and implement it.
|
42
|
+
* Add 'recent' option (was removed in 0.3.0).
|
43
|
+
* Write tests for Minitest class.
|
32
44
|
|
33
45
|
== About
|
34
46
|
Author:: Wes 'Narnach' Oldenbeuving (narnach@gmail.com)
|
data/Rakefile
CHANGED
@@ -2,7 +2,6 @@ require "rake"
|
|
2
2
|
require "rake/clean"
|
3
3
|
require "rake/gempackagetask"
|
4
4
|
require 'rubygems'
|
5
|
-
require 'lib/minitest'
|
6
5
|
|
7
6
|
################################################################################
|
8
7
|
### Gem
|
@@ -10,7 +9,8 @@ require 'lib/minitest'
|
|
10
9
|
|
11
10
|
begin
|
12
11
|
# Parse gemspec using the github safety level.
|
13
|
-
|
12
|
+
file = Dir['*.gemspec'].first
|
13
|
+
data = File.read(file)
|
14
14
|
spec = nil
|
15
15
|
Thread.new { spec = eval("$SAFE = 3\n%s" % data)}.join
|
16
16
|
|
@@ -19,10 +19,10 @@ begin
|
|
19
19
|
package.gem_spec = spec
|
20
20
|
end
|
21
21
|
rescue Exception => e
|
22
|
-
printf "WARNING: Error caught (%s): %s\n", e.class.name, e.message
|
22
|
+
printf "WARNING: Error caught (%s): %s\n%s", e.class.name, e.message, e.backtrace[0...5].map {|l| ' %s' % l}.join("\n")
|
23
23
|
end
|
24
24
|
|
25
25
|
desc 'Package and install the gem for the current version'
|
26
26
|
task :install => :gem do
|
27
|
-
system "sudo gem install -l pkg
|
27
|
+
system "sudo gem install -l pkg/%s-%s.gem" % [spec.name, spec.version]
|
28
28
|
end
|
data/bin/minitest
CHANGED
data/lib/dir_monitor.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
# Dirmonitor's purpose is to serve as a file monitoring helper for Minitest.
|
2
|
+
#
|
2
3
|
# Its intended functionality is:
|
3
4
|
# - Keep track of new files in monitored directories.
|
4
5
|
# - Keep track of changed files in monitored directories.
|
5
|
-
# - Link these files to their specs, so Minitest can run
|
6
|
+
# - Link these files to their specs or tests, so Minitest can run them.
|
6
7
|
class DirMonitor
|
7
8
|
attr_reader :known_files, :dirs, :last_mtime
|
8
9
|
|
9
10
|
# Setup a new DirMonitor.
|
10
|
-
#
|
11
|
+
#
|
12
|
+
# The input parameter(s) are flattened and forced to a string.
|
13
|
+
#
|
14
|
+
# This means that directories can be provided in a number of ways:
|
11
15
|
# DirMonitor.new 'lib', 'app'
|
12
16
|
# DirMonitor.new :lib, :app
|
13
17
|
# DirMonitor.new %w[lib app]
|
@@ -42,16 +46,6 @@ class DirMonitor
|
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
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
|
-
|
55
49
|
# Scan for new files.
|
56
50
|
# All new file names are yielded.
|
57
51
|
def scan_new(&block) # :yields: file
|
@@ -64,32 +58,40 @@ class DirMonitor
|
|
64
58
|
end
|
65
59
|
|
66
60
|
# Scan for new files and check for changed known files.
|
67
|
-
#
|
61
|
+
# The same file is not yielded twice.
|
68
62
|
def scan_new_or_changed_with_spec(&block) # :yields: file, spec
|
69
63
|
yielded_files = {}
|
70
|
-
yield_once_block = Proc.new do |file
|
71
|
-
|
72
|
-
|
73
|
-
|
64
|
+
yield_once_block = Proc.new do |file|
|
65
|
+
spec_file = spec_for(file)
|
66
|
+
next if yielded_files.has_key? spec_file
|
67
|
+
next unless File.exist?(spec_file)
|
68
|
+
block.call(file, spec_file)
|
69
|
+
yielded_files[spec_file]=file
|
74
70
|
end
|
75
|
-
|
76
|
-
|
71
|
+
scan_new(&yield_once_block)
|
72
|
+
scan_changed(&yield_once_block)
|
77
73
|
end
|
78
74
|
|
79
|
-
#
|
80
|
-
#
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
75
|
+
# Scan for new files and check for changed known files.
|
76
|
+
# The same file is not yielded twice.
|
77
|
+
def scan_new_or_changed_with_test(&block) # :yields: file, test
|
78
|
+
yielded_files = {}
|
79
|
+
yield_once_block = Proc.new do |file|
|
80
|
+
test_file = test_for(file)
|
81
|
+
next if yielded_files.has_key? test_file
|
82
|
+
next unless File.exist?(test_file)
|
83
|
+
block.call(file, test_file)
|
84
|
+
yielded_files[test_file]=file
|
86
85
|
end
|
86
|
+
scan_new(&yield_once_block)
|
87
|
+
scan_changed(&yield_once_block)
|
87
88
|
end
|
88
89
|
|
89
90
|
# Find the (theoretical) spec file name for a given file.
|
90
91
|
# The assumptions are:
|
91
92
|
# - All specs reside in the 'spec' directory.
|
92
|
-
# -
|
93
|
+
# - The directory structure is the same; lib/a/b/c maps to spec/a/b/c.
|
94
|
+
# - All specs file names have the suffix '_spec.rb'; Ruby code has the '.rb' extension.
|
93
95
|
# - The file name for a non-ruby file spec simply has '_spec.rb' suffixed to the entire file name.
|
94
96
|
# The returned file name does not necessarily have to exist.
|
95
97
|
def spec_for(file)
|
@@ -111,6 +113,41 @@ class DirMonitor
|
|
111
113
|
return File.join(spec_dir, spec_file)
|
112
114
|
end
|
113
115
|
|
116
|
+
# Find the (theoretical) test file name for a given file.
|
117
|
+
# The assumptions are:
|
118
|
+
# - All tests reside in the 'test' directory.
|
119
|
+
# - The directory structure is the same; lib/a/b/c maps to test/a/b/c.
|
120
|
+
# - Rails is the exception to this rule:
|
121
|
+
# - Controllers are tested in test/functional
|
122
|
+
# - Models are tested in test/unit
|
123
|
+
# - All test file names have the suffix '_test.rb'. Ruby code has the '.rb' extension.
|
124
|
+
# - The file name for a non-ruby file test simply has '_test.rb' suffixed to the entire file name.
|
125
|
+
# The returned file name does not necessarily have to exist.
|
126
|
+
def test_for(file)
|
127
|
+
base = File.basename(file)
|
128
|
+
extension = File.extname(base)
|
129
|
+
dir = File.dirname(file)
|
130
|
+
dir_array = dir.split('/')
|
131
|
+
if extension == '.rb' and dir_array.first=='test'
|
132
|
+
return file
|
133
|
+
end
|
134
|
+
if extension == '.rb'
|
135
|
+
base_without_extension = base[0, base.size - extension.size]
|
136
|
+
test_file = base_without_extension + '_test' + extension
|
137
|
+
else
|
138
|
+
test_file = base + '_test.rb'
|
139
|
+
end
|
140
|
+
dir_array[0]='test'
|
141
|
+
case dir_array[1]
|
142
|
+
when 'controllers'
|
143
|
+
dir_array[1] = 'functional'
|
144
|
+
when 'models'
|
145
|
+
dir_array[1] = 'unit'
|
146
|
+
end
|
147
|
+
test_dir = dir_array.join('/')
|
148
|
+
return File.join(test_dir, test_file)
|
149
|
+
end
|
150
|
+
|
114
151
|
private
|
115
152
|
|
116
153
|
# Get the modification time for a file.
|
data/lib/minitest.rb
CHANGED
@@ -1,20 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'set_ext'
|
2
2
|
require 'dir_monitor'
|
3
3
|
|
4
|
-
class Set
|
5
|
-
def join(*args,&block)
|
6
|
-
map.join(*args,&block)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
4
|
# = Minitest
|
11
5
|
# The default usage of Minitest is this:
|
12
6
|
# minitest = Minitest.new
|
13
7
|
# minitest.start
|
14
8
|
# This will do the following:
|
15
9
|
# - Initialize a DirMonitor
|
16
|
-
# -
|
17
|
-
# - Frequently check for new or changed files; run rspec on their associated specs
|
10
|
+
# - Frequently check for new or changed files; run rspec or test/unit on their associated specs or tests
|
18
11
|
# - Run rcov (code coverage tester) on all specs when exiting (Press ctrl-C on send SIGINT to the process)
|
19
12
|
class Minitest
|
20
13
|
attr_accessor :source_dirs
|
@@ -42,40 +35,22 @@ class Minitest
|
|
42
35
|
ignores.join(",")
|
43
36
|
end
|
44
37
|
|
45
|
-
# Command line string to run rcov for all monitored specs.
|
46
|
-
def rcov
|
47
|
-
"#{rcov_cmd} -T --exclude \"#{rcov_ignores}\" -Ilib #{spec_cmd} -- " + known_specs.join(" ")
|
48
|
-
end
|
49
|
-
|
50
|
-
# Command line string to run rspec for an array of specs. Defaults to all specs.
|
51
|
-
def rspec(specs=known_specs)
|
52
|
-
"#{spec_cmd} #{specs.join(" ")} #{spec_opts}"
|
53
|
-
end
|
54
|
-
|
55
38
|
def source_dirs
|
56
39
|
@source_dirs || DEFAULT_SOURCE_DIRS
|
57
40
|
end
|
58
41
|
|
59
|
-
def rcov_cmd
|
60
|
-
@rcov_cmd ||= find_rcov_cmd
|
61
|
-
end
|
62
|
-
|
63
|
-
# The command to use to run specs.
|
64
|
-
def spec_cmd
|
65
|
-
@spec_cmd ||= ( File.exist?('script/spec') ? 'script/spec' : find_spec_cmd )
|
66
|
-
end
|
67
|
-
|
68
42
|
def spec_opts
|
69
43
|
@spec_opts ||= ( File.exist?('spec/spec.opts') ? '-O spec/spec.opts' : '' )
|
70
44
|
end
|
71
45
|
|
72
46
|
def start
|
73
47
|
@active = true
|
74
|
-
@
|
48
|
+
@spec_monitor = DirMonitor.new(source_dirs)
|
49
|
+
@test_monitor = DirMonitor.new(source_dirs)
|
75
50
|
trap_int_for_rcov
|
76
51
|
while active? do
|
77
52
|
reset_need_testing
|
78
|
-
@
|
53
|
+
@spec_monitor.scan_new_or_changed_with_spec do |file, spec|
|
79
54
|
known_specs << spec
|
80
55
|
need_testing << spec
|
81
56
|
end
|
@@ -83,19 +58,18 @@ class Minitest
|
|
83
58
|
print "\nTesting files: #{need_testing.join(" ")}\n"
|
84
59
|
system rspec(need_testing)
|
85
60
|
end
|
61
|
+
tests_to_run = Set.new
|
62
|
+
@test_monitor.scan_new_or_changed_with_test do |file, test|
|
63
|
+
tests_to_run << test
|
64
|
+
end
|
65
|
+
if tests_to_run.size > 0
|
66
|
+
print "\nTesting files: #{tests_to_run.join(" ")}\n"
|
67
|
+
system 'ruby -e "" -rtest/unit %s' % tests_to_run.map{|test| '-r%s' % test}.join(" ")
|
68
|
+
end
|
86
69
|
sleep 1
|
87
70
|
end
|
88
71
|
end
|
89
72
|
|
90
|
-
def trap_int_for_rcov
|
91
|
-
Signal.trap("INT") do
|
92
|
-
print "\nNow we run rcov and we're done.\n\n"
|
93
|
-
puts rcov
|
94
|
-
system rcov
|
95
|
-
@active = false
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
73
|
private
|
100
74
|
|
101
75
|
def find_rcov_cmd
|
@@ -106,7 +80,35 @@ class Minitest
|
|
106
80
|
`which spec`.strip
|
107
81
|
end
|
108
82
|
|
83
|
+
# Command line string to run rcov for all monitored specs.
|
84
|
+
def rcov
|
85
|
+
"#{rcov_cmd} -T --exclude \"#{rcov_ignores}\" -Ilib #{spec_cmd} -- " + known_specs.join(" ")
|
86
|
+
end
|
87
|
+
|
88
|
+
def rcov_cmd
|
89
|
+
@rcov_cmd ||= find_rcov_cmd
|
90
|
+
end
|
91
|
+
|
109
92
|
def reset_need_testing
|
110
93
|
@need_testing = Set.new
|
111
94
|
end
|
95
|
+
|
96
|
+
# Command line string to run rspec for an array of specs. Defaults to all specs.
|
97
|
+
def rspec(specs=known_specs)
|
98
|
+
"#{spec_cmd} #{specs.join(" ")} #{spec_opts}"
|
99
|
+
end
|
100
|
+
|
101
|
+
# The command to use to run specs.
|
102
|
+
def spec_cmd
|
103
|
+
@spec_cmd ||= ( File.exist?('script/spec') ? 'script/spec' : find_spec_cmd )
|
104
|
+
end
|
105
|
+
|
106
|
+
def trap_int_for_rcov
|
107
|
+
Signal.trap("INT") do
|
108
|
+
print "\nNow we run rcov and we're done.\n\n"
|
109
|
+
puts rcov
|
110
|
+
system rcov
|
111
|
+
@active = false
|
112
|
+
end
|
113
|
+
end
|
112
114
|
end
|
data/lib/set_ext.rb
ADDED
data/minitest.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
# Project
|
3
|
+
s.name = 'minitest'
|
4
|
+
s.summary = "Minitest is a simple autotester tool."
|
5
|
+
s.description = "Minitest is a simple autotester tool, which uses rSpec and rCov to test ruby and rails projects."
|
6
|
+
s.version = '0.3.1'
|
7
|
+
s.date = '2008-08-14'
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Wes Oldenbeuving"]
|
10
|
+
s.email = "narnach@gmail.com"
|
11
|
+
s.homepage = "http://www.github.com/Narnach/minitest"
|
12
|
+
|
13
|
+
# Files
|
14
|
+
root_files = %w[MIT-LICENSE README.rdoc Rakefile minitest.gemspec]
|
15
|
+
bin_files = %w[minitest]
|
16
|
+
lib_files = %w[minitest dir_monitor set_ext]
|
17
|
+
test_files = %w[]
|
18
|
+
spec_files = %w[minitest dir_monitor set_ext]
|
19
|
+
other_files = %w[spec/spec.opts spec/spec_helper.rb]
|
20
|
+
s.bindir = "bin"
|
21
|
+
s.require_path = "lib"
|
22
|
+
s.executables = bin_files
|
23
|
+
s.test_files = test_files.map {|f| 'test/%s_test.rb' % f} + spec_files.map {|f| 'spec/%s_spec.rb' % f}
|
24
|
+
s.files = root_files + s.test_files + other_files + bin_files.map {|f| 'bin/%s' % f} + lib_files.map {|f| 'lib/%s.rb' % f}
|
25
|
+
|
26
|
+
# rdoc
|
27
|
+
s.has_rdoc = true
|
28
|
+
s.extra_rdoc_files = %w[ README.rdoc MIT-LICENSE]
|
29
|
+
s.rdoc_options << '--inline-source' << '--line-numbers' << '--main' << 'README.rdoc'
|
30
|
+
|
31
|
+
# Dependencies
|
32
|
+
s.add_dependency 'rspec', "> 0.0.0"
|
33
|
+
s.add_dependency 'rcov', "> 0.0.0"
|
34
|
+
|
35
|
+
# Requirements
|
36
|
+
s.required_ruby_version = ">= 1.8.0"
|
37
|
+
end
|
data/spec/dir_monitor_spec.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
|
1
|
+
require File.join(File.dirname(__FILE__),'spec_helper')
|
2
2
|
require 'dir_monitor'
|
3
3
|
|
4
|
-
describe DirMonitor
|
4
|
+
describe DirMonitor do
|
5
|
+
|
6
|
+
describe ".new" do
|
5
7
|
it "should accept multiple directories" do
|
6
8
|
dm = DirMonitor.new('lib','app')
|
7
9
|
dm.dirs.should == ['lib','app']
|
@@ -18,7 +20,7 @@ describe DirMonitor, ".new" do
|
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
describe
|
23
|
+
describe "#scan" do
|
22
24
|
it "should find all files in the directories" do
|
23
25
|
known_files1 = %w[lib/minitest.rb lib/dir_monitor.rb]
|
24
26
|
known_files2 = %w[app/another.rb app/files.rb app/more/things.txt]
|
@@ -30,7 +32,7 @@ describe DirMonitor, "#scan" do
|
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
|
-
describe
|
35
|
+
describe "#scan_new" do
|
34
36
|
before(:each) do
|
35
37
|
@known_files = %w[lib/minitest.rb lib/dir_monitor.rb]
|
36
38
|
Dir.stub!(:glob).with('lib/**/*').and_return(@known_files)
|
@@ -57,34 +59,7 @@ describe DirMonitor, "#scan_new" do
|
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
60
|
-
describe
|
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'
|
66
|
-
end
|
67
|
-
|
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}]
|
75
|
-
end
|
76
|
-
|
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 == []
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe DirMonitor, "#scan_changed" do
|
62
|
+
describe "#scan_changed" do
|
88
63
|
before(:each) do
|
89
64
|
@file = 'lib/dir_monitor.rb'
|
90
65
|
@time = Time.now
|
@@ -124,7 +99,7 @@ describe DirMonitor, "#scan_changed" do
|
|
124
99
|
end
|
125
100
|
end
|
126
101
|
|
127
|
-
describe
|
102
|
+
describe "#scan_new_or_changed_with_spec" do
|
128
103
|
before(:each) do
|
129
104
|
@file = 'lib/dir_monitor.rb'
|
130
105
|
@spec = 'spec/dir_monitor_spec.rb'
|
@@ -132,69 +107,94 @@ describe DirMonitor, "scan_changed_with_spec" do
|
|
132
107
|
Dir.stub!(:glob).with('lib/**/*').and_return([@file])
|
133
108
|
File.stub!(:mtime).with(@file).and_return(@time)
|
134
109
|
@dm = DirMonitor.new 'lib'
|
135
|
-
@dm.scan
|
136
110
|
end
|
137
111
|
|
138
|
-
it "should yield
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
changes << { changed_file => spec_file }
|
112
|
+
it "should yield a file and spec when a file is new" do
|
113
|
+
results = []
|
114
|
+
@dm.scan_new_or_changed_with_spec do |file, spec|
|
115
|
+
results << {file => spec}
|
143
116
|
end
|
144
|
-
|
117
|
+
results.should == [{@file=>@spec}]
|
145
118
|
end
|
146
119
|
|
147
|
-
it "should
|
148
|
-
|
149
|
-
|
150
|
-
@
|
151
|
-
|
120
|
+
it "should yield a file and spec when a file is not new but has changed" do
|
121
|
+
@dm.scan
|
122
|
+
@dm.scan_changed {|f|}
|
123
|
+
File.should_receive(:mtime).with(@file).and_return(@time+1)
|
124
|
+
results = []
|
125
|
+
@dm.scan_new_or_changed_with_spec do |file, spec|
|
126
|
+
results << {file => spec}
|
152
127
|
end
|
153
|
-
|
128
|
+
results.should == [{@file=>@spec}]
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should not yield a file and spec when a file is not new and has not changed" do
|
132
|
+
@dm.scan
|
133
|
+
@dm.scan_changed {|f|}
|
134
|
+
results = []
|
135
|
+
@dm.scan_new_or_changed_with_spec do |file, spec|
|
136
|
+
results << {file => spec}
|
137
|
+
end
|
138
|
+
results.should == []
|
154
139
|
end
|
155
140
|
end
|
156
141
|
|
157
|
-
describe
|
142
|
+
describe "#scan_new_or_changed_with_test" do
|
158
143
|
before(:each) do
|
159
144
|
@file = 'lib/dir_monitor.rb'
|
160
|
-
@
|
145
|
+
@test = 'test/dir_monitor_test.rb'
|
161
146
|
@time = Time.now
|
162
147
|
Dir.stub!(:glob).with('lib/**/*').and_return([@file])
|
163
148
|
File.stub!(:mtime).with(@file).and_return(@time)
|
149
|
+
File.stub!(:exist?).with(@test).and_return(true)
|
164
150
|
@dm = DirMonitor.new 'lib'
|
165
151
|
end
|
166
152
|
|
167
|
-
it "should yield a file and
|
153
|
+
it "should yield a file and test when a file is new" do
|
168
154
|
results = []
|
169
|
-
@dm.
|
170
|
-
results << {file =>
|
155
|
+
@dm.scan_new_or_changed_with_test do |file, test|
|
156
|
+
results << {file => test}
|
171
157
|
end
|
172
|
-
results.should == [{@file=>@
|
158
|
+
results.should == [{@file=>@test}]
|
173
159
|
end
|
174
160
|
|
175
|
-
it "should yield a file and
|
161
|
+
it "should yield a file and test when a file is not new but has changed" do
|
176
162
|
@dm.scan
|
177
163
|
@dm.scan_changed {|f|}
|
178
164
|
File.should_receive(:mtime).with(@file).and_return(@time+1)
|
179
165
|
results = []
|
180
|
-
@dm.
|
181
|
-
results << {file =>
|
166
|
+
@dm.scan_new_or_changed_with_test do |file, test|
|
167
|
+
results << {file => test}
|
182
168
|
end
|
183
|
-
results.should == [{@file=>@
|
169
|
+
results.should == [{@file=>@test}]
|
184
170
|
end
|
185
171
|
|
186
|
-
it "should not yield a file and
|
172
|
+
it "should not yield a file and test when a file is not new and has not changed" do
|
187
173
|
@dm.scan
|
188
174
|
@dm.scan_changed {|f|}
|
189
175
|
results = []
|
190
|
-
@dm.
|
191
|
-
results << {file =>
|
176
|
+
@dm.scan_new_or_changed_with_test do |file, test|
|
177
|
+
results << {file => test}
|
178
|
+
end
|
179
|
+
results.should == []
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should skip files with non-existent tests" do
|
183
|
+
@dm.scan
|
184
|
+
@dm.scan_changed {|f|}
|
185
|
+
|
186
|
+
@test = @dm.test_for(@file)
|
187
|
+
File.should_receive(:mtime).with(@file).and_return(@time+1)
|
188
|
+
File.should_receive(:exist?).with(@test).and_return(false)
|
189
|
+
results = []
|
190
|
+
@dm.scan_new_or_changed_with_test do |file, test|
|
191
|
+
results << {file => test}
|
192
192
|
end
|
193
193
|
results.should == []
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
197
|
-
describe
|
197
|
+
describe "#spec_for" do
|
198
198
|
before(:each) do
|
199
199
|
@dm = DirMonitor.new
|
200
200
|
end
|
@@ -215,4 +215,41 @@ describe DirMonitor, "#spec_for" do
|
|
215
215
|
spec = 'spec/dir_monitor_spec.rb'
|
216
216
|
@dm.spec_for(spec).should == spec
|
217
217
|
end
|
218
|
-
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "#test_for" do
|
221
|
+
before(:each) do
|
222
|
+
@dm = DirMonitor.new
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should find the test for a given file" do
|
226
|
+
file = 'lib/dir_monitor.rb'
|
227
|
+
test = 'test/dir_monitor_test.rb'
|
228
|
+
@dm.test_for(file).should == test
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should find the test for non-ruby files" do
|
232
|
+
file = 'app/views/posts/post.html.haml'
|
233
|
+
test = 'test/views/posts/post.html.haml_test.rb'
|
234
|
+
@dm.test_for(file).should == test
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should map tests to themselves" do
|
238
|
+
test = 'test/dir_monitor_test.rb'
|
239
|
+
@dm.test_for(test).should == test
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should recognize Rails controllers" do
|
243
|
+
file = 'app/controllers/posts_controller.rb'
|
244
|
+
test = 'test/functional/posts_controller_test.rb'
|
245
|
+
@dm.test_for(file).should == test
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should recognize Rails models" do
|
249
|
+
file = 'app/models/post.rb'
|
250
|
+
test = 'test/unit/post_test.rb'
|
251
|
+
@dm.test_for(file).should == test
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
end # describe DirMonitor
|
data/spec/minitest_spec.rb
CHANGED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
|
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wes Oldenbeuving
|
@@ -43,12 +43,16 @@ files:
|
|
43
43
|
- MIT-LICENSE
|
44
44
|
- README.rdoc
|
45
45
|
- Rakefile
|
46
|
-
-
|
47
|
-
- lib/dir_monitor.rb
|
48
|
-
- lib/minitest.rb
|
49
|
-
- spec/dir_monitor_spec.rb
|
46
|
+
- minitest.gemspec
|
50
47
|
- spec/minitest_spec.rb
|
48
|
+
- spec/dir_monitor_spec.rb
|
49
|
+
- spec/set_ext_spec.rb
|
51
50
|
- spec/spec.opts
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
- bin/minitest
|
53
|
+
- lib/minitest.rb
|
54
|
+
- lib/dir_monitor.rb
|
55
|
+
- lib/set_ext.rb
|
52
56
|
has_rdoc: true
|
53
57
|
homepage: http://www.github.com/Narnach/minitest
|
54
58
|
post_install_message:
|
@@ -79,6 +83,6 @@ signing_key:
|
|
79
83
|
specification_version: 2
|
80
84
|
summary: Minitest is a simple autotester tool.
|
81
85
|
test_files:
|
82
|
-
- spec/dir_monitor_spec.rb
|
83
86
|
- spec/minitest_spec.rb
|
84
|
-
- spec/
|
87
|
+
- spec/dir_monitor_spec.rb
|
88
|
+
- spec/set_ext_spec.rb
|