test-loop 9.4.0 → 10.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +32 -26
  2. data/lib/test/loop.rb +21 -19
  3. data/lib/test/loop/notify.rb +3 -2
  4. metadata +1 -1
data/README.md CHANGED
@@ -134,37 +134,37 @@ the name of the test being defined.
134
134
 
135
135
  ### Test::Loop.before_each_test
136
136
 
137
- A lambda function that is executed inside the worker process before loading
138
- the test file. It is passed (1) the path to the test file, (2) the path to
137
+ Array of lambda functions that are executed inside the worker process before
138
+ loading the test file.
139
+
140
+ These functions are passed (1) the path to the test file, (2) the path to
139
141
  the log file containing the live output of running the test file, and (3) an
140
142
  array containing the names of tests (which were identified by
141
143
  `Test::Loop.test_name_parser`) inside the test file that have changed since
142
144
  the last run of the test file.
143
145
 
144
- The default implementation of this function instructs Test::Unit and RSpec to
145
- only run certain test blocks inside the test file. This accelerates your
146
- test-driven development cycle and improves productivity!
147
-
148
- If you wish to add extend the default implementation, store and recall it:
146
+ For example, to print a worker process' ID and what work it will perform:
149
147
 
150
- default_implementation = Test::Loop.before_each_test
148
+ Test::Loop.before_each_test.push lambda {
149
+ |test_file, log_file, test_names|
151
150
 
152
- Test::Loop.before_each_test = lambda do |test_file, log_file, test_names|
153
- default_implementation.call test_file, log_file, test_names
154
- # do something additional ...
155
- end
151
+ p :worker_pid => $$,
152
+ :test_file => test_file,
153
+ :log_file => log_file,
154
+ :test_names => test_names
155
+ }
156
156
 
157
- Or if you want to completely replace the default implementation:
158
-
159
- Test::Loop.before_each_test = lambda do |test_file, log_file, test_names|
160
- # your replacement here ...
161
- end
157
+ By default, the first function in this array instructs Test::Unit and RSpec to
158
+ only run certain test blocks inside the test file. This accelerates your
159
+ test-driven development cycle and improves productivity!
162
160
 
163
161
  ### Test::Loop.after_each_test
164
162
 
165
- A lambda function that is executed inside the master process after a test has
166
- finished running. It is passed (1) the path to the test file, (2) the path to
167
- the log file containing the output of running the test file, (3) a
163
+ Array of lambda functions that are executed inside the master process after a
164
+ test has finished running.
165
+
166
+ These functions are passed (1) the path to the test file, (2) the path to the
167
+ log file containing the output of running the test file, (3) a
168
168
  `Process::Status` object describing the exit status of the worker process that
169
169
  ran the test file, (4) the time when test execution began, and (5) how many
170
170
  seconds it took for the overall test execution to complete.
@@ -172,14 +172,18 @@ seconds it took for the overall test execution to complete.
172
172
  For example, to delete log files for successful tests, add the following to
173
173
  your configuration file:
174
174
 
175
- Test::Loop.after_each_test = lambda do |test_file, log_file, run_status, started_at, elapsed_time|
175
+ Test::Loop.after_each_test.push lambda {
176
+ |test_file, log_file, run_status, started_at, elapsed_time|
177
+
176
178
  File.delete(log_file) if run_status.success?
177
- end
179
+ }
178
180
 
179
181
  For example, to see on-screen-display notifications only about test failures,
180
182
  add the following to your configuration file:
181
183
 
182
- Test::Loop.after_each_test = lambda do |test_file, log_file, run_status, started_at, elapsed_time|
184
+ Test::Loop.after_each_test.push lambda {
185
+ |test_file, log_file, run_status, started_at, elapsed_time|
186
+
183
187
  unless run_status.success?
184
188
  title = 'FAIL at %s in %0.1fs' % [started_at.strftime('%r'), elapsed_time]
185
189
 
@@ -191,7 +195,7 @@ add the following to your configuration file:
191
195
  system 'xmessage', '-timeout', '5', '-title', title, message
192
196
  end
193
197
  end
194
- end
198
+ }
195
199
 
196
200
  Note that the above functionality is available as a configuration preset:
197
201
 
@@ -201,7 +205,9 @@ For example, to see on-screen-display notifications about completed test runs,
201
205
  regardless of whether they passed or failed, add the following to your
202
206
  configuration file:
