minitest 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,3 +1,16 @@
1
+ === 2.5.0 / 2011-08-18
2
+
3
+ * 4 minor enhancements:
4
+
5
+ * Added 2 more arguments against rspec: let & subject in 9 loc! (emmanuel/luis)
6
+ * Added TestCase.i_suck_and_my_tests_are_order_dependent!
7
+ * Extended describe to take an optional method name (2 line change!). (emmanuel)
8
+ * Refactored and extended minitest/pride to do full 256 color support. (lolcat)
9
+
10
+ * 1 bug fix:
11
+
12
+ * Doc fixes. (chastell)
13
+
1
14
  === 2.4.0 / 2011-08-09
2
15
 
3
16
  * 4 minor enhancements:
@@ -4,31 +4,90 @@ require "minitest/unit"
4
4
  # Show your testing pride!
5
5
 
6
6
  class PrideIO
7
+ ESC = "\e["
8
+ NND = "#{ESC}0m"
9
+
7
10
  attr_reader :io
8
11
 
9
12
  def initialize io
10
13
  @io = io
11
14
  # stolen from /System/Library/Perl/5.10.0/Term/ANSIColor.pm
12
- @colors = (31..36).to_a
15
+ # also reference http://en.wikipedia.org/wiki/ANSI_escape_code
16
+ @colors ||= (31..36).to_a
13
17
  @size = @colors.size
14
18
  @index = 0
19
+ # io.sync = true
15
20
  end
16
21
 
17
22
  def print o
18
23
  case o
19
24
  when "." then
20
- io.print "\e[#{@colors[@index % @size]}m*\e[0m"
21
- @index += 1
25
+ io.print pride o
22
26
  when "E", "F" then
23
- io.print "\e[41m\e[37m#{o}\e[0m"
27
+ io.print "#{ESC}41m#{ESC}37m#{o}#{NND}"
24
28
  else
25
29
  io.print o
26
30
  end
27
31
  end
28
32
 
33
+ def puts(*o)
34
+ o.map! { |s|
35
+ s.sub(/Finished tests/) {
36
+ @index = 0
37
+ 'Fabulous tests'.split(//).map { |c|
38
+ pride(c)
39
+ }.join
40
+ }
41
+ }
42
+
43
+ super
44
+ end
45
+
46
+ def pride string
47
+ string = "*" if string == "."
48
+ c = @colors[@index % @size]
49
+ @index += 1
50
+ "#{ESC}#{c}m#{string}#{NND}"
51
+ end
52
+
29
53
  def method_missing msg, *args
30
54
  io.send(msg, *args)
31
55
  end
32
56
  end
33
57
 
34
- MiniTest::Unit.output = PrideIO.new(MiniTest::Unit.output)
58
+ class PrideLOL < PrideIO # inspired by lolcat, but massively cleaned up
59
+ PI_3 = Math::PI / 3
60
+
61
+ def initialize io
62
+ # walk red, green, and blue around a circle separated by equal thirds.
63
+ #
64
+ # To visualize, type this into wolfram-alpha:
65
+ #
66
+ # plot (3*sin(x)+3), (3*sin(x+2*pi/3)+3), (3*sin(x+4*pi/3)+3)
67
+
68
+ # 6 has wide pretty gradients. 3 == lolcat, about half the width
69
+ @colors = (0...(6 * 7)).map { |n|
70
+ n *= 1.0 / 6
71
+ r = (3 * Math.sin(n ) + 3).to_i
72
+ g = (3 * Math.sin(n + 2 * PI_3) + 3).to_i
73
+ b = (3 * Math.sin(n + 4 * PI_3) + 3).to_i
74
+
75
+ # Then we take rgb and encode them in a single number using base 6.
76
+ # For some mysterious reason, we add 16... to clear the bottom 4 bits?
77
+ # Yes... they're ugly.
78
+
79
+ 36 * r + 6 * g + b + 16
80
+ }
81
+
82
+ super
83
+ end
84
+
85
+ def pride string
86
+ c = @colors[@index % @size]
87
+ @index += 1
88
+ "#{ESC}38;5;#{c}m#{string}#{NND}"
89
+ end
90
+ end
91
+
92
+ klass = ENV['TERM'] =~ /^xterm(-256color)?$/ ? PrideLOL : PrideIO
93
+ MiniTest::Unit.output = klass.new(MiniTest::Unit.output)
data/lib/minitest/spec.rb CHANGED
@@ -53,16 +53,16 @@ module Kernel # :nodoc:
53
53
  # end
54
54
  # end
55
55
 
56
- def describe desc, &block # :doc:
56
+ def describe desc, additional_desc = nil, &block # :doc:
57
57
  stack = MiniTest::Spec.describe_stack
58
- name = [stack.last, desc].compact.join("::")
58
+ name = [stack.last, desc, additional_desc].compact.join("::")
59
59
  sclas = stack.last || if Class === self && self < MiniTest::Spec then
60
60
  self
61
61
  else
62
62
  MiniTest::Spec.spec_type desc
63
63
  end
64
64
 
65
- cls = sclas.create(name, desc)
65
+ cls = sclas.create name, desc
66
66
 
67
67
  stack.push cls
68
68
  cls.class_eval(&block)
@@ -116,7 +116,7 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
116
116
  end
117
117
 
118
118
  ##
119
- # Returns the children of this spec"
119
+ # Returns the children of this spec.
120
120
 
121
121
  def self.children
