GUnit 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{GUnit}
8
- s.version = "0.3.3"
8
+ s.version = "0.3.4"
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-02-03}
12
+ s.date = %q{2010-02-08}
13
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 = [
@@ -124,12 +124,12 @@ module GUnit
124
124
  self.run_excercise
125
125
  response = self.send(self.method_name.to_sym)
126
126
  self.run_teardowns
127
- rescue GUnit::NothingToDo => e
128
- response = ToDoResponse.new(e.message, e.backtrace)
129
- rescue GUnit::AssertionFailure => e
130
- response = FailResponse.new(e.message, e.backtrace)
131
127
  rescue ::Exception => e
132
- response = ExceptionResponse.new(e.message, e.backtrace)
128
+ response = case e
129
+ when GUnit::NothingToDo then ToDoResponse
130
+ when GUnit::AssertionFailure then FailResponse
131
+ else; ExceptionResponse
132
+ end.new(e.message, e.backtrace, self)
133
133
  ensure
134
134
  return response
135
135
  end
@@ -4,13 +4,14 @@ module GUnit
4
4
 
5
5
  DEFAULT_MESSAGE = ''
6
6
 
7
- attr_accessor :message
7
+ attr_accessor :message, :test_case
8
8
  attr_reader :backtrace, :line_number, :file_name
9
9
 
10
10
  # FailResponse.new("my message")
11
11
  def initialize(*args)
12
12
  self.message = args.find{|arg| arg.is_a?(String) } || self.class::DEFAULT_MESSAGE
13
13
  self.backtrace = args.find{|arg| arg.is_a?(Array) } || []
14
+ self.test_case = args.find{|arg| arg.is_a?(GUnit::TestCase) }
14
15
  end
15
16
 
16
17
  def backtrace=(traces=[])
@@ -111,6 +111,7 @@ module GUnit
111
111
  @io.puts ""
112
112
  @responses.select{|response| !response.is_a?(GUnit::PassResponse) }.each do |response|
113
113
  @io.print self.class.response_color(response)
114
+ @io.print response.test_case.context.all_message + "\n" if response.test_case && response.test_case.context
114
115
  @io.print "#{response.message} (#{response.file_name}:#{response.line_number})\n"
115
116
  @io.print DEFAULT_COLOR
116
117
  end
@@ -160,6 +160,7 @@ class GUnit::TestCaseTest < Test::Unit::TestCase
160
160
  assert response.is_a?(GUnit::TestResponse)
161
161
  assert response.is_a?(GUnit::FailResponse)
162
162
  assert_equal exception_message, response.message
163
+ assert_equal @my_test_case4, response.test_case
163
164
  end
164
165
 
165
166
  def test_run_with_test_method_raising_nothing_to_do_exception
@@ -192,6 +193,20 @@ class GUnit::TestCaseTest < Test::Unit::TestCase
192
193
  assert_equal exception_message, response.message
193
194
  end
194
195
 
196
+ def test_run_with_test_method_raising_string
197
+ exception = 'Whoops'
198
+ verify_message = "The truth"
199
+ verification = mock
200
+ verification.expects(:run).raises(exception)
201
+ dynamic_method_name = MyClassTest.verify(verify_message)
202
+ GUnit::Verification.expects(:new).with(verify_message).returns(verification)
203
+ @my_test_case5 = MyClassTest.new(dynamic_method_name)
204
+ response = @my_test_case5.run
205
+ assert response.is_a?(GUnit::TestResponse)
206
+ assert response.is_a?(GUnit::ExceptionResponse)
207
+ assert_equal exception, response.message
208
+ end
209
+
195
210
  def test_test_methods
196
211
  assert MyClassTest.test_methods.include?(:test_one)
197
212
  assert MyClassTest.test_methods.include?(:test_two)
@@ -31,6 +31,12 @@ class GUnit::TestResponseTest < Test::Unit::TestCase
31
31
  assert_equal backtrace, @test_response1.backtrace
32
32
  end
33
33
 
34
+ def test_test_case_setter
35
+ test_case = GUnit::TestCase.new
36
+ @test_response1.test_case = test_case
37
+ assert_equal test_case, @test_response1.test_case
38
+ end
39
+
34
40
  # TestResponse.new('my fixtures')
35
41
  def test_initialize_with_string
36
42
  message = 'Uhohs'
@@ -38,12 +44,21 @@ class GUnit::TestResponseTest < Test::Unit::TestCase
38
44
  assert @test_response2.message === message
39
45
  end
40
46
 
47
+ # TestResponse.new(['a', 'b', 'c'])
41
48
  def test_initialize_with_array
42
49
  backtrace = ['a', 'b', 'c']
43
50
  @test_response2 = GUnit::TestResponse.new(backtrace)
44
51
  assert_equal backtrace, @test_response2.backtrace
45
52
  end
46
53
 
54
+ # TestResponse.new(GUnit::TestCase.new)
55
+ def test_initialize_with_test_case
56
+ test_case = GUnit::TestCase.new
57
+ @test_response2 = GUnit::TestResponse.new(test_case)
58
+ assert_equal test_case, @test_response2.test_case
59
+ end
60
+
61
+ # TestResponse.new('my fixtures', ['a', 'b', 'c'])
47
62
  def test_initialize_with_string_and_array
48
63
  message = 'Uhohs'
49
64
  backtrace = ['a', 'b', 'c']
@@ -52,6 +67,15 @@ class GUnit::TestResponseTest < Test::Unit::TestCase
52
67
  assert @test_response2.message === message
53
68
  end
54
69
 
70
+ # TestResponse.new('my fixtures', GUnit::TestCase.new, ['a', 'b', 'c'])
71
+ def test_initialize_with_string_test_case_and_array
72
+ message = 'Uhohs'
73
+ backtrace = ['a', 'b', 'c']
74
+ @test_response2 = GUnit::TestResponse.new(message, backtrace)
75
+ assert_equal backtrace, @test_response2.backtrace
76
+ assert @test_response2.message === message
77
+ end
78
+
55
79
  def test_line_number
56
80
  assert_nil @test_response1.line_number
57
81
 
@@ -159,11 +159,19 @@ class GUnit::TestRunnerTest < Test::Unit::TestCase
159
159
  end
160
160
 
161
161
  def test_run_not_silent
162
+ test_case1 = GUnit::TestCase.new
163
+ test_case2 = GUnit::TestCase.new
164
+ context2_message = "my context here"
165
+ context2 = mock(:all_message => context2_message)
166
+ test_case2.expects(:context).at_least(1).returns(context2)
167
+ test_case3 = GUnit::TestCase.new
168
+ test_case4 = GUnit::TestCase.new
169
+
162
170
  test_response1 = GUnit::PassResponse.new
163
171
  fail_response_message = "Whoops. Failed."
164
172
  fail_line_number = 63
165
173
  fail_file_name = 'my_test.rb'
166
- test_response2 = GUnit::FailResponse.new(fail_response_message, ["samples/#{fail_file_name}:#{fail_line_number}:in `my_method'"])
174
+ test_response2 = GUnit::FailResponse.new(fail_response_message, ["samples/#{fail_file_name}:#{fail_line_number}:in `my_method'"], test_case2)
167
175
  exception_response_message = "Exceptional"
168
176
  exception_line_number = 72
169
177
  exception_file_name = 'my_other_test.rb'
@@ -171,7 +179,19 @@ class GUnit::TestRunnerTest < Test::Unit::TestCase
171
179
  to_do_response_message = "Not dun yet"
172
180
  test_response4 = GUnit::ToDoResponse.new(to_do_response_message)
173
181
  @test_runner.silent = false
182
+
183
+ test_case1.expects(:run).returns(test_response1)
184
+ test_case2.expects(:run).returns(test_response2)
185
+ test_case3.expects(:run).returns(test_response3)
186
+ test_case4.expects(:run).returns(test_response4)
187
+
188
+ test_suite = GUnit::TestSuite.new
189
+ test_suite.tests = [test_case1, test_case2, test_case4]
190
+ @test_runner.tests = [test_suite, test_case3]
191
+
174
192
  io = mock
193
+ io.stubs(:puts)
194
+
175
195
  io.expects(:print).with(GUnit::TestRunner::PASS_CHAR).at_least(1)
176
196
  io.expects(:print).with(GUnit::TestRunner::FAIL_CHAR).at_least(1)
177
197
  io.expects(:print).with(GUnit::TestRunner::EXCEPTION_CHAR).at_least(1)
@@ -186,25 +206,12 @@ class GUnit::TestRunnerTest < Test::Unit::TestCase
186
206
 
187
207
  io.expects(:print).with(GUnit::TestRunner::DEFAULT_COLOR).at_least(7)
188
208
 
189
- io.stubs(:puts)
209
+ io.expects(:print).with() { |value| value =~ /#{context2_message}/ }
190
210
  io.expects(:print).with() { |value| value =~ /#{fail_response_message}/ && value =~ /#{fail_file_name}/ && value =~ /#{fail_line_number}/ }.at_least(1)
191
211
  io.expects(:print).with() { |value| value =~ /#{exception_response_message}/ && value =~ /#{exception_file_name}/ && value =~ /#{exception_line_number}/ }.at_least(1)
192
212
  io.expects(:print).with() { |value| value =~ /#{to_do_response_message}/ }.at_least(1)
193
213
  @test_runner.io = io
194
214
 
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
-
204
- test_suite = GUnit::TestSuite.new
205
- test_suite.tests = [test_case1, test_case2, test_case4]
206
- @test_runner.tests = [test_suite, test_case3]
207
-
208
215
  io.expects(:puts).with(test_case1.class.to_s).at_least(1)
209
216
 
210
217
  @test_runner.run
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.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Sterndale
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-03 00:00:00 -05:00
12
+ date: 2010-02-08 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15