GUnit 0.2.2 → 0.3.0
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.
- data/VERSION +1 -1
- data/gunit.gemspec +6 -2
- data/lib/gunit/test_case.rb +45 -19
- data/lib/gunit/test_runner.rb +35 -8
- data/lib/gunit.rb +2 -2
- data/samples/Rakefile +21 -0
- data/samples/martini.rb +34 -0
- data/samples/test/martini_test.rb +57 -0
- data/samples/test/test_helper.rb +8 -0
- data/test/integration/foo_test.rb +1 -1
- data/test/test_helper.rb +1 -0
- data/test/unit/test_case_test.rb +17 -1
- data/test/unit/test_runner_test.rb +93 -4
- metadata +6 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/gunit.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{GUnit}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
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-
|
12
|
+
s.date = %q{2010-01-27}
|
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 our boy.}
|
14
14
|
s.email = %q{gsterndale@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -40,6 +40,10 @@ Gem::Specification.new do |s|
|
|
40
40
|
"lib/gunit/test_suite.rb",
|
41
41
|
"lib/gunit/to_do_response.rb",
|
42
42
|
"lib/gunit/verification.rb",
|
43
|
+
"samples/Rakefile",
|
44
|
+
"samples/martini.rb",
|
45
|
+
"samples/test/martini_test.rb",
|
46
|
+
"samples/test/test_helper.rb",
|
43
47
|
"test/integration/foo_test.rb",
|
44
48
|
"test/test_helper.rb",
|
45
49
|
"test/unit/assertions_test.rb",
|
data/lib/gunit/test_case.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
module GUnit
|
2
|
-
|
3
2
|
# Acts as a TestSuite Factory
|
4
3
|
# Creates a TestCase Object for each Test Method
|
5
4
|
# Adds all TestCase Objects onto a TestSuite Object
|
@@ -12,9 +11,8 @@ module GUnit
|
|
12
11
|
|
13
12
|
# count, run, display
|
14
13
|
class TestCase
|
15
|
-
|
16
14
|
include Assertions
|
17
|
-
|
15
|
+
|
18
16
|
TEST_METHOD_PREFIX = 'test'
|
19
17
|
|
20
18
|
attr_accessor :method_name
|
@@ -23,23 +21,39 @@ module GUnit
|
|
23
21
|
@@method_count = 0
|
24
22
|
@@context_stack = [ GUnit::Context.new ]
|
25
23
|
@@test_method_contexts = {}
|
26
|
-
|
24
|
+
@@autorun = true
|
25
|
+
@@subclasses = []
|
26
|
+
|
27
27
|
def initialize(method=nil)
|
28
28
|
self.method_name = method
|
29
29
|
end
|
30
|
-
|
31
|
-
def
|
32
|
-
|
30
|
+
|
31
|
+
def self.subclasses
|
32
|
+
@@subclasses
|
33
33
|
end
|
34
|
-
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
self.run_teardowns
|
40
|
-
response
|
34
|
+
|
35
|
+
def self.inherited(subclass)
|
36
|
+
subclasses << subclass
|
37
|
+
# autorun must happen at exit, otherwise the subclass won't be loaded
|
38
|
+
at_exit { subclass.autorun }
|
41
39
|
end
|
42
|
-
|
40
|
+
|
41
|
+
def self.autorun=(a)
|
42
|
+
@@autorun = !a.nil? && a
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.autorun?
|
46
|
+
@@autorun
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.autorun
|
50
|
+
if GUnit::TestCase.autorun?
|
51
|
+
test_runner = GUnit::TestRunner.instance
|
52
|
+
test_runner.tests << suite
|
53
|
+
test_runner.run!
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
43
57
|
def self.suite
|
44
58
|
# Create an new instance of self.class for each test method and add them to a TestSuite Object
|
45
59
|
test_suite = TestSuite.new
|
@@ -119,9 +133,21 @@ module GUnit
|
|
119
133
|
TEST_METHOD_PREFIX.to_sym
|
120
134
|
end
|
121
135
|
end
|
122
|
-
|
136
|
+
|
137
|
+
def context
|
138
|
+
self.class.context_for_method(self.method_name)
|
139
|
+
end
|
140
|
+
|
141
|
+
def run
|
142
|
+
self.run_setups
|
143
|
+
self.run_excercise
|
144
|
+
response = self.send(self.method_name.to_sym)
|
145
|
+
self.run_teardowns
|
146
|
+
response
|
147
|
+
end
|
148
|
+
|
123
149
|
protected
|
124
|
-
|
150
|
+
|
125
151
|
def run_setups
|
126
152
|
self.context.all_setups.each {|s| s.run(self) }
|
127
153
|
end
|
@@ -145,7 +171,7 @@ module GUnit
|
|
145
171
|
end
|
146
172
|
name
|
147
173
|
end
|
148
|
-
|
174
|
+
|
149
175
|
end
|
150
|
-
|
176
|
+
|
151
177
|
end
|
data/lib/gunit/test_runner.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
1
3
|
module GUnit
|
2
4
|
|
3
5
|
# How many tests have run
|
@@ -15,28 +17,53 @@ module GUnit
|
|
15
17
|
# After all tests have run, the TestRunner displays a summery of results
|
16
18
|
|
17
19
|
class TestRunner
|
18
|
-
|
20
|
+
|
21
|
+
include Singleton
|
22
|
+
|
19
23
|
PASS_CHAR = '.'
|
20
24
|
FAIL_CHAR = 'F'
|
21
25
|
TODO_CHAR = '*'
|
22
26
|
EXCEPTION_CHAR = 'E'
|
23
27
|
|
28
|
+
DEFAULT_PATTERNS = ['test/**/*_test.rb', 'test/**/test_*.rb']
|
29
|
+
|
24
30
|
# TestSuites and/or TestCases
|
25
|
-
attr_accessor :io, :silent
|
26
|
-
attr_writer :tests
|
31
|
+
attr_accessor :io, :silent, :patterns
|
32
|
+
attr_writer :tests, :autorun
|
27
33
|
attr_reader :responses
|
28
34
|
|
29
35
|
def initialize(*args)
|
30
|
-
@responses = []
|
31
|
-
@io = STDOUT
|
32
36
|
STDOUT.sync = true
|
33
|
-
|
37
|
+
reset
|
34
38
|
end
|
35
|
-
|
39
|
+
|
40
|
+
def reset
|
41
|
+
@io = STDOUT
|
42
|
+
@silent = false
|
43
|
+
@responses = []
|
44
|
+
@tests = []
|
45
|
+
@patterns = DEFAULT_PATTERNS
|
46
|
+
@autorun = true
|
47
|
+
end
|
48
|
+
|
49
|
+
def discover
|
50
|
+
files = self.patterns.inject([]){|memo, pattern| memo + Dir.glob(pattern) }.compact
|
51
|
+
files.each {|file| Kernel.require file }
|
52
|
+
self.tests = TestCase.subclasses.inject([]){|memo, test_case| memo << test_case.suite }.compact
|
53
|
+
end
|
54
|
+
|
36
55
|
def tests
|
37
56
|
@tests ||= []
|
38
57
|
end
|
39
|
-
|
58
|
+
|
59
|
+
def autorun?
|
60
|
+
! @autorun.nil? && @autorun
|
61
|
+
end
|
62
|
+
|
63
|
+
def run!
|
64
|
+
self.run if self.autorun?
|
65
|
+
end
|
66
|
+
|
40
67
|
def run
|
41
68
|
self.tests.each do |test|
|
42
69
|
case
|
data/lib/gunit.rb
CHANGED
@@ -17,9 +17,9 @@ require 'gunit/fail_response'
|
|
17
17
|
require 'gunit/pass_response'
|
18
18
|
require 'gunit/to_do_response'
|
19
19
|
|
20
|
-
require 'gunit/test_case'
|
21
|
-
require 'gunit/test_suite'
|
22
20
|
require 'gunit/test_runner'
|
21
|
+
require 'gunit/test_suite'
|
22
|
+
require 'gunit/test_case'
|
23
23
|
|
24
24
|
|
25
25
|
|
data/samples/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
# require 'GUnit'
|
4
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'gunit')
|
5
|
+
|
6
|
+
task :default => "gunit:test"
|
7
|
+
|
8
|
+
namespace :gunit do
|
9
|
+
|
10
|
+
desc "Run GUnit tests"
|
11
|
+
task :test do
|
12
|
+
test_runner = GUnit::TestRunner.instance
|
13
|
+
test_runner.autorun = false
|
14
|
+
test_runner.patterns = ['test/**/*_test.rb']
|
15
|
+
test_runner.discover
|
16
|
+
test_runner.run
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
|
data/samples/martini.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
class Martini
|
2
|
+
|
3
|
+
class BadBartender < Exception; end
|
4
|
+
|
5
|
+
attr_accessor :ice, :vermouth, :olive_brine
|
6
|
+
attr_reader :liquor, :garnish
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
@ice = false
|
10
|
+
@vermouth = false
|
11
|
+
@olive_brine = true
|
12
|
+
@garnish = 'olives'
|
13
|
+
@liquor = 'vodka'
|
14
|
+
end
|
15
|
+
|
16
|
+
def dirty?
|
17
|
+
olive_brine && ! (garnish =~ /olive/).nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
def straight_up?
|
21
|
+
! ice
|
22
|
+
end
|
23
|
+
|
24
|
+
def garnish=(g)
|
25
|
+
raise BadBartender unless g =~ /lemon|olive/
|
26
|
+
@garnish = g
|
27
|
+
end
|
28
|
+
|
29
|
+
def liquor=(l)
|
30
|
+
raise BadBartender unless l =~ /vodka|gin/
|
31
|
+
@liquor = l
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class MartiniTest < GUnit::TestCase
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@martini = Martini.new
|
7
|
+
end
|
8
|
+
|
9
|
+
verify "ice attribute" do
|
10
|
+
ice = false
|
11
|
+
@martini.ice = ice
|
12
|
+
assert ice === @martini.ice
|
13
|
+
end
|
14
|
+
|
15
|
+
verify "vermouth attribute" do
|
16
|
+
vermouth = false
|
17
|
+
@martini.vermouth = vermouth
|
18
|
+
assert vermouth === @martini.vermouth
|
19
|
+
end
|
20
|
+
|
21
|
+
verify "olive_brine attribute" do
|
22
|
+
olive_brine = false
|
23
|
+
@martini.olive_brine = olive_brine
|
24
|
+
assert olive_brine === @martini.olive_brine
|
25
|
+
end
|
26
|
+
|
27
|
+
verify "liquor attribute" do
|
28
|
+
liquor = 'gin'
|
29
|
+
@martini.liquor = liquor
|
30
|
+
assert liquor === @martini.liquor
|
31
|
+
end
|
32
|
+
|
33
|
+
verify "garnish attribute" do
|
34
|
+
garnish = 'lemon'
|
35
|
+
@martini.garnish = garnish
|
36
|
+
assert garnish === @martini.garnish
|
37
|
+
end
|
38
|
+
|
39
|
+
verify "dirty by default" do
|
40
|
+
assert @martini.dirty?
|
41
|
+
end
|
42
|
+
|
43
|
+
verify "straight up by default" do
|
44
|
+
assert @martini.straight_up?
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with ice" do
|
48
|
+
setup do
|
49
|
+
@martini.ice = true
|
50
|
+
end
|
51
|
+
|
52
|
+
verify "not straight up" do
|
53
|
+
assert ! @martini.straight_up?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ruby-debug'
|
3
|
+
require File.join(File.dirname(__FILE__), '..', 'martini')
|
4
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'gunit')
|
5
|
+
|
6
|
+
# $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
# $LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
# require 'gunit'
|
@@ -171,7 +171,7 @@ end
|
|
171
171
|
|
172
172
|
class FooGUnitTestTest < Test::Unit::TestCase
|
173
173
|
def setup
|
174
|
-
@test_runner = GUnit::TestRunner.
|
174
|
+
@test_runner = GUnit::TestRunner.instance
|
175
175
|
@test_runner.io = mock('io')
|
176
176
|
@test_runner.io.stubs(:print)
|
177
177
|
@test_runner.io.stubs(:puts)
|
data/test/test_helper.rb
CHANGED
data/test/unit/test_case_test.rb
CHANGED
@@ -21,7 +21,23 @@ class GUnit::TestCaseTest < Test::Unit::TestCase
|
|
21
21
|
def test_it_is_a_test_case
|
22
22
|
assert @my_test_case.is_a?(GUnit::TestCase)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
|
+
def test_subclasses_class_attr
|
26
|
+
assert ! GUnit::TestCase.subclasses.empty?
|
27
|
+
assert GUnit::TestCase.subclasses.include?(MyClassTest)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_autorun_class_attr
|
31
|
+
assert GUnit::TestCase.autorun? === false # set to false in test_helper.rb
|
32
|
+
GUnit::TestCase.autorun = true
|
33
|
+
assert GUnit::TestCase.autorun?
|
34
|
+
GUnit::TestRunner.expects(:instance).times(1).returns(mock(:tests => [], :run! => true))
|
35
|
+
MyClassTest.autorun
|
36
|
+
GUnit::TestCase.autorun = false
|
37
|
+
GUnit::TestRunner.expects(:instance).times(0)
|
38
|
+
MyClassTest.autorun
|
39
|
+
end
|
40
|
+
|
25
41
|
def test_method_name_setter_getter
|
26
42
|
method_name = "my_method"
|
27
43
|
assert_not_equal method_name, @my_test_case.method_name
|
@@ -3,24 +3,96 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|
3
3
|
class GUnit::TestRunnerTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def setup
|
6
|
-
@test_runner = GUnit::TestRunner.
|
6
|
+
@test_runner = GUnit::TestRunner.instance
|
7
|
+
@test_runner.reset
|
7
8
|
io = Object.new
|
8
9
|
@test_runner.io = io
|
9
10
|
@test_runner.io.stubs(:print)
|
10
11
|
@test_runner.io.stubs(:puts)
|
11
12
|
end
|
12
|
-
|
13
|
+
|
13
14
|
def test_it_is_a_test_runner
|
14
15
|
assert @test_runner.is_a?(GUnit::TestRunner)
|
15
16
|
end
|
16
|
-
|
17
|
+
|
18
|
+
def test_singleton
|
19
|
+
assert_raise NoMethodError do; @test_runner.new; end
|
20
|
+
tests = [GUnit::TestSuite.new, GUnit::TestCase.new]
|
21
|
+
assert @test_runner.tests != tests
|
22
|
+
@test_runner.tests = tests
|
23
|
+
assert @test_runner.tests == tests
|
24
|
+
@test_runner = GUnit::TestRunner.instance
|
25
|
+
assert @test_runner.tests == tests
|
26
|
+
end
|
27
|
+
|
17
28
|
def test_tests_getter_setter
|
18
29
|
tests = [GUnit::TestSuite.new, GUnit::TestCase.new]
|
19
30
|
assert @test_runner.tests != tests
|
20
31
|
@test_runner.tests = tests
|
21
32
|
assert @test_runner.tests == tests
|
22
33
|
end
|
34
|
+
|
35
|
+
def test_patterns_getter_setter
|
36
|
+
patterns = ['test/**/*_MY_test.rb', 'test/**/MY_test_*.rb']
|
37
|
+
assert @test_runner.patterns != patterns
|
38
|
+
@test_runner.patterns = patterns
|
39
|
+
assert @test_runner.patterns == patterns
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_autorun_getter_setter
|
43
|
+
assert @test_runner.autorun?
|
44
|
+
@test_runner.autorun = false
|
45
|
+
assert ! @test_runner.autorun?
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_default_patterns
|
49
|
+
assert ! @test_runner.patterns.empty?
|
50
|
+
assert_equal GUnit::TestRunner::DEFAULT_PATTERNS, @test_runner.patterns
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_discover_tests
|
54
|
+
pattern1 = 'foo'
|
55
|
+
pattern2 = 'bar'
|
56
|
+
file1 = 'foo.rb'
|
57
|
+
file2 = 'bar.rb'
|
58
|
+
file3 = 'baz.rb'
|
59
|
+
@test_runner.patterns = [ pattern1, pattern2 ]
|
60
|
+
Dir.expects(:glob).with(pattern1).returns( [ file1, file2 ] ).once
|
61
|
+
Dir.expects(:glob).with(pattern2).returns( [ file3 ] ).once
|
62
|
+
Kernel.expects(:require).with(file1).returns(true).once
|
63
|
+
Kernel.expects(:require).with(file2).returns(true).once
|
64
|
+
Kernel.expects(:require).with(file3).returns(true).once
|
65
|
+
suite1 = mock
|
66
|
+
suite2 = mock
|
67
|
+
test_case_subclass1 = mock(:suite => suite1)
|
68
|
+
test_case_subclass2 = mock(:suite => suite2)
|
69
|
+
GUnit::TestCase.expects(:subclasses).returns([test_case_subclass1, test_case_subclass2])
|
70
|
+
@test_runner.discover
|
71
|
+
assert @test_runner.tests.include?(suite1)
|
72
|
+
assert @test_runner.tests.include?(suite2)
|
73
|
+
end
|
23
74
|
|
75
|
+
|
76
|
+
def test_reset_clears_tests_responses_patterns_autorun
|
77
|
+
patterns = [ 'test/**/*_MY_test.rb', 'test/**/MY_test_*.rb' ]
|
78
|
+
@test_runner.patterns = patterns
|
79
|
+
test_response1 = GUnit::PassResponse.new
|
80
|
+
test_suite = GUnit::TestSuite.new
|
81
|
+
test_suite.expects(:run).multiple_yields(test_response1)
|
82
|
+
@test_runner.tests = [test_suite]
|
83
|
+
@test_runner.autorun = false
|
84
|
+
@test_runner.run
|
85
|
+
assert @test_runner.responses.include?(test_response1)
|
86
|
+
assert ! @test_runner.tests.empty?
|
87
|
+
assert ! @test_runner.responses.empty?
|
88
|
+
assert_not_equal GUnit::TestRunner::DEFAULT_PATTERNS, @test_runner.patterns
|
89
|
+
@test_runner.reset
|
90
|
+
assert @test_runner.autorun?
|
91
|
+
assert @test_runner.tests.empty?
|
92
|
+
assert @test_runner.responses.empty?
|
93
|
+
assert_equal GUnit::TestRunner::DEFAULT_PATTERNS, @test_runner.patterns
|
94
|
+
end
|
95
|
+
|
24
96
|
def test_tests_set_nil_has_empty_tests
|
25
97
|
@test_runner.tests = nil
|
26
98
|
assert @test_runner.tests.empty?
|
@@ -44,7 +116,8 @@ class GUnit::TestRunnerTest < Test::Unit::TestCase
|
|
44
116
|
end
|
45
117
|
|
46
118
|
def test_io_default
|
47
|
-
|
119
|
+
@test_runner.reset
|
120
|
+
assert @test_runner.io == STDOUT
|
48
121
|
end
|
49
122
|
|
50
123
|
def test_silent_getter_setter
|
@@ -64,6 +137,22 @@ class GUnit::TestRunnerTest < Test::Unit::TestCase
|
|
64
137
|
@test_runner.run
|
65
138
|
end
|
66
139
|
|
140
|
+
def test_run_bang
|
141
|
+
@test_runner.io = mock() # fails if any methods on io are called
|
142
|
+
@test_runner.silent = true
|
143
|
+
test_response1 = GUnit::PassResponse.new
|
144
|
+
test_suite = GUnit::TestSuite.new
|
145
|
+
@test_runner.tests = [test_suite]
|
146
|
+
|
147
|
+
test_suite.expects(:run).times(0)
|
148
|
+
@test_runner.autorun = false
|
149
|
+
@test_runner.run!
|
150
|
+
|
151
|
+
test_suite.expects(:run).times(1).yields(test_response1)
|
152
|
+
@test_runner.autorun = true
|
153
|
+
@test_runner.run!
|
154
|
+
end
|
155
|
+
|
67
156
|
def test_run_not_silent
|
68
157
|
test_response1 = GUnit::PassResponse.new
|
69
158
|
fail_response_message = "Whoops. Failed."
|
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.
|
4
|
+
version: 0.3.0
|
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-01-
|
12
|
+
date: 2010-01-27 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -46,6 +46,10 @@ files:
|
|
46
46
|
- lib/gunit/test_suite.rb
|
47
47
|
- lib/gunit/to_do_response.rb
|
48
48
|
- lib/gunit/verification.rb
|
49
|
+
- samples/Rakefile
|
50
|
+
- samples/martini.rb
|
51
|
+
- samples/test/martini_test.rb
|
52
|
+
- samples/test/test_helper.rb
|
49
53
|
- test/integration/foo_test.rb
|
50
54
|
- test/test_helper.rb
|
51
55
|
- test/unit/assertions_test.rb
|