GUnit 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/gunit.gemspec +4 -1
- data/lib/gunit.rb +1 -0
- data/lib/gunit/assertions.rb +6 -20
- data/lib/gunit/exercise.rb +3 -38
- data/lib/gunit/groundwork.rb +41 -0
- data/lib/gunit/setup.rb +3 -38
- data/lib/gunit/teardown.rb +3 -38
- data/lib/gunit/test_runner.rb +23 -18
- data/test/unit/exercise_test.rb +4 -73
- data/test/unit/groundwork_test.rb +98 -0
- data/test/unit/setup_test.rb +7 -76
- data/test/unit/teardown_test.rb +7 -76
- metadata +4 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/gunit.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{GUnit}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.2"
|
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"]
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/gunit/exception_response.rb",
|
31
31
|
"lib/gunit/exercise.rb",
|
32
32
|
"lib/gunit/fail_response.rb",
|
33
|
+
"lib/gunit/groundwork.rb",
|
33
34
|
"lib/gunit/pass_response.rb",
|
34
35
|
"lib/gunit/proc_extensions.rb",
|
35
36
|
"lib/gunit/setup.rb",
|
@@ -51,6 +52,7 @@ Gem::Specification.new do |s|
|
|
51
52
|
"test/unit/exception_response_test.rb",
|
52
53
|
"test/unit/exercise_test.rb",
|
53
54
|
"test/unit/fail_response_test.rb",
|
55
|
+
"test/unit/groundwork_test.rb",
|
54
56
|
"test/unit/pass_response_test.rb",
|
55
57
|
"test/unit/proc_extensions_test.rb",
|
56
58
|
"test/unit/setup_test.rb",
|
@@ -75,6 +77,7 @@ Gem::Specification.new do |s|
|
|
75
77
|
"test/unit/exception_response_test.rb",
|
76
78
|
"test/unit/exercise_test.rb",
|
77
79
|
"test/unit/fail_response_test.rb",
|
80
|
+
"test/unit/groundwork_test.rb",
|
78
81
|
"test/unit/pass_response_test.rb",
|
79
82
|
"test/unit/proc_extensions_test.rb",
|
80
83
|
"test/unit/setup_test.rb",
|
data/lib/gunit.rb
CHANGED
data/lib/gunit/assertions.rb
CHANGED
@@ -45,39 +45,25 @@ module GUnit
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def assert_raises(*args, &blk)
|
48
|
-
expected = args[0]
|
49
|
-
|
50
|
-
|
48
|
+
expected, message = args[0], args[1]
|
49
|
+
|
51
50
|
begin
|
52
51
|
blk.call
|
53
52
|
rescue Exception => e
|
54
53
|
actual = e
|
55
54
|
end
|
56
55
|
|
57
|
-
|
56
|
+
was_raised = if actual.nil?
|
58
57
|
false
|
59
58
|
else
|
60
59
|
case expected
|
61
60
|
when String then actual.to_s == expected
|
62
61
|
when Class then actual.is_a?(expected)
|
63
|
-
when
|
62
|
+
when nil then !actual.nil?
|
64
63
|
else; actual == expected
|
65
64
|
end
|
66
65
|
end
|
67
66
|
|
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
|
80
|
-
|
81
67
|
message ||= case
|
82
68
|
when !expected.nil? && !actual.nil?
|
83
69
|
"Expected #{expected.to_s} to be raised, but got #{actual.to_s}"
|
@@ -86,8 +72,8 @@ module GUnit
|
|
86
72
|
else
|
87
73
|
"Nothing raised"
|
88
74
|
end
|
89
|
-
|
90
|
-
assert
|
75
|
+
|
76
|
+
assert was_raised, message
|
91
77
|
end
|
92
78
|
|
93
79
|
end
|
data/lib/gunit/exercise.rb
CHANGED
@@ -1,41 +1,6 @@
|
|
1
1
|
module GUnit
|
2
|
-
|
3
|
-
class Exercise
|
4
|
-
attr_writer :message
|
5
|
-
attr_accessor :task
|
6
|
-
|
7
|
-
# Exercise.new("my message")
|
8
|
-
# Exercise.new("my message") { @foo.bar() }
|
9
|
-
# Exercise.new() { @foo.bar() }
|
10
|
-
def initialize(*args, &blk)
|
11
|
-
self.message = args[0]
|
12
|
-
self.task = blk if blk
|
13
|
-
end
|
14
|
-
|
15
|
-
def run(binding=self)
|
16
|
-
begin
|
17
|
-
if @task.is_a?(Proc)
|
18
|
-
bound_task = @task.bind(binding)
|
19
|
-
bound_task.call
|
20
|
-
end
|
21
|
-
return true
|
22
|
-
rescue GUnit::AssertionFailure => e
|
23
|
-
FailResponse.new
|
24
|
-
rescue ::StandardError => e
|
25
|
-
ExceptionResponse.new
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def message
|
30
|
-
@message || default_message
|
31
|
-
end
|
32
|
-
|
33
|
-
def default_message
|
34
|
-
"Exercise"
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
2
|
|
3
|
+
class Exercise < Groundwork
|
4
|
+
end
|
41
5
|
|
6
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module GUnit
|
2
|
+
|
3
|
+
class Groundwork
|
4
|
+
attr_writer :message
|
5
|
+
attr_accessor :task
|
6
|
+
|
7
|
+
# Groundwork.new("my message")
|
8
|
+
# Groundwork.new("my message") { @foo.bar() }
|
9
|
+
# Groundwork.new() { @foo.bar() }
|
10
|
+
def initialize(*args, &blk)
|
11
|
+
self.message = args[0]
|
12
|
+
self.task = blk if blk
|
13
|
+
end
|
14
|
+
|
15
|
+
def run(binding=self)
|
16
|
+
begin
|
17
|
+
if @task.is_a?(Proc)
|
18
|
+
bound_task = @task.bind(binding)
|
19
|
+
bound_task.call
|
20
|
+
end
|
21
|
+
return true
|
22
|
+
rescue GUnit::AssertionFailure => e
|
23
|
+
FailResponse.new
|
24
|
+
rescue ::StandardError => e
|
25
|
+
ExceptionResponse.new
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def message
|
30
|
+
@message || default_message
|
31
|
+
end
|
32
|
+
|
33
|
+
def default_message
|
34
|
+
self.class.to_s.split('::').last
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
data/lib/gunit/setup.rb
CHANGED
@@ -1,41 +1,6 @@
|
|
1
1
|
module GUnit
|
2
|
-
|
3
|
-
class Setup
|
4
|
-
attr_writer :message
|
5
|
-
attr_accessor :task
|
6
|
-
|
7
|
-
# Setup.new("my message")
|
8
|
-
# Setup.new("my message") { @foo = "bar" }
|
9
|
-
# Setup.new() { @foo = "bar" }
|
10
|
-
def initialize(*args, &blk)
|
11
|
-
self.message = args[0]
|
12
|
-
self.task = blk if blk
|
13
|
-
end
|
14
|
-
|
15
|
-
def run(binding=self)
|
16
|
-
begin
|
17
|
-
if @task.is_a?(Proc)
|
18
|
-
bound_task = @task.bind(binding)
|
19
|
-
bound_task.call
|
20
|
-
end
|
21
|
-
return true
|
22
|
-
rescue GUnit::AssertionFailure => e
|
23
|
-
FailResponse.new
|
24
|
-
rescue ::StandardError => e
|
25
|
-
ExceptionResponse.new
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def message
|
30
|
-
@message || default_message
|
31
|
-
end
|
32
|
-
|
33
|
-
def default_message
|
34
|
-
"Setup"
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
2
|
|
3
|
+
class Setup < Groundwork
|
4
|
+
end
|
41
5
|
|
6
|
+
end
|
data/lib/gunit/teardown.rb
CHANGED
@@ -1,41 +1,6 @@
|
|
1
1
|
module GUnit
|
2
|
-
|
3
|
-
class Teardown
|
4
|
-
attr_writer :message
|
5
|
-
attr_accessor :task
|
6
|
-
|
7
|
-
# Teardown.new("my message")
|
8
|
-
# Teardown.new("my message") { @foo = "bar" }
|
9
|
-
# Teardown.new() { @foo = "bar" }
|
10
|
-
def initialize(*args, &blk)
|
11
|
-
self.message = args[0]
|
12
|
-
self.task = blk if blk
|
13
|
-
end
|
14
|
-
|
15
|
-
def run(binding=self)
|
16
|
-
begin
|
17
|
-
if @task.is_a?(Proc)
|
18
|
-
bound_task = @task.bind(binding)
|
19
|
-
bound_task.call
|
20
|
-
end
|
21
|
-
return true
|
22
|
-
rescue GUnit::AssertionFailure => e
|
23
|
-
FailResponse.new
|
24
|
-
rescue ::StandardError => e
|
25
|
-
ExceptionResponse.new
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def message
|
30
|
-
@message || default_message
|
31
|
-
end
|
32
|
-
|
33
|
-
def default_message
|
34
|
-
"Teardown"
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
2
|
|
3
|
+
class Teardown < Groundwork
|
4
|
+
end
|
41
5
|
|
6
|
+
end
|
data/lib/gunit/test_runner.rb
CHANGED
@@ -70,28 +70,13 @@ module GUnit
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def run
|
73
|
-
|
73
|
+
self.print_test_cases_summary unless self.silent
|
74
74
|
self.test_cases.each do |test_case|
|
75
75
|
response = test_case.run
|
76
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
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
unless self.silent
|
85
|
-
@io.puts ""
|
86
|
-
@responses.each do |response|
|
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
|
92
|
-
end
|
93
|
-
@io.puts "#{@responses.length} verifications: #{passes.length} passed, #{fails.length} failed, #{exceptions.length} exceptions, #{to_dos.length} to-dos"
|
77
|
+
self.print_response_char(response) unless self.silent
|
94
78
|
end
|
79
|
+
self.print_responses_summary unless self.silent
|
95
80
|
end
|
96
81
|
|
97
82
|
def passes
|
@@ -112,6 +97,26 @@ module GUnit
|
|
112
97
|
|
113
98
|
protected
|
114
99
|
|
100
|
+
def print_test_cases_summary
|
101
|
+
@io.puts test_case_classes.map{|klass| klass.to_s }.join(', ')
|
102
|
+
end
|
103
|
+
|
104
|
+
def print_response_char(response)
|
105
|
+
@io.print self.class.response_color(response)
|
106
|
+
@io.print self.class.response_character(response)
|
107
|
+
@io.print DEFAULT_COLOR
|
108
|
+
end
|
109
|
+
|
110
|
+
def print_responses_summary
|
111
|
+
@io.puts ""
|
112
|
+
@responses.select{|r| !r.is_a?(GUnit::PassResponse) }.each do |response|
|
113
|
+
@io.print self.class.response_color(response)
|
114
|
+
@io.print "#{response.message} (#{response.file_name}:#{response.line_number})\n"
|
115
|
+
@io.print DEFAULT_COLOR
|
116
|
+
end
|
117
|
+
@io.puts "#{@responses.length} verifications: #{passes.length} passed, #{fails.length} failed, #{exceptions.length} exceptions, #{to_dos.length} to-dos"
|
118
|
+
end
|
119
|
+
|
115
120
|
# Flatten array of TestSuites and TestCases into a single dimensional array of TestCases
|
116
121
|
def test_cases(a=self.tests)
|
117
122
|
a.map do |test|
|
data/test/unit/exercise_test.rb
CHANGED
@@ -19,82 +19,13 @@ class GUnit::ExerciseTest < Test::Unit::TestCase
|
|
19
19
|
@exercise1 = GUnit::Exercise.new
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
assert @exercise1.is_a?(GUnit::
|
22
|
+
def test_it_is_a_groundwork
|
23
|
+
assert @exercise1.is_a?(GUnit::Groundwork)
|
24
24
|
end
|
25
25
|
|
26
26
|
def test_has_default_message
|
27
27
|
assert_not_nil @exercise1.message
|
28
|
+
assert_equal 'Exercise', @exercise1.message
|
28
29
|
end
|
29
|
-
|
30
|
-
def test_message_setter
|
31
|
-
message = "Exercise some code"
|
32
|
-
@exercise1.message = message
|
33
|
-
assert_equal message, @exercise1.message
|
34
|
-
end
|
35
|
-
|
36
|
-
# Exercise.new('some feature')
|
37
|
-
def test_initialize_with_one_arg
|
38
|
-
message = 'some feature'
|
39
|
-
@exercise2 = GUnit::Exercise.new(message)
|
40
|
-
assert @exercise2.message === message
|
41
|
-
end
|
42
|
-
|
43
|
-
# Exercise.new('some feature'){ @foo = "bar" }
|
44
|
-
def test_initialize_with_one_arg_and_block
|
45
|
-
message = 'some feature'
|
46
|
-
task = (@foo = "bar")
|
47
|
-
@exercise2 = GUnit::Exercise.new(message) { (@foo = "bar") }
|
48
|
-
assert message === @exercise2.message
|
49
|
-
assert task === @exercise2.task.call
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_run_with_task_called_returns_true
|
53
|
-
@exercise1.task = Proc.new { true }
|
54
|
-
response = @exercise1.run
|
55
|
-
assert response === true
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_run_with_task_called_returns_false
|
59
|
-
@exercise1.task = Proc.new { false }
|
60
|
-
response = @exercise1.run
|
61
|
-
assert response === true
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_run_with_task_is_false
|
65
|
-
@exercise1.task = false
|
66
|
-
response = @exercise1.run
|
67
|
-
assert response === true
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_run_with_task_is_nil
|
71
|
-
@exercise1.task = nil
|
72
|
-
response = @exercise1.run
|
73
|
-
assert response === true
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_run_with_assertion_failure_exception
|
77
|
-
@exercise1.task = lambda { raise GUnit::AssertionFailure }
|
78
|
-
response = @exercise1.run
|
79
|
-
assert response.is_a?(GUnit::TestResponse)
|
80
|
-
assert response.is_a?(GUnit::FailResponse)
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_run_with_random_exception
|
84
|
-
@exercise1.task = lambda { raise 'Boom' }
|
85
|
-
response = @exercise1.run
|
86
|
-
assert response.is_a?(GUnit::TestResponse)
|
87
|
-
assert response.is_a?(GUnit::ExceptionResponse)
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_run_with_binding
|
91
|
-
obj = Object.new
|
92
|
-
obj.instance_variable_set("@foo", "bar")
|
93
|
-
@exercise1.task = Proc.new { instance_variable_set("@foo", "zip") }
|
94
|
-
@exercise1.run
|
95
|
-
assert_equal "bar", obj.instance_variable_get("@foo")
|
96
|
-
@exercise1.run(obj)
|
97
|
-
assert_equal "zip", obj.instance_variable_get("@foo")
|
98
|
-
end
|
99
|
-
|
30
|
+
|
100
31
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
# class MyClassTest < GUnit::TestCase
|
4
|
+
# groundwork "Some fixtures should be created here"
|
5
|
+
#
|
6
|
+
# context "An instance of MyClass"
|
7
|
+
# groundwork "renamed" do
|
8
|
+
# @foo.rename("the foo")
|
9
|
+
# end
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
|
13
|
+
class GUnit::GroundworkTest < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@groundwork1 = GUnit::Groundwork.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_it_is_a_groundwork
|
20
|
+
assert @groundwork1.is_a?(GUnit::Groundwork)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_has_default_message
|
24
|
+
assert_not_nil @groundwork1.message
|
25
|
+
assert_equal 'Groundwork', @groundwork1.message
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_message_setter
|
29
|
+
message = "Groundwork some code"
|
30
|
+
@groundwork1.message = message
|
31
|
+
assert_equal message, @groundwork1.message
|
32
|
+
end
|
33
|
+
|
34
|
+
# Groundwork.new('some feature')
|
35
|
+
def test_initialize_with_one_arg
|
36
|
+
message = 'some feature'
|
37
|
+
@groundwork2 = GUnit::Groundwork.new(message)
|
38
|
+
assert @groundwork2.message === message
|
39
|
+
end
|
40
|
+
|
41
|
+
# Groundwork.new('some feature'){ @foo = "bar" }
|
42
|
+
def test_initialize_with_one_arg_and_block
|
43
|
+
message = 'some feature'
|
44
|
+
task = (@foo = "bar")
|
45
|
+
@groundwork2 = GUnit::Groundwork.new(message) { (@foo = "bar") }
|
46
|
+
assert message === @groundwork2.message
|
47
|
+
assert task === @groundwork2.task.call
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_run_with_task_called_returns_true
|
51
|
+
@groundwork1.task = Proc.new { true }
|
52
|
+
response = @groundwork1.run
|
53
|
+
assert response === true
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_run_with_task_called_returns_false
|
57
|
+
@groundwork1.task = Proc.new { false }
|
58
|
+
response = @groundwork1.run
|
59
|
+
assert response === true
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_run_with_task_is_false
|
63
|
+
@groundwork1.task = false
|
64
|
+
response = @groundwork1.run
|
65
|
+
assert response === true
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_run_with_task_is_nil
|
69
|
+
@groundwork1.task = nil
|
70
|
+
response = @groundwork1.run
|
71
|
+
assert response === true
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_run_with_assertion_failure_exception
|
75
|
+
@groundwork1.task = lambda { raise GUnit::AssertionFailure }
|
76
|
+
response = @groundwork1.run
|
77
|
+
assert response.is_a?(GUnit::TestResponse)
|
78
|
+
assert response.is_a?(GUnit::FailResponse)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_run_with_random_exception
|
82
|
+
@groundwork1.task = lambda { raise 'Boom' }
|
83
|
+
response = @groundwork1.run
|
84
|
+
assert response.is_a?(GUnit::TestResponse)
|
85
|
+
assert response.is_a?(GUnit::ExceptionResponse)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_run_with_binding
|
89
|
+
obj = Object.new
|
90
|
+
obj.instance_variable_set("@foo", "bar")
|
91
|
+
@groundwork1.task = Proc.new { instance_variable_set("@foo", "zip") }
|
92
|
+
@groundwork1.run
|
93
|
+
assert_equal "bar", obj.instance_variable_get("@foo")
|
94
|
+
@groundwork1.run(obj)
|
95
|
+
assert_equal "zip", obj.instance_variable_get("@foo")
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
data/test/unit/setup_test.rb
CHANGED
@@ -11,87 +11,18 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|
11
11
|
# end
|
12
12
|
|
13
13
|
class GUnit::SetupTest < Test::Unit::TestCase
|
14
|
-
|
14
|
+
|
15
15
|
def setup
|
16
16
|
@setup1 = GUnit::Setup.new
|
17
17
|
end
|
18
|
-
|
19
|
-
def
|
20
|
-
assert @setup1.is_a?(GUnit::
|
18
|
+
|
19
|
+
def test_it_is_a_groundwork
|
20
|
+
assert @setup1.is_a?(GUnit::Groundwork)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def test_has_default_message
|
24
24
|
assert_not_nil @setup1.message
|
25
|
+
assert_equal 'Setup', @setup1.message
|
25
26
|
end
|
26
|
-
|
27
|
-
def test_message_setter
|
28
|
-
message = "Set something up"
|
29
|
-
@setup1.message = message
|
30
|
-
assert_equal message, @setup1.message
|
31
|
-
end
|
32
|
-
|
33
|
-
# Setup.new('my fixtures')
|
34
|
-
def test_initialize_with_one_arg
|
35
|
-
message = 'my fixtures'
|
36
|
-
@setup2 = GUnit::Setup.new(message)
|
37
|
-
assert @setup2.message === message
|
38
|
-
end
|
39
|
-
|
40
|
-
# Setup.new('my fixtures'){ @foo = "bar" }
|
41
|
-
def test_initialize_with_one_arg_and_block
|
42
|
-
message = 'my fixtures'
|
43
|
-
task = (@foo = "bar")
|
44
|
-
@setup2 = GUnit::Setup.new(message) { (@foo = "bar") }
|
45
|
-
assert message === @setup2.message
|
46
|
-
assert task === @setup2.task.call
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_run_with_task_called_returns_true
|
50
|
-
@setup1.task = Proc.new { true }
|
51
|
-
response = @setup1.run
|
52
|
-
assert response === true
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_run_with_task_called_returns_false
|
56
|
-
@setup1.task = Proc.new { false }
|
57
|
-
response = @setup1.run
|
58
|
-
assert response === true
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_run_with_task_is_false
|
62
|
-
@setup1.task = false
|
63
|
-
response = @setup1.run
|
64
|
-
assert response === true
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_run_with_task_is_nil
|
68
|
-
@setup1.task = nil
|
69
|
-
response = @setup1.run
|
70
|
-
assert response === true
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_run_with_assertion_failure_exception
|
74
|
-
@setup1.task = lambda { raise GUnit::AssertionFailure }
|
75
|
-
response = @setup1.run
|
76
|
-
assert response.is_a?(GUnit::TestResponse)
|
77
|
-
assert response.is_a?(GUnit::FailResponse)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_run_with_random_exception
|
81
|
-
@setup1.task = lambda { raise 'Boom' }
|
82
|
-
response = @setup1.run
|
83
|
-
assert response.is_a?(GUnit::TestResponse)
|
84
|
-
assert response.is_a?(GUnit::ExceptionResponse)
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_run_with_binding
|
88
|
-
obj = Object.new
|
89
|
-
obj.instance_variable_set("@foo", "bar")
|
90
|
-
@setup1.task = Proc.new { instance_variable_set("@foo", "zip") }
|
91
|
-
@setup1.run
|
92
|
-
assert_equal "bar", obj.instance_variable_get("@foo")
|
93
|
-
@setup1.run(obj)
|
94
|
-
assert_equal "zip", obj.instance_variable_get("@foo")
|
95
|
-
end
|
96
|
-
|
27
|
+
|
97
28
|
end
|
data/test/unit/teardown_test.rb
CHANGED
@@ -11,87 +11,18 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
|
11
11
|
# end
|
12
12
|
|
13
13
|
class GUnit::TeardownTest < Test::Unit::TestCase
|
14
|
-
|
14
|
+
|
15
15
|
def setup
|
16
16
|
@teardown1 = GUnit::Teardown.new
|
17
17
|
end
|
18
|
-
|
19
|
-
def
|
20
|
-
assert @teardown1.is_a?(GUnit::
|
18
|
+
|
19
|
+
def test_it_is_a_groundwork
|
20
|
+
assert @teardown1.is_a?(GUnit::Groundwork)
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def test_has_default_message
|
24
24
|
assert_not_nil @teardown1.message
|
25
|
+
assert_equal 'Teardown', @teardown1.message
|
25
26
|
end
|
26
|
-
|
27
|
-
def test_message_setter
|
28
|
-
message = "Set something up"
|
29
|
-
@teardown1.message = message
|
30
|
-
assert_equal message, @teardown1.message
|
31
|
-
end
|
32
|
-
|
33
|
-
# Teardown.new('my fixtures')
|
34
|
-
def test_initialize_with_one_arg
|
35
|
-
message = 'my fixtures'
|
36
|
-
@teardown2 = GUnit::Teardown.new(message)
|
37
|
-
assert @teardown2.message === message
|
38
|
-
end
|
39
|
-
|
40
|
-
# Teardown.new('my fixtures'){ @foo = "bar" }
|
41
|
-
def test_initialize_with_one_arg_and_block
|
42
|
-
message = 'my fixtures'
|
43
|
-
task = (@foo = "bar")
|
44
|
-
@teardown2 = GUnit::Teardown.new(message) { (@foo = "bar") }
|
45
|
-
assert message === @teardown2.message
|
46
|
-
assert task === @teardown2.task.call
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_run_with_task_called_returns_true
|
50
|
-
@teardown1.task = Proc.new { true }
|
51
|
-
response = @teardown1.run
|
52
|
-
assert response === true
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_run_with_task_called_returns_false
|
56
|
-
@teardown1.task = Proc.new { false }
|
57
|
-
response = @teardown1.run
|
58
|
-
assert response === true
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_run_with_task_is_false
|
62
|
-
@teardown1.task = false
|
63
|
-
response = @teardown1.run
|
64
|
-
assert response === true
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_run_with_task_is_nil
|
68
|
-
@teardown1.task = nil
|
69
|
-
response = @teardown1.run
|
70
|
-
assert response === true
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_run_with_assertion_failure_exception
|
74
|
-
@teardown1.task = lambda { raise GUnit::AssertionFailure }
|
75
|
-
response = @teardown1.run
|
76
|
-
assert response.is_a?(GUnit::TestResponse)
|
77
|
-
assert response.is_a?(GUnit::FailResponse)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_run_with_random_exception
|
81
|
-
@teardown1.task = lambda { raise 'Boom' }
|
82
|
-
response = @teardown1.run
|
83
|
-
assert response.is_a?(GUnit::TestResponse)
|
84
|
-
assert response.is_a?(GUnit::ExceptionResponse)
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_run_with_binding
|
88
|
-
obj = Object.new
|
89
|
-
obj.instance_variable_set("@foo", "bar")
|
90
|
-
@teardown1.task = Proc.new { instance_variable_set("@foo", "zip") }
|
91
|
-
@teardown1.run
|
92
|
-
assert_equal "bar", obj.instance_variable_get("@foo")
|
93
|
-
@teardown1.run(obj)
|
94
|
-
assert_equal "zip", obj.instance_variable_get("@foo")
|
95
|
-
end
|
96
|
-
|
27
|
+
|
97
28
|
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.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Sterndale
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/gunit/exception_response.rb
|
37
37
|
- lib/gunit/exercise.rb
|
38
38
|
- lib/gunit/fail_response.rb
|
39
|
+
- lib/gunit/groundwork.rb
|
39
40
|
- lib/gunit/pass_response.rb
|
40
41
|
- lib/gunit/proc_extensions.rb
|
41
42
|
- lib/gunit/setup.rb
|
@@ -57,6 +58,7 @@ files:
|
|
57
58
|
- test/unit/exception_response_test.rb
|
58
59
|
- test/unit/exercise_test.rb
|
59
60
|
- test/unit/fail_response_test.rb
|
61
|
+
- test/unit/groundwork_test.rb
|
60
62
|
- test/unit/pass_response_test.rb
|
61
63
|
- test/unit/proc_extensions_test.rb
|
62
64
|
- test/unit/setup_test.rb
|
@@ -103,6 +105,7 @@ test_files:
|
|
103
105
|
- test/unit/exception_response_test.rb
|
104
106
|
- test/unit/exercise_test.rb
|
105
107
|
- test/unit/fail_response_test.rb
|
108
|
+
- test/unit/groundwork_test.rb
|
106
109
|
- test/unit/pass_response_test.rb
|
107
110
|
- test/unit/proc_extensions_test.rb
|
108
111
|
- test/unit/setup_test.rb
|