GUnit 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ Unit Test. Gangsta style.
4
4
 
5
5
  GUnit is a fresh new XUnit Test implementation, poppin' a cap in the ass of TestUnit.
6
6
 
7
- Just playin'. TestUnit is our boy.
7
+ Just playin'. TestUnit is the shizzle.
8
8
 
9
9
  == Rolling with the following features:
10
10
  * Nested contexts
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ begin
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "GUnit"
8
8
  gem.summary = %Q{XUnit Test. Gangsta style.}
9
- gem.description = %Q{GUnit is a fresh new XUnit Test implementation, poppin' a cap in the ass of TestUnit. Just playin'. TestUnit is our boy.}
9
+ gem.description = %Q{GUnit is a fresh new XUnit Test implementation, poppin' a cap in the ass of TestUnit. Just playin'. TestUnit is the shizzle.}
10
10
  gem.email = "gsterndale@gmail.com"
11
11
  gem.homepage = "http://github.com/gsterndale/gunit"
12
12
  gem.authors = ["Greg Sterndale"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{GUnit}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Greg Sterndale"]
12
- s.date = %q{2010-01-27}
13
- s.description = %q{GUnit is a fresh new XUnit Test implementation, poppin' a cap in the ass of TestUnit. Just playin'. TestUnit is our boy.}
12
+ s.date = %q{2010-01-30}
13
+ s.description = %q{GUnit is a fresh new XUnit Test implementation, poppin' a cap in the ass of TestUnit. Just playin'. TestUnit is the shizzle.}
14
14
  s.email = %q{gsterndale@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -54,18 +54,29 @@ module GUnit
54
54
  actual = e
55
55
  end
56
56
 
57
- bool = case
58
- when actual.nil?
57
+ bool = if actual.nil?
59
58
  false
60
- when expected.is_a?(String)
61
- actual.to_s == expected
62
- when expected.is_a?(Class)
63
- actual.is_a?(expected)
64
- when expected.nil?
65
- !actual.nil?
66
59
  else
67
- actual == expected
60
+ case expected
61
+ when String then actual.to_s == expected
62
+ when Class then actual.is_a?(expected)
63
+ when Nil then !actual.nil?
64
+ else; actual == expected
65
+ end
68
66
  end
67
+
68
+ # bool = case
69
+ # when actual.nil?
70
+ # false
71
+ # when expected.is_a?(String)
72
+ # actual.to_s == expected
73
+ # when expected.is_a?(Class)
74
+ # actual.is_a?(expected)
75
+ # when expected.nil?
76
+ # !actual.nil?
77
+ # else
78
+ # actual == expected
79
+ # end
69
80
 
70
81
  message ||= case
71
82
  when !expected.nil? && !actual.nil?
@@ -20,11 +20,16 @@ module GUnit
20
20
 
21
21
  include Singleton
22
22
 
23
- PASS_CHAR = '.'
24
- FAIL_CHAR = 'F'
25
- TODO_CHAR = '*'
26
- EXCEPTION_CHAR = 'E'
27
-
23
+ PASS_CHAR = '.'
24
+ FAIL_CHAR = 'F'
25
+ TODO_CHAR = '*'
26
+ EXCEPTION_CHAR = 'E'
27
+ PASS_COLOR = "\e[0;32m"
28
+ FAIL_COLOR = "\e[0;31m"
29
+ EXCEPTION_COLOR = "\e[0;31m"
30
+ TODO_COLOR = "\e[0;33m"
31
+ DEFAULT_COLOR = "\e[0m"
32
+
28
33
  DEFAULT_PATTERNS = ['test/**/*_test.rb', 'test/**/test_*.rb']
29
34
 
30
35
  # TestSuites and/or TestCases
@@ -65,24 +70,25 @@ module GUnit
65
70
  end
66
71
 
67
72
  def run
68
- self.tests.each do |test|
69
- case
70
- when test.is_a?(TestSuite)
71
- test.run do |response|
72
- @responses << response
73
- @io.print self.class.response_character(response) unless self.silent
74
- end
75
- when test.is_a?(TestCase)
76
- response = test.run
77
- @responses << response
78
- @io.print self.class.response_character(response) unless self.silent
73
+ @io.puts test_case_classes.map{|klass| klass.to_s }.join(', ') unless self.silent
74
+ self.test_cases.each do |test_case|
75
+ response = test_case.run
76
+ @responses << response
77
+ unless self.silent
78
+ @io.print self.class.response_color(response)
79
+ @io.print self.class.response_character(response)
80
+ @io.print DEFAULT_COLOR
79
81
  end
80
82
  end
81
83
 
82
84
  unless self.silent
83
85
  @io.puts ""
84
86
  @responses.each do |response|
85
- @io.puts "#{response.message} (#{response.file_name}:#{response.line_number})" unless response.is_a?(GUnit::PassResponse)
87
+ unless response.is_a?(GUnit::PassResponse)
88
+ @io.print self.class.response_color(response)
89
+ @io.print "#{response.message} (#{response.file_name}:#{response.line_number})\n"
90
+ @io.print DEFAULT_COLOR
91
+ end
86
92
  end
87
93
  @io.puts "#{@responses.length} verifications: #{passes.length} passed, #{fails.length} failed, #{exceptions.length} exceptions, #{to_dos.length} to-dos"
88
94
  end
@@ -105,20 +111,41 @@ module GUnit
105
111
  end
106
112
 
107
113
  protected
108
-
114
+
115
+ # Flatten array of TestSuites and TestCases into a single dimensional array of TestCases
116
+ def test_cases(a=self.tests)
117
+ a.map do |test|
118
+ case test
119
+ when GUnit::TestSuite
120
+ test_cases(test.tests)
121
+ when GUnit::TestCase
122
+ test
123
+ end
124
+ end.flatten
125
+ end
126
+
127
+ # Unique TestCase subclasses
128
+ def test_case_classes
129
+ test_cases.map{|test| test.class }.uniq
130
+ end
131
+
109
132
  def self.response_character(response)
110
- case
111
- when response.is_a?(PassResponse)
112
- PASS_CHAR
113
- when response.is_a?(FailResponse)
114
- FAIL_CHAR
115
- when response.is_a?(ExceptionResponse)
116
- EXCEPTION_CHAR
117
- when response.is_a?(ToDoResponse)
118
- TODO_CHAR
133
+ case response
134
+ when PassResponse then PASS_CHAR
135
+ when FailResponse then FAIL_CHAR
136
+ when ExceptionResponse then EXCEPTION_CHAR
137
+ when ToDoResponse then TODO_CHAR
138
+ end
139
+ end
140
+
141
+ def self.response_color(response)
142
+ case response
143
+ when PassResponse then PASS_COLOR
144
+ when FailResponse then FAIL_COLOR
145
+ when ExceptionResponse then EXCEPTION_COLOR
146
+ when ToDoResponse then TODO_COLOR
119
147
  end
120
148
  end
121
-
122
149
  end
123
150
 
124
151
  end
@@ -1,29 +1,17 @@
1
1
  module GUnit
2
-
2
+
3
3
  class TestSuite
4
-
5
- # TestCases (TODO and/or TestSuites)
4
+
5
+ # TestCases and/or TestSuites
6
6
  attr_writer :tests
7
-
7
+
8
8
  def initialize()
9
9
  end
10
-
10
+
11
11
  def tests
12
12
  @tests ||= []
13
13
  end
14
-
15
- def run(&blk)
16
- self.tests.each do |test|
17
- case
18
- when test.is_a?(TestSuite)
19
- test.run{|response| blk.call(response) if blk }
20
- when test.is_a?(TestCase)
21
- response = test.run
22
- blk.call(response) if blk
23
- end
24
- end
25
- end
26
-
14
+
27
15
  end
28
-
16
+
29
17
  end
@@ -1,8 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'ruby-debug'
3
3
  require File.join(File.dirname(__FILE__), '..', 'martini')
4
- require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'gunit')
5
4
 
6
- # $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
- # $LOAD_PATH.unshift(File.dirname(__FILE__))
8
- # require 'gunit'
5
+ # Let's use this version of GUnit, instead of whatever may be install via Gem
6
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'gunit')
7
+ # require 'GUnit'
@@ -77,8 +77,10 @@ class GUnit::TestRunnerTest < Test::Unit::TestCase
77
77
  patterns = [ 'test/**/*_MY_test.rb', 'test/**/MY_test_*.rb' ]