203
207
 
204
- Test::Loop.after_each_test = lambda do |test_file, log_file, run_status, started_at, elapsed_time|
208
+ Test::Loop.after_each_test.push lambda {
209
+ |test_file, log_file, run_status, started_at, elapsed_time|
210
+
205
211
  success = run_status.success?
206
212
 
207
213
  title = '%s at %s in %0.1fs' %
@@ -214,7 +220,7 @@ configuration file:
214
220
  system 'growlnotify', '-a', 'Xcode', '-m', message, title or
215
221
  system 'xmessage', '-timeout', '5', '-title', title, message
216
222
  end
217
- end
223
+ }
218
224
 
219
225
  ------------------------------------------------------------------------------
220
226
  Configuration Presets
data/lib/test/loop.rb CHANGED
@@ -27,24 +27,25 @@ module Test
27
27
  end
28
28
  end
29
29
 
30
- Loop.before_each_test = lambda do |test_file, log_file, test_names|
31
- unless test_names.empty?
32
- test_name_pattern = test_names.map do |name|
33
- # sanitize string interpolations and invalid method name characters
34
- name.gsub(/\#\{.*?\}/, ' ').strip.gsub(/\W+/, '.*')
35
- end.join('|')
36
-
37
- case File.basename(test_file)
38
- when /(\b|_)test(\b|_)/ # Test::Unit
39
- ARGV.push '--name', "/#{test_name_pattern}/"
40
- when /(\b|_)spec(\b|_)/ # RSpec
41
- ARGV.push '--example', test_name_pattern
30
+ Loop.before_each_test = [
31
+ lambda {|test_file, log_file, test_names|
32
+ unless test_names.empty?
33
+ test_name_pattern = test_names.map do |name|
34
+ # sanitize string interpolations and invalid method name characters
35
+ name.gsub(/\#\{.*?\}/, ' ').strip.gsub(/\W+/, '.*')
36
+ end.join('|')
37
+
38
+ case File.basename(test_file)
39
+ when /(\b|_)test(\b|_)/ # Test::Unit
40
+ ARGV.push '--name', "/#{test_name_pattern}/"
41
+ when /(\b|_)spec(\b|_)/ # RSpec
42
+ ARGV.push '--example', test_name_pattern
43
+ end
42
44
  end
43
- end
44
- end
45
+ }
46
+ ]
45
47
 
46
- Loop.after_each_test =
47
- lambda {|test_file, log_file, run_status, started_at, elapsed_time|}
48
+ Loop.after_each_test = []
48
49
 
49
50
  class << Loop
50
51
  def run
@@ -205,7 +206,7 @@ module Test
205
206
  end.compact.uniq
206
207
 
207
208
  # tell the testing framework to run only the changed test blocks
208
- before_each_test.call test_file, log_file, test_names
209
+ before_each_test.each {|f| f.call test_file, log_file, test_names }
209
210
 
210
211
  # make the process title Test::Unit friendly and ps(1) searchable
211
212
  $0 = "test-loop #{test_file}"
@@ -233,8 +234,9 @@ module Test
233
234
  STDERR.print File.read(log_file)
234
235
  end
235
236
 
236
- after_each_test.call \
237
- test_file, log_file, run_status, @last_ran_at, elapsed_time
237
+ after_each_test.each do |f|
238
+ f.call test_file, log_file, run_status, @last_ran_at, elapsed_time
239
+ end
238
240
 
239
241
  @running_files_lock.synchronize { @running_files.delete test_file }
240
242
  end
@@ -1,6 +1,7 @@
1
1
  require 'test/loop'
2
2
 
3
- Test::Loop.after_each_test = lambda do |test_file, log_file, run_status, started_at, elapsed_time|
3
+ Test::Loop.after_each_test.push lambda {
4
+ |test_file, log_file, run_status, started_at, elapsed_time|
4
5
  unless run_status.success?
5
6
  title = 'FAIL at %s in %0.1fs' % [started_at.strftime('%r'), elapsed_time]
6
7
  message = test_file
@@ -10,4 +11,4 @@ Test::Loop.after_each_test = lambda do |test_file, log_file, run_status, started
10
11
  system 'xmessage', '-timeout', '5', '-title', title, message
11
12
  end
12
13
  end
13
- end
14
+ }
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: test-loop
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 9.4.0
5
+ version: 10.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Suraj N. Kurapati