test-loop 2.0.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +22 -11
  2. data/bin/test-loop +18 -14
  3. metadata +4 -4
data/README.md CHANGED
@@ -8,8 +8,8 @@ and tests changes in your Ruby application in an efficient manner, whereby it:
8
8
  2. Forks to evaluate your test files directly and without overhead.
9
9
 
10
10
  It relies on file modification times to determine what parts of your Ruby
11
- application have changed and then uses Rake's `String#pathmap` function to
12
- determine which test files in your test suite correspond to those changes.
11
+ application have changed and then determines which test files in your test
12
+ suite correspond to those changes using a simple lambda mapping function.
13
13
 
14
14
 
15
15
  Features
@@ -24,7 +24,7 @@ Features
24
24
  * Supports Test::Unit, RSpec, or any other testing framework that is utilized
25
25
  by your application's `test/test_helper.rb` and `spec/spec_helper.rb` files.
26
26
 
27
- * Implemented in less than 55 (SLOC) lines of code! :-)
27
+ * Implemented in less than 60 (SLOC) lines of code! :-)
28
28
 
29
29
 
30
30
  Installation
@@ -54,13 +54,13 @@ If installed as a Git clone:
54
54
  Operation
55
55
  ---------
56
56
 
57
- * Press Control-Z (or send the SIGTSTP signal) to forcibly run all
57
+ * Press Control-Z or send the SIGTSTP signal to forcibly run all
58
58
  tests, even if there are no changes in your Ruby application.
59
59
 
60
- * Press Control-\ (or send the SIGQUIT signal) to forcibly reabsorb
60
+ * Press Control-\ or send the SIGQUIT signal to forcibly reabsorb
61
61
  the test execution overhead, even if its sources have not changed.
62
62
 
63
- * Press Control-C (or send the SIGINT signal) to quit the test loop.
63
+ * Press Control-C or send the SIGINT signal to quit the test loop.
64
64
 
65
65
 
66
66
  Configuration
@@ -77,13 +77,24 @@ define the following instance variables:
77
77
  set of files which cause the overhead to be reabsorbed whenever they change.
78
78
 
79
79
  * `@source_file_to_test_file_mapping` is a hash that maps a file globbing
80
- pattern describing a set of source files to a [Rake pathmap expression](
81
- http://rake.rubyforge.org/classes/String.html#M000017 ) yielding a file
82
- globbing pattern describing a set of test files that need to be run. In
83
- other words, whenever the source files (the hash key; left-hand side of the
84
- mapping) change, their associated test files (the hash value; right-hand
80
+ pattern describing a set of source files to a lambda function yielding a
81
+ file globbing pattern describing a set of test files that need to be run.
82
+ In other words, whenever the source files (the hash key; left-hand side of
83
+ the mapping) change, their associated test files (the hash value; right-hand
85
84
  side of the mapping) are run.
86
85
 
86
+ For example, if test files had the same names as their source files but the
87
+ letters were in reverse order, then you would add the following to your
88
+ `.test-loop` file:
89
+
90
+ @source_file_to_test_file_mapping = {
91
+ '{lib,app}/**/*.rb' => lambda do |path|
92
+ extn = File.extname(path)
93
+ name = File.basename(path, extn)
94
+ "{test,spec}/**/#{name.reverse}#{extn}" # <== notice the reverse()
95
+ end
96
+ }
97
+
87
98
  * `@after_test_execution` is a proc/lambda object that is executed after tests
88
99
  are run. It is passed three things: the status of the test execution
89
100
  subprocess, the time when the tests were run, and the list of test files
data/bin/test-loop CHANGED
@@ -21,14 +21,11 @@
21
21
  # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
22
22
  # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
23
  #
24
-
25
- require 'rake' # for String#pathmap
26
-
27
- def notify message
28
- puts "test-loop: #{message}"
29
- end
30
-
31
24
  begin
25
+ def notify message
26
+ puts "test-loop: #{message}"
27
+ end
28
+
32
29
  notify 'Loading configuration...'
33
30
  config_file = File.join(Dir.pwd, '.test-loop')
34
31
  load config_file if File.exist? config_file
@@ -41,8 +38,15 @@ begin
41
38
  push(config_file, 'config/*.{rb,yml}').uniq!
42
39
 
43
40
  (@source_file_to_test_file_mapping ||= {}).merge!(
44
- '{test,spec}/**/*_{test,spec}.rb' => '%p',
45
- '{lib,app}/**/*.rb' => '{test,spec}/**/%n_{test,spec}%x'
41
+ # source files that correspond to test files
42
+ '{lib,app}/**/*.rb' => lambda do |path|
43
+ extn = File.extname(path)
44
+ name = File.basename(path, extn)
45
+ "{test,spec}/**/#{name}_{test,spec}#{extn}"
46
+ end,
47
+
48
+ # the actual test files themselves
49
+ '{test,spec}/**/*_{test,spec}.rb' => lambda {|path| path }
46
50
  )
47
51
 
48
52
  @after_test_execution ||= lambda {|status, ran_at, files|}
@@ -52,8 +56,8 @@ begin
52
56
 
53
57
  notify 'Absorbing overhead...'
54
58
  Dir[*@overhead_file_globs].each do |file|
55
- $LOAD_PATH.insert 1, file.pathmap('%d')
56
- require file.pathmap('%n')
59
+ $LOAD_PATH.insert 1, File.dirname(file)
60
+ require File.basename(file, File.extname(file))
57
61
  end
58
62
 
59
63
  # continuously watch for and test changed code
@@ -66,10 +70,10 @@ begin
66
70
  loop do
67
71
  # figure out what test files need to be run
68
72
  test_files = @source_file_to_test_file_mapping.
69
- map do |source_file_glob, test_file_pathmap|
73
+ map do |source_file_glob, test_file_glob_mapper|
70
74
  Dir[source_file_glob].
71
75
  select {|file| File.mtime(file) > last_ran_at }.
72
- map {|path| Dir[path.pathmap(test_file_pathmap)] }
76
+ map {|path| Dir[test_file_glob_mapper.call(path)] }
73
77
  end.flatten.uniq
74
78
 
75
79
  # fork worker process to run the test files
@@ -91,7 +95,7 @@ begin
91
95
  end
92
96
  rescue Interrupt
93
97
  # user wants to quit the loop
94
- rescue StandardError, LoadError => error
98
+ rescue StandardError, LoadError, SyntaxError => error
95
99
  puts error.inspect, error.backtrace
96
100
  sleep 1 and exec $0, *ARGV
97
101
  end
metadata CHANGED
@@ -3,10 +3,10 @@ name: test-loop
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 2
6
+ - 3
7
7
  - 0
8
- - 2
9
- version: 2.0.2
8
+ - 0
9
+ version: 3.0.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Suraj N. Kurapati
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-02 00:00:00 -08:00
17
+ date: 2011-01-04 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies: []
20
20