78
78
  @test_runner.patterns = patterns
79
79
  test_response1 = GUnit::PassResponse.new
80
+ test_case = GUnit::TestCase.new
81
+ test_case.expects(:run).returns(test_response1)
80
82
  test_suite = GUnit::TestSuite.new
81
- test_suite.expects(:run).multiple_yields(test_response1)
83
+ test_suite.expects(:tests).returns([test_case]).at_least(1)
82
84
  @test_runner.tests = [test_suite]
83
85
  @test_runner.autorun = false
84
86
  @test_runner.run
@@ -130,9 +132,11 @@ class GUnit::TestRunnerTest < Test::Unit::TestCase
130
132
  def test_run_silent
131
133
  @test_runner.io = mock() # fails if any methods on io are called
132
134
  @test_runner.silent = true
133
- test_response1 = GUnit::PassResponse.new
135
+ test_response1 = GUnit::PassResponse.new
136
+ test_case = GUnit::TestCase.new
137
+ test_case.expects(:run).returns(test_response1)
134
138
  test_suite = GUnit::TestSuite.new
135
- test_suite.expects(:run).yields(test_response1)
139
+ test_suite.tests = [test_case]
136
140
  @test_runner.tests = [test_suite]
137
141
  @test_runner.run
138
142
  end
@@ -140,15 +144,16 @@ class GUnit::TestRunnerTest < Test::Unit::TestCase
140
144
  def test_run_bang