122
122
  @children ||= []
@@ -183,7 +183,18 @@ class MiniTest::Spec < MiniTest::Unit::TestCase
183
183
  end
184
184
  end
185
185
 
186
- def self.create(name, desc) # :nodoc:
186
+ def self.let name, &block
187
+ define_method name do
188
+ @_memoized ||= {}
189
+ @_memoized.fetch(name) { |k| @_memoized[k] = instance_eval(&block) }
190
+ end
191
+ end
192
+
193
+ def self.subject &block
194
+ let :subject, &block
195
+ end
196
+
197
+ def self.create name, desc # :nodoc:
187
198
  cls = Class.new(self) do
188
199
  @name = name
189
200
  @desc = desc
data/lib/minitest/unit.rb CHANGED
@@ -571,7 +571,7 @@ module MiniTest
571
571
  end
572
572
 
573
573
  ##
574
- # Fails if +o1+ is not +op+ +o2+ nil. eg:
574
+ # Fails if +o1+ is not +op+ +o2+. Eg:
575
575
  #
576
576
  # refute_operator 1, :>, 2 #=> pass
577
577
  # refute_operator 1, :<, 2 #=> fail
@@ -614,7 +614,7 @@ module MiniTest
614
614
  end
615
615
 
616
616
  class Unit
617
- VERSION = "2.4.0" # :nodoc:
617
+ VERSION = "2.5.0" # :nodoc:
618
618
 
619
619
  attr_accessor :report, :failures, :errors, :skips # :nodoc:
620
620
  attr_accessor :test_count, :assertion_count # :nodoc:
@@ -983,18 +983,24 @@ module MiniTest
983
983
 
984
984
  reset
985
985
 
986
+ ##
987
+ # Call this at the top of your tests when you absolutely
988
+ # positively need to have ordered tests. In doing so, you're
989
+ # admitting that you suck and your tests are weak.
990
+
991
+ def self.i_suck_and_my_tests_are_order_dependent!
992
+ class << self
993
+ define_method :test_order do :alpha end
994
+ end
995
+ end
996
+
986
997
  def self.inherited klass # :nodoc:
987
998
  @@test_suites[klass] = true
988
999
  klass.reset_setup_teardown_hooks
989
1000
  super
990
1001
  end
991
1002
 
992
- ##
993
- # Defines test order and is subclassable. Defaults to :random
994
- # but can be overridden to return :alpha if your tests are order
995
- # dependent (read: weak).
996
-
997
- def self.test_order
1003
+ def self.test_order # :nodoc:
998
1004
  :random
999
1005
  end
1000
1006
 
@@ -1,8 +1,6 @@
1
- require 'minitest/spec'
1
+ require 'minitest/autorun'
2
2
  require 'stringio'
3
3
 
4
- MiniTest::Unit.autorun
5
-
6
4
  describe MiniTest::Spec do
7
5
  before do
8
6
  @assertion_count = 4
@@ -196,6 +194,53 @@ describe MiniTest::Spec do
196
194
  end
197
195
  end
198
196
 
197
+ describe MiniTest::Spec, :let do
198
+ i_suck_and_my_tests_are_order_dependent!
199
+
200
+ def _count
201
+ $let_count ||= 0
202
+ end
203
+
204
+ let :count do
205
+ $let_count += 1
206
+ $let_count
207
+ end
208
+
209
+ it "is evaluated once per example" do
210
+ _count.must_equal 0
211
+
212
+ count.must_equal 1
213
+ count.must_equal 1
214
+
215
+ _count.must_equal 1
216
+ end
217
+
218
+ it "is REALLY evaluated once per example" do
219
+ _count.must_equal 1
220
+
221
+ count.must_equal 2
222
+ count.must_equal 2
223
+
224
+ _count.must_equal 2
225
+ end
226
+ end
227
+
228
+ describe MiniTest::Spec, :subject do
229
+ attr_reader :subject_evaluation_count
230
+
231
+ subject do
232
+ @subject_evaluation_count ||= 0
233
+ @subject_evaluation_count += 1
234
+ @subject_evaluation_count
235
+ end
236
+
237
+ it "is evaluated once per example" do
238
+ subject.must_equal 1
239
+ subject.must_equal 1
240
+ subject_evaluation_count.must_equal 1
241
+ end
242
+ end
243
+
199
244
  class TestMeta < MiniTest::Unit::TestCase
200
245
  def test_setup
201
246
  srand 42
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 2.4.0
10
+ version: 2.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Davis
@@ -36,7 +36,7 @@ cert_chain:
36
36
  FBHgymkyj/AOSqKRIpXPhjC6
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2011-08-10 00:00:00 Z
39
+ date: 2011-08-19 00:00:00 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: hoe
@@ -46,11 +46,11 @@ dependencies:
46
46
  requirements:
47
47
  - - ~>
48
48
  - !ruby/object:Gem::Version
49
- hash: 23
49
+ hash: 21
50
50
  segments:
51
51
  - 2
52
- - 10
53
- version: "2.10"
52
+ - 11
53
+ version: "2.11"
54
54
  type: :development
55
55
  version_requirements: *id001
56
56
  description: |-
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  requirements: []
140
140
 
141
141
  rubyforge_project: bfts
142
- rubygems_version: 1.8.5
142
+ rubygems_version: 1.8.7
143
143
  signing_key:
144
144
  specification_version: 3
145
145
  summary: minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking
metadata.gz.sig CHANGED
Binary file