tryouts 2.0.1.002 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/CHANGES.txt +10 -0
  2. data/README.rdoc +6 -3
  3. data/Rakefile +2 -2
  4. data/VERSION.yml +2 -2
  5. data/lib/tryouts.rb +58 -42
  6. metadata +6 -7
data/CHANGES.txt CHANGED
@@ -1,5 +1,15 @@
1
1
  TRYOUTS, CHANGES
2
2
 
3
+ #### 2.0.3 (2010-11-03) ###############################
4
+
5
+ * FIXED: Print test value not expected value twice!
6
+
7
+ #### 2.0.2 (2010-11-03) ###############################
8
+
9
+ * FIXED: Properly skip test cases with commented out expectations (i.e ##=>)
10
+ * CHANGE: Revised CLI output. Print output for each test case as it's running.
11
+
12
+
3
13
  #### 2.0.1.002 (2010-07-21) ###############################
4
14
 
5
15
  * FIXED: clean error (bad value for range). Didn't run tryouts. Bad Delano!
data/README.rdoc CHANGED
@@ -1,8 +1,10 @@
1
1
  = Tryouts v2.0 ALPHA
2
2
 
3
- <i>Put your Ruby tests in comments.</i>
3
+ <i>Don't waste your time writing tests.</i>
4
4
 
5
- <b>NOTE: Tryouts syntax changed 0.x. The old version is still available in the 0.8-FINAL branch.</b>
5
+ <b>NOTE: Tryouts syntax changed since 0.x. The old version is still available in the 0.8-FINAL branch.</b>
6
+
7
+ Check out the screencast[http://www.rubypulse.com/episode-0.46_tryouts.html] created by Alex Peuchert.
6
8
 
7
9
 
8
10
  == Basic syntax
@@ -36,7 +38,7 @@
36
38
  end
37
39
  #=> :success
38
40
 
39
- For real world examples, see the Gibbler[github.com/delano/gibbler/tree/master/try/] tryouts.
41
+ For real world examples, see the Gibbler[http://github.com/delano/gibbler/tree/master/try/] tryouts.
40
42
 
41
43
  == Setup / Cleanup
42
44
 
@@ -89,5 +91,6 @@ With help from:
89
91
  == Thanks
90
92
 
91
93
  * Syntenic[http://syntenic.com/] for the hackfest venue.
94
+ * AlexPeuchert[http://www.rubypulse.com/] for the screencast.
92
95
 
93
96
  <i>This collision was brought to you by Montreal.rb.</i>
data/Rakefile CHANGED
@@ -17,10 +17,10 @@ name = "stella"
17
17
  begin
18
18
  require "jeweler"
19
19
  Jeweler::Tasks.new do |gem|
20
- gem.version = "#{config[:MAJOR]}.#{config[:MINOR]}.#{config[:PATCH]}.#{config[:BUILD]}"
20
+ gem.version = "#{config[:MAJOR]}.#{config[:MINOR]}.#{config[:PATCH]}"
21
21
  gem.name = "tryouts"
22
22
  gem.rubyforge_project = gem.name
23
- gem.summary = "Put your Ruby tests in comments."
23
+ gem.summary = "Don't waste your time writing tests"
24
24
  gem.description = gem.summary
25
25
  gem.email = "delano@solutious.com"
26
26
  gem.homepage = "http://github.com/delano/tryouts"
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :MAJOR: 2
3
3
  :MINOR: 0
4
- :PATCH: 1
5
- :BUILD: '002'
4
+ :PATCH: 3
5
+ :BUILD: '001'
data/lib/tryouts.rb CHANGED
@@ -43,7 +43,7 @@ class Tryouts
43
43
 
44
44
  def run_all *paths
45
45
  batches = paths.collect do |path|
46
- run path
46
+ parse path
47
47
  end
48
48
 
49
49
  all, skipped_tests, failed_tests = 0, 0, 0
@@ -52,45 +52,42 @@ class Tryouts
52
52
  msg 'Ruby %s @ %-40s' % [RUBY_VERSION, Time.now], $/
53
53
 
54
54
  batches.each do |batch|
55
- if !batch.run?
56
- skipped_batches += 1
57
- status = "SKIP"
58
- elsif batch.failed?
59
- failed_batches += 1
60
- status = Console.color(:red, "FAIL").bright
61
- else
62
- status = Console.color(:green, "PASS").bright
63
- end
64
55
 
65
56
  path = batch.path.gsub(/#{Dir.pwd}\/?/, '')
66
57
 
67
- msg '%-60s %s' % [path, status]
68
- batch.each do |t|
69
- if t.failed? && failed_tests == 0
70
- #msg Console.reverse(" %-60s" % 'Errors')
58
+ msg '%-60s %s' % [path, ''] # status
59
+
60
+ before_handler = Proc.new do |t|
61
+ msg Console.reverse(' %-58s ' % [t.desc.to_s])
62
+ msg t.test.inspect, t.exps.inspect
63
+ end
64
+
65
+ batch.run(before_handler) do |t|
66
+ if t.failed?
67
+ failed_tests += 1
68
+ msg Console.color(:red, t.failed.join($/)), $/
69
+ elsif t.skipped? || !t.run?
70
+ skipped_tests += 1
71
+ msg Console.bright(t.skipped.join($/)), $/
72
+ else
73
+ msg Console.color(:green, t.passed.join($/)), $/
71
74
  end
72
75
 
73
76
  all += 1
74
- skipped_tests += 1 unless t.run?
75
-
76
- if t.failed?
77
- msg if (failed_tests += 1) == 1
78
- msg Console.reverse(' %-58s ' % [t.desc.to_s])
79
- msg t.test.inspect, t.exps.inspect
80
- msg Console.color(:red, t.failed.join($/)), $/
81
- end
77
+
82
78
  end
83
79
  end
80
+
84
81
  msg
85
82
  if all > 0
86
83
  suffix = 'tests passed'
87
- suffix << " (#{skipped_tests} skipped)" if skipped_tests > 0
84
+ suffix << " (and #{skipped_tests} skipped)" if skipped_tests > 0
88
85
  msg cformat(all-failed_tests-skipped_tests, all-skipped_tests, suffix) if all-skipped_tests > 0
89
86
  end
90
87
  if batches.size > 1
91
88
  if batches.size-skipped_batches > 0
92
89
  suffix = "batches passed"
93
- suffix << " (#{skipped_batches} skipped)" if skipped_batches > 0
90
+ suffix << " (and #{skipped_batches} skipped)" if skipped_batches > 0
94
91
  msg cformat(batches.size-skipped_batches-failed_batches, batches.size-skipped_batches, suffix)
95
92
  end
96
93
  end
@@ -172,7 +169,7 @@ class Tryouts
172
169
  batch << TestCase.new(desc, test, exps)
173
170
  end
174
171
  end
175
-
172
+
176
173
  batch
177
174
  end
178
175
 
@@ -208,7 +205,7 @@ class Tryouts
208
205
  private
209
206
 
210
207
  def expectation? str
211
- !ignore?(str) && str.strip.match(/^\#\s*=>/)
208
+ !ignore?(str) && str.strip.match(/\A\#+\s*=>/)
212
209
  end
213
210
 
214
211
  def comment? str
@@ -224,8 +221,8 @@ class Tryouts
224
221
  end
225
222
 
226
223
  def test_begin? str
227
- ret = !str.strip.match(/^\#+\s*TEST/i).nil? ||
228
- !str.strip.match(/^\#\#+[\s\w]+/i).nil?
224
+ ret = !str.strip.match(/\#+\s*TEST/i).nil? ||
225
+ !str.strip.match(/\A\#\#+[\s\w]+/i).nil?
229
226
  ret
230
227
  end
231
228
 
@@ -246,10 +243,15 @@ class Tryouts
246
243
  @container = Container.new.metaclass
247
244
  @run = false
248
245
  end
249
- def run
246
+ def run(before_test, &after_test)
250
247
  return if empty?
251
248
  setup
252
- ret = self.select { |tc| !tc.run } # select failed
249
+ ret = self.select { |tc|
250
+ before_test.call(tc) unless before_test.nil?
251
+ ret = !tc.run
252
+ after_test.call(tc)
253
+ ret # select failed tests
254
+ }
253
255
  @failed = ret.size
254
256
  @run = true
255
257
  clean
@@ -275,7 +277,7 @@ class Tryouts
275
277
  end
276
278
  end
277
279
  class TestCase
278
- attr_reader :desc, :test, :exps, :failed, :passed
280
+ attr_reader :desc, :test, :exps, :failed, :passed, :skipped
279
281
  def initialize(d,t,e)
280
282
  @desc, @test, @exps, @path = d,t,e
281
283
  end
@@ -288,24 +290,38 @@ class Tryouts
288
290
  def run
289
291
  Tryouts.debug '%s:%d' % [@test.path, @test.first]
290
292
  Tryouts.debug inspect, $/
291
- test_value = Tryouts.eval @test.to_s, @test.path, @test.first
292
- @passed, @failed = [], []
293
- exps.each_with_index { |exp,idx|
294
- exp =~ /\#+\s*=>\s*(.+)$/
295
- exp_value = Tryouts.eval($1, @exps.path, @exps.first+idx)
296
- ret = test_value == exp_value
297
- if ret
298
- @passed << ' %s == %s' % [test_value.inspect, exp_value.inspect]
293
+ expectations = exps.collect { |exp,idx|
294
+ exp =~ /\A\#?\s*=>\s*(.+)\Z/
295
+ $1 # this will be nil if the expectation is commented out
296
+ }
297
+
298
+ # Evaluate test block only if there are valid expectations
299
+ unless expectations.compact.empty?
300
+ test_value = Tryouts.eval @test.to_s, @test.path, @test.first
301
+ @has_run = true
302
+ end
303
+
304
+ @passed, @failed, @skipped = [], [], []
305
+ expectations.each_with_index { |exp,idx|
306
+ if exp.nil?
307
+ @skipped << ' [skipped]'
299
308
  else
300
- @failed << ' %s != %s' % [test_value.inspect, exp_value.inspect]
309
+ exp_value = Tryouts.eval(exp, @exps.path, @exps.first+idx)
310
+ if test_value == exp_value
311
+ @passed << ' == %s' % [test_value.inspect]
312
+ else
313
+ @failed << ' != %s' % [test_value.inspect]
314
+ end
301
315
  end
302
- ret
303
316
  }
304
317
  Tryouts.debug
305
318
  @failed.empty?
306
319
  end
320
+ def skipped?
321
+ !@skipped.nil? && !@skipped.empty?
322
+ end
307
323
  def run?
308
- !@failed.nil?
324
+ @has_run == true
309
325
  end
310
326
  def failed?
311
327
  !@failed.nil? && !@failed.empty?
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tryouts
3
3
  version: !ruby/object:Gem::Version
4
- hash: 111
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 1
10
- - 2
11
- version: 2.0.1.002
9
+ - 3
10
+ version: 2.0.3
12
11
  platform: ruby
13
12
  authors:
14
13
  - Delano Mandelbaum
@@ -16,11 +15,11 @@ autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
17
 
19
- date: 2010-07-21 00:00:00 -04:00
18
+ date: 2010-11-03 00:00:00 -04:00
20
19
  default_executable: try
21
20
  dependencies: []
22
21
 
23
- description: Put your Ruby tests in comments.
22
+ description: Don't waste your time writing tests
24
23
  email: delano@solutious.com
25
24
  executables:
26
25
  - try
@@ -76,6 +75,6 @@ rubyforge_project: tryouts
76
75
  rubygems_version: 1.3.7
77
76
  signing_key:
78
77
  specification_version: 3
79
- summary: Put your Ruby tests in comments.
78
+ summary: Don't waste your time writing tests
80
79
  test_files: []
81
80