141
145
  @test_runner.io = mock() # fails if any methods on io are called
142
146
  @test_runner.silent = true
143
- test_response1 = GUnit::PassResponse.new
147
+ test_case = GUnit::TestCase.new
144
148
  test_suite = GUnit::TestSuite.new
149
+ test_suite.tests = [test_case]
145
150
  @test_runner.tests = [test_suite]
146
-
147
- test_suite.expects(:run).times(0)
151
+ test_case.expects(:run).times(0)
148
152
  @test_runner.autorun = false
149
153
  @test_runner.run!
150
-
151
- test_suite.expects(:run).times(1).yields(test_response1)
154
+
155
+ test_response1 = GUnit::PassResponse.new
156
+ test_case.expects(:run).times(1).returns(test_response1)
152
157
  @test_runner.autorun = true
153
158
  @test_runner.run!
154
159
  end
@@ -158,29 +163,49 @@ class GUnit::TestRunnerTest < Test::Unit::TestCase
158
163
  fail_response_message = "Whoops. Failed."
159
164
  fail_line_number = 63
160
165
  fail_file_name = 'my_test.rb'
161
- backtrace =
162
166
  test_response2 = GUnit::FailResponse.new(fail_response_message, ["samples/#{fail_file_name}:#{fail_line_number}:in `my_method'"])
163
167
  exception_response_message = "Exceptional"
164
168
  exception_line_number = 72
165
169
  exception_file_name = 'my_other_test.rb'
166
170
  test_response3 = GUnit::ExceptionResponse.new(exception_response_message, ["samples/#{exception_file_name}:#{exception_line_number}:in `my_method'"])
167
- test_response4 = GUnit::ToDoResponse.new
171
+ to_do_response_message = "Not dun yet"
172
+ test_response4 = GUnit::ToDoResponse.new(to_do_response_message)
168
173
  @test_runner.silent = false
169
174
  io = mock
170
175
  io.expects(:print).with(GUnit::TestRunner::PASS_CHAR).at_least(1)
171
176
  io.expects(:print).with(GUnit::TestRunner::FAIL_CHAR).at_least(1)
172
177
  io.expects(:print).with(GUnit::TestRunner::EXCEPTION_CHAR).at_least(1)
173
178
  io.expects(:print).with(GUnit::TestRunner::TODO_CHAR).at_least(1)
179
+
180
+ io.expects(:print).with(GUnit::TestRunner::PASS_COLOR).at_least(1)
181
+ # One call to print with each color for every response char and every failing message
182
+ io.expects(:print).with(GUnit::TestRunner::FAIL_COLOR).at_least(4)
183
+ # FAIL_COLOR and EXCEPTION_COLOR are the same. Setting two identical expectations causes a failure
184
+ # io.expects(:print).with(GUnit::TestRunner::EXCEPTION_COLOR).at_least(2)
185
+ io.expects(:print).with(GUnit::TestRunner::TODO_COLOR).at_least(2)
186
+
187
+ io.expects(:print).with(GUnit::TestRunner::DEFAULT_COLOR).at_least(7)
188
+
174
189
  io.stubs(:puts)
175
- io.expects(:puts).with() { |value| value =~ /#{fail_response_message}/ && value =~ /#{fail_file_name}/ && value =~ /#{fail_line_number}/ }.at_least(1)
176
- io.expects(:puts).with() { |value| value =~ /#{exception_response_message}/ && value =~ /#{exception_file_name}/ && value =~ /#{exception_line_number}/ }.at_least(1)
190
+ io.expects(:print).with() { |value| value =~ /#{fail_response_message}/ && value =~ /#{fail_file_name}/ && value =~ /#{fail_line_number}/ }.at_least(1)
191
+ io.expects(:print).with() { |value| value =~ /#{exception_response_message}/ && value =~ /#{exception_file_name}/ && value =~ /#{exception_line_number}/ }.at_least(1)
192
+ io.expects(:print).with() { |value| value =~ /#{to_do_response_message}/ }.at_least(1)
177
193
  @test_runner.io = io
178
-
194
+
195
+ test_case1 = GUnit::TestCase.new
196
+ test_case1.expects(:run).returns(test_response1)
197
+ test_case2 = GUnit::TestCase.new
198
+ test_case2.expects(:run).returns(test_response2)
199
+ test_case3 = GUnit::TestCase.new
200
+ test_case3.expects(:run).returns(test_response3)
201
+ test_case4 = GUnit::TestCase.new
202
+ test_case4.expects(:run).returns(test_response4)
203
+
179
204
  test_suite = GUnit::TestSuite.new
180
- test_suite.expects(:run).multiple_yields(test_response1, test_response2, test_response4)
181
- test_case = GUnit::TestCase.new
182
- test_case.expects(:run).returns(test_response3)
183
- @test_runner.tests = [test_suite, test_case]
205
+ test_suite.tests = [test_case1, test_case2, test_case4]
206
+ @test_runner.tests = [test_suite, test_case3]
207
+
208
+ io.expects(:puts).with(test_case1.class.to_s).at_least(1)
184
209
 
185
210
  @test_runner.run
186
211
  end
@@ -190,11 +215,17 @@ class GUnit::TestRunnerTest < Test::Unit::TestCase
190
215
  test_response2 = GUnit::FailResponse.new
191
216
  test_response3 = GUnit::ExceptionResponse.new
192
217
  test_response4 = GUnit::ToDoResponse.new
218
+ test_case1 = GUnit::TestCase.new
219
+ test_case1.expects(:run).returns(test_response1)
220
+ test_case2 = GUnit::TestCase.new
221
+ test_case2.expects(:run).returns(test_response2)
222
+ test_case3 = GUnit::TestCase.new
223
+ test_case3.expects(:run).returns(test_response3)
224
+ test_case4 = GUnit::TestCase.new
225
+ test_case4.expects(:run).returns(test_response4)
193
226
  test_suite = GUnit::TestSuite.new
194
- test_suite.expects(:run).multiple_yields(test_response1, test_response2, test_response4)
195
- test_case = GUnit::TestCase.new
196
- test_case.expects(:run).returns(test_response3)
197
- @test_runner.tests = [test_suite, test_case]
227
+ test_suite.tests = [test_case1, test_case2, test_case4]
228
+ @test_runner.tests = [test_suite, test_case3]
198
229
 
199
230
  @test_runner.run
200
231
 
@@ -1,48 +1,26 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class GUnit::TestSuiteTest < Test::Unit::TestCase
4
-
4
+
5
5
  def setup
6
6
  @test_suite = GUnit::TestSuite.new
7
7
  end
8
-
8
+
9
9
  def test_it_is_a_test_suite
10
10
  assert @test_suite.is_a?(GUnit::TestSuite)
11
11
  end
12
-
12
+
13
13
  def test_tests_getter_setter
14
14
  tests = [GUnit::TestSuite.new, GUnit::TestCase.new]
15
15
  assert @test_suite.tests != tests
16
16
  @test_suite.tests = tests
17
17
  assert @test_suite.tests == tests
18
18
  end
19
-
19
+
20
20
  def test_tests_set_nil_has_empty_tests
21
21
  @test_suite.tests = nil
22
22
  assert @test_suite.tests.empty?
23
23
  assert @test_suite.tests.is_a?(Enumerable)
24
24
  end
25
-
26
- def test_run_runs_all_tests_saves_responses
27
- test_response1 = GUnit::PassResponse.new
28
- test_response2 = GUnit::FailResponse.new
29
- test_response3 = GUnit::ExceptionResponse.new
30
25
 
31
- test_suite = GUnit::TestSuite.new
32
- test_suite.expects(:run).multiple_yields(test_response1, test_response2)
33
-
34
- test_case = GUnit::TestCase.new
35
- test_case.expects(:run).returns(test_response3)
36
-
37
- @test_suite.tests = [test_suite, test_case]
38
-
39
- responses = []
40
- @test_suite.run{|r| responses << r }
41
-
42
- assert responses.include?(test_response1)
43
- assert responses.include?(test_response2)
44
- assert responses.include?(test_response3)
45
- assert responses.length == 3
46
- end
47
-
48
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: GUnit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Sterndale
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-27 00:00:00 -05:00
12
+ date: 2010-01-30 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: GUnit is a fresh new XUnit Test implementation, poppin' a cap in the ass of TestUnit. Just playin'. TestUnit is our boy.
16
+ description: GUnit is a fresh new XUnit Test implementation, poppin' a cap in the ass of TestUnit. Just playin'. TestUnit is the shizzle.
17
17
  email: gsterndale@gmail.com
18
18
  executables: []
19
19