assert 2.3.1 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/assert/assertions.rb +74 -66
- data/lib/assert/context.rb +15 -16
- data/lib/assert/suite.rb +2 -2
- data/lib/assert/test.rb +8 -0
- data/lib/assert/version.rb +1 -1
- data/test/unit/assertions/assert_instance_of_tests.rb +1 -1
- data/test/unit/context_tests.rb +2 -8
- data/test/unit/test_tests.rb +106 -25
- metadata +4 -4
data/lib/assert/assertions.rb
CHANGED
@@ -1,154 +1,162 @@
|
|
1
1
|
module Assert
|
2
2
|
module Assertions
|
3
3
|
|
4
|
-
def assert_block(desc=nil)
|
5
|
-
|
6
|
-
assert(yield, desc, msg)
|
4
|
+
def assert_block(desc = nil)
|
5
|
+
assert(yield, desc){ "Expected block to return a true value." }
|
7
6
|
end
|
8
7
|
|
9
|
-
def assert_not_block(desc=nil)
|
10
|
-
|
11
|
-
assert(!yield, desc, msg)
|
8
|
+
def assert_not_block(desc = nil)
|
9
|
+
assert(!yield, desc){ "Expected block to return a false value." }
|
12
10
|
end
|
13
11
|
alias_method :refute_block, :assert_not_block
|
14
12
|
|
15
|
-
def assert_empty(collection, desc=nil)
|
16
|
-
|
17
|
-
|
13
|
+
def assert_empty(collection, desc = nil)
|
14
|
+
assert(collection.empty?, desc) do
|
15
|
+
"Expected #{collection.inspect} to be empty."
|
16
|
+
end
|
18
17
|
end
|
19
18
|
|
20
|
-
def assert_not_empty(collection, desc=nil)
|
21
|
-
|
22
|
-
|
19
|
+
def assert_not_empty(collection, desc = nil)
|
20
|
+
assert(!collection.empty?, desc) do
|
21
|
+
"Expected #{collection.inspect} to not be empty."
|
22
|
+
end
|
23
23
|
end
|
24
24
|
alias_method :refute_empty, :assert_not_empty
|
25
25
|
|
26
|
-
def assert_equal(expected, actual, desc=nil)
|
27
|
-
|
28
|
-
|
26
|
+
def assert_equal(expected, actual, desc = nil)
|
27
|
+
assert(actual == expected, desc) do
|
28
|
+
"Expected #{expected.inspect}, not #{actual.inspect}."
|
29
|
+
end
|
29
30
|
end
|
30
31
|
|
31
|
-
def assert_not_equal(expected, actual, desc=nil)
|
32
|
-
|
33
|
-
|
32
|
+
def assert_not_equal(expected, actual, desc = nil)
|
33
|
+
assert(actual != expected, desc) do
|
34
|
+
"#{actual.inspect} not expected to equal #{expected.inspect}."
|
35
|
+
end
|
34
36
|
end
|
35
37
|
alias_method :refute_equal, :assert_not_equal
|
36
38
|
|
37
|
-
def assert_file_exists(file_path, desc=nil)
|
38
|
-
|
39
|
-
|
39
|
+
def assert_file_exists(file_path, desc = nil)
|
40
|
+
assert(File.exists?(File.expand_path(file_path)), desc) do
|
41
|
+
"Expected #{file_path.inspect} to exist."
|
42
|
+
end
|
40
43
|
end
|
41
44
|
|
42
|
-
def assert_not_file_exists(file_path, desc=nil)
|
43
|
-
|
44
|
-
|
45
|
+
def assert_not_file_exists(file_path, desc = nil)
|
46
|
+
assert(!File.exists?(File.expand_path(file_path)), desc) do
|
47
|
+
"Expected #{file_path.inspect} to not exist."
|
48
|
+
end
|
45
49
|
end
|
46
50
|
alias_method :refute_file_exists, :assert_not_file_exists
|
47
51
|
|
48
|
-
def assert_includes(object, collection, desc=nil)
|
49
|
-
|
50
|
-
|
52
|
+
def assert_includes(object, collection, desc = nil)
|
53
|
+
assert(collection.include?(object), desc) do
|
54
|
+
"Expected #{collection.inspect} to include #{object.inspect}."
|
55
|
+
end
|
51
56
|
end
|
52
57
|
alias_method :assert_included, :assert_includes
|
53
58
|
|
54
|
-
def assert_not_includes(object, collection, desc=nil)
|
55
|
-
|
56
|
-
|
59
|
+
def assert_not_includes(object, collection, desc = nil)
|
60
|
+
assert(!collection.include?(object), desc) do
|
61
|
+
"Expected #{collection.inspect} to not include #{object.inspect}."
|
62
|
+
end
|
57
63
|
end
|
58
64
|
alias_method :assert_not_included, :assert_not_includes
|
59
65
|
alias_method :refute_includes, :assert_not_includes
|
60
66
|
alias_method :refute_included, :assert_not_includes
|
61
67
|
|
62
|
-
def assert_instance_of(klass, instance, desc=nil)
|
63
|
-
|
64
|
-
|
65
|
-
|
68
|
+
def assert_instance_of(klass, instance, desc = nil)
|
69
|
+
assert(instance.instance_of?(klass), desc) do
|
70
|
+
"Expected #{instance.inspect} (#{instance.class}) to be an instance of #{klass}."
|
71
|
+
end
|
66
72
|
end
|
67
73
|
|
68
|
-
def assert_not_instance_of(klass, instance, desc=nil)
|
69
|
-
|
70
|
-
|
74
|
+
def assert_not_instance_of(klass, instance, desc = nil)
|
75
|
+
assert(!instance.instance_of?(klass), desc) do
|
76
|
+
"#{instance.inspect} (#{instance.class}) not expected to be an instance of #{klass}."
|
77
|
+
end
|
71
78
|
end
|
72
79
|
alias_method :refute_instance_of, :assert_not_instance_of
|
73
80
|
|
74
81
|
def assert_kind_of(klass, instance, desc=nil)
|
75
|
-
|
76
|
-
|
77
|
-
|
82
|
+
assert(instance.kind_of?(klass), desc) do
|
83
|
+
"Expected #{instance.inspect} (#{instance.class}) to be a kind of #{klass}."
|
84
|
+
end
|
78
85
|
end
|
79
86
|
|
80
87
|
def assert_not_kind_of(klass, instance, desc=nil)
|
81
|
-
|
82
|
-
|
88
|
+
assert(!instance.kind_of?(klass), desc) do
|
89
|
+
"#{instance.inspect} not expected to be a kind of #{klass}."
|
90
|
+
end
|
83
91
|
end
|
84
92
|
alias_method :refute_kind_of, :assert_not_kind_of
|
85
93
|
|
86
94
|
def assert_match(expected, actual, desc=nil)
|
87
|
-
|
88
|
-
|
89
|
-
|
95
|
+
exp = String === expected && String === actual ? /#{Regexp.escape(expected)}/ : expected
|
96
|
+
assert(actual =~ exp, desc) do
|
97
|
+
"Expected #{actual.inspect} to match #{expected.inspect}."
|
98
|
+
end
|
90
99
|
end
|
91
100
|
|
92
101
|
def assert_not_match(expected, actual, desc=nil)
|
93
|
-
|
94
|
-
|
95
|
-
|
102
|
+
exp = String === expected && String === actual ? /#{Regexp.escape(expected)}/ : expected
|
103
|
+
assert(actual !~ exp, desc) do
|
104
|
+
"#{actual.inspect} not expected to match #{expected.inspect}."
|
105
|
+
end
|
96
106
|
end
|
97
107
|
alias_method :refute_match, :assert_not_match
|
98
108
|
alias_method :assert_no_match, :assert_not_match
|
99
109
|
|
100
110
|
def assert_nil(object, desc=nil)
|
101
|
-
|
102
|
-
assert(object.nil?, desc, msg)
|
111
|
+
assert(object.nil?, desc){ "Expected nil, not #{object.inspect}." }
|
103
112
|
end
|
104
113
|
|
105
114
|
def assert_not_nil(object, desc=nil)
|
106
|
-
|
107
|
-
assert(!object.nil?, desc, msg)
|
115
|
+
assert(!object.nil?, desc){ "Expected #{object.inspect} to not be nil." }
|
108
116
|
end
|
109
117
|
alias_method :refute_nil, :assert_not_nil
|
110
118
|
|
111
119
|
def assert_raises(*exceptions, &block)
|
112
120
|
desc = exceptions.last.kind_of?(String) ? exceptions.pop : nil
|
113
121
|
err = RaisedException.new(exceptions, &block)
|
114
|
-
assert(err.raised?, desc
|
122
|
+
assert(err.raised?, desc){ err.msg }
|
115
123
|
end
|
116
124
|
alias_method :assert_raise, :assert_raises
|
117
125
|
|
118
126
|
def assert_nothing_raised(*exceptions, &block)
|
119
127
|
desc = exceptions.last.kind_of?(String) ? exceptions.pop : nil
|
120
128
|
err = NoRaisedException.new(exceptions, &block)
|
121
|
-
assert(!err.raised?, desc
|
129
|
+
assert(!err.raised?, desc){ err.msg }
|
122
130
|
end
|
123
131
|
alias_method :assert_not_raises, :assert_nothing_raised
|
124
132
|
alias_method :assert_not_raise, :assert_nothing_raised
|
125
133
|
|
126
134
|
def assert_respond_to(method, object, desc=nil)
|
127
|
-
|
128
|
-
|
129
|
-
|
135
|
+
assert(object.respond_to?(method), desc) do
|
136
|
+
"Expected #{object.inspect} (#{object.class}) to respond to `#{method}`."
|
137
|
+
end
|
130
138
|
end
|
131
139
|
alias_method :assert_responds_to, :assert_respond_to
|
132
140
|
|
133
141
|
def assert_not_respond_to(method, object, desc=nil)
|
134
|
-
|
135
|
-
|
136
|
-
|
142
|
+
assert(!object.respond_to?(method), desc) do
|
143
|
+
"#{object.inspect} (#{object.class}) not expected to respond to `#{method}`."
|
144
|
+
end
|
137
145
|
end
|
138
146
|
alias_method :assert_not_responds_to, :assert_not_respond_to
|
139
147
|
alias_method :refute_respond_to, :assert_not_respond_to
|
140
148
|
alias_method :refute_responds_to, :assert_not_respond_to
|
141
149
|
|
142
150
|
def assert_same(expected, actual, desc=nil)
|
143
|
-
|
144
|
-
|
145
|
-
|
151
|
+
assert(actual.equal?(expected), desc) do
|
152
|
+
"Expected #{actual} (#{actual.object_id}) to be the same as #{expected} (#{expected.object_id})."
|
153
|
+
end
|
146
154
|
end
|
147
155
|
|
148
156
|
def assert_not_same(expected, actual, desc=nil)
|
149
|
-
|
150
|
-
|
151
|
-
|
157
|
+
assert(!actual.equal?(expected), desc) do
|
158
|
+
"#{actual} (#{actual.object_id}) not expected to be the same as #{expected} (#{expected.object_id})."
|
159
|
+
end
|
152
160
|
end
|
153
161
|
alias_method :refute_same, :assert_not_same
|
154
162
|
|
data/lib/assert/context.rb
CHANGED
@@ -174,17 +174,19 @@ module Assert
|
|
174
174
|
# check if the assertion is a truthy value, if so create a new pass result, otherwise
|
175
175
|
# create a new fail result with the desc and what failed msg.
|
176
176
|
# all other assertion helpers use this one in the end
|
177
|
-
def assert(assertion, fail_desc=
|
178
|
-
|
179
|
-
|
180
|
-
|
177
|
+
def assert(assertion, fail_desc = nil)
|
178
|
+
if assertion
|
179
|
+
pass
|
180
|
+
else
|
181
|
+
what_failed_msg = block_given? ? yield : "Failed assert: assertion was <#{assertion.inspect}>."
|
182
|
+
fail(fail_message(fail_desc, what_failed_msg))
|
183
|
+
end
|
181
184
|
end
|
182
185
|
|
183
186
|
# the opposite of assert, check if the assertion is a false value, if so create a new pass
|
184
187
|
# result, otherwise create a new fail result with the desc and it's what failed msg
|
185
|
-
def assert_not(assertion, fail_desc=nil)
|
186
|
-
|
187
|
-
assert(!assertion, fail_desc, what_failed_msg)
|
188
|
+
def assert_not(assertion, fail_desc = nil)
|
189
|
+
assert(!assertion, fail_desc){ "Failed assert_not: assertion was <#{assertion.inspect}>." }
|
188
190
|
end
|
189
191
|
alias_method :refute, :assert_not
|
190
192
|
|
@@ -206,13 +208,12 @@ module Assert
|
|
206
208
|
|
207
209
|
# adds a Fail result to the end of the test's results
|
208
210
|
# break test execution if Assert.config.halt_on_fail
|
209
|
-
def fail(
|
210
|
-
message = (fail_message(fail_msg) { }).call
|
211
|
+
def fail(message = nil)
|
211
212
|
if Assert.config.halt_on_fail
|
212
|
-
raise Result::TestFailure, message
|
213
|
+
raise Result::TestFailure, message || ''
|
213
214
|
else
|
214
215
|
capture_result do |test, backtrace|
|
215
|
-
Assert::Result::Fail.new(test, message, backtrace)
|
216
|
+
Assert::Result::Fail.new(test, message || '', backtrace)
|
216
217
|
end
|
217
218
|
end
|
218
219
|
end
|
@@ -220,7 +221,7 @@ module Assert
|
|
220
221
|
|
221
222
|
# adds a Skip result to the end of the test's results and breaks test execution
|
222
223
|
def skip(skip_msg=nil)
|
223
|
-
raise(Result::TestSkipped, skip_msg ||
|
224
|
+
raise(Result::TestSkipped, skip_msg || '')
|
224
225
|
end
|
225
226
|
|
226
227
|
# alter the backtraces of fail results generated in the given block
|
@@ -250,10 +251,8 @@ module Assert
|
|
250
251
|
protected
|
251
252
|
|
252
253
|
# Returns a Proc that will output a custom message along with the default fail message.
|
253
|
-
def fail_message(fail_desc=nil,
|
254
|
-
|
255
|
-
[ fail_desc, what_failed.call ].compact.join("\n")
|
256
|
-
end
|
254
|
+
def fail_message(fail_desc = nil, what_failed_msg = nil)
|
255
|
+
[ fail_desc, what_failed_msg ].compact.join("\n")
|
257
256
|
end
|
258
257
|
|
259
258
|
private
|
data/lib/assert/suite.rb
CHANGED
@@ -77,7 +77,7 @@ module Assert
|
|
77
77
|
if block_given?
|
78
78
|
self.setups << block
|
79
79
|
else
|
80
|
-
self.setups.each{|setup| setup.call}
|
80
|
+
self.setups.each{ |setup| setup.call }
|
81
81
|
end
|
82
82
|
end
|
83
83
|
alias_method :startup, :setup
|
@@ -86,7 +86,7 @@ module Assert
|
|
86
86
|
if block_given?
|
87
87
|
self.teardowns << block
|
88
88
|
else
|
89
|
-
self.teardowns.reverse.each{|teardown| teardown.call}
|
89
|
+
self.teardowns.reverse.each{ |teardown| teardown.call }
|
90
90
|
end
|
91
91
|
end
|
92
92
|
alias_method :shutdown, :teardown
|
data/lib/assert/test.rb
CHANGED
@@ -35,11 +35,19 @@ module Assert
|
|
35
35
|
@results << Result::Fail.new(self, err)
|
36
36
|
rescue Result::TestSkipped => err
|
37
37
|
@results << Result::Skip.new(self, err)
|
38
|
+
rescue SignalException => err
|
39
|
+
raise(err)
|
38
40
|
rescue Exception => err
|
39
41
|
@results << Result::Error.new(self, err)
|
40
42
|
ensure
|
41
43
|
begin
|
42
44
|
run_test_teardown(run_scope)
|
45
|
+
rescue Result::TestFailure => err
|
46
|
+
@results << Result::Fail.new(self, err)
|
47
|
+
rescue Result::TestSkipped => err
|
48
|
+
@results << Result::Skip.new(self, err)
|
49
|
+
rescue SignalException => err
|
50
|
+
raise(err)
|
43
51
|
rescue Exception => teardown_err
|
44
52
|
@results << Result::Error.new(self, teardown_err)
|
45
53
|
end
|
data/lib/assert/version.rb
CHANGED
@@ -50,7 +50,7 @@ module Assert::Assertions
|
|
50
50
|
end
|
51
51
|
|
52
52
|
should "have a fail message with custom and generic explanations" do
|
53
|
-
exp = "#{@args[2]}\n#{@args[1].inspect} not expected to"\
|
53
|
+
exp = "#{@args[2]}\n#{@args[1].inspect} (#{@args[1].class}) not expected to"\
|
54
54
|
" be an instance of #{@args[0]}."
|
55
55
|
assert_equal exp, subject.fail_results.first.message
|
56
56
|
end
|
data/test/unit/context_tests.rb
CHANGED
@@ -108,12 +108,6 @@ class Assert::Context
|
|
108
108
|
assert_equal fail_msg, result.message
|
109
109
|
end
|
110
110
|
|
111
|
-
should "set any given result message evaluated from a proc" do
|
112
|
-
fail_msg = ::Proc.new{ "Still didn't work" }
|
113
|
-
result = @context.fail(fail_msg)
|
114
|
-
assert_equal fail_msg.call, result.message
|
115
|
-
end
|
116
|
-
|
117
111
|
end
|
118
112
|
|
119
113
|
class HaltOnFailTests < FailTests
|
@@ -151,13 +145,13 @@ class Assert::Context
|
|
151
145
|
end
|
152
146
|
|
153
147
|
should "return a pass result given a `true` assertion" do
|
154
|
-
result = subject.assert(true, @fail_desc
|
148
|
+
result = subject.assert(true, @fail_desc){ @what_failed }
|
155
149
|
assert_kind_of Assert::Result::Pass, result
|
156
150
|
assert_nil result.message
|
157
151
|
end
|
158
152
|
|
159
153
|
should "return a fail result given a `false` assertion" do
|
160
|
-
result = subject.assert(false, @fail_desc
|
154
|
+
result = subject.assert(false, @fail_desc){ @what_failed }
|
161
155
|
assert_kind_of Assert::Result::Fail, result
|
162
156
|
assert_equal [@fail_desc, @what_failed].join("\n"), result.message
|
163
157
|
end
|
data/test/unit/test_tests.rb
CHANGED
@@ -7,7 +7,7 @@ class Assert::Test
|
|
7
7
|
desc "a test obj"
|
8
8
|
setup do
|
9
9
|
@test_code = lambda{ assert(true) }
|
10
|
-
@context_class = Factory.context_class
|
10
|
+
@context_class = Factory.context_class{ desc "context class" }
|
11
11
|
@context_info = Factory.context_info(@context_class)
|
12
12
|
@test = Factory.test("should do something amazing", @context_info, @test_code)
|
13
13
|
end
|
@@ -51,9 +51,16 @@ class Assert::Test
|
|
51
51
|
ignore("something")
|
52
52
|
assert(true)
|
53
53
|
assert(false)
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
end
|
55
|
+
@test.context_class.setup do
|
56
|
+
ignore("something")
|
57
|
+
assert(true)
|
58
|
+
assert(false)
|
59
|
+
end
|
60
|
+
@test.context_class.teardown do
|
61
|
+
ignore("something")
|
62
|
+
assert(true)
|
63
|
+
assert(false)
|
57
64
|
end
|
58
65
|
@test.run
|
59
66
|
end
|
@@ -61,7 +68,7 @@ class Assert::Test
|
|
61
68
|
|
62
69
|
should "know its pass results" do
|
63
70
|
assert_kind_of Array, subject.pass_results
|
64
|
-
assert_equal
|
71
|
+
assert_equal 3, subject.pass_results.size
|
65
72
|
subject.pass_results.each do |result|
|
66
73
|
assert_kind_of Assert::Result::Pass, result
|
67
74
|
end
|
@@ -70,7 +77,7 @@ class Assert::Test
|
|
70
77
|
|
71
78
|
should "know its fail results" do
|
72
79
|
assert_kind_of Array, subject.fail_results
|
73
|
-
assert_equal
|
80
|
+
assert_equal 3, subject.fail_results.size
|
74
81
|
subject.fail_results.each do |result|
|
75
82
|
assert_kind_of Assert::Result::Fail, result
|
76
83
|
end
|
@@ -79,7 +86,7 @@ class Assert::Test
|
|
79
86
|
|
80
87
|
should "know its ignore results" do
|
81
88
|
assert_kind_of Array, subject.ignore_results
|
82
|
-
assert_equal
|
89
|
+
assert_equal 3, subject.ignore_results.size
|
83
90
|
subject.ignore_results.each do |result|
|
84
91
|
assert_kind_of Assert::Result::Ignore, result
|
85
92
|
end
|
@@ -87,25 +94,48 @@ class Assert::Test
|
|
87
94
|
end
|
88
95
|
|
89
96
|
should "know the total number of results" do
|
90
|
-
assert_equal(
|
97
|
+
assert_equal(9, subject.result_count)
|
91
98
|
end
|
92
99
|
|
93
100
|
end
|
94
101
|
|
95
102
|
class SkipHandlingTests < BasicTests
|
96
103
|
setup do
|
97
|
-
@test = Factory.test("skip test", @context_info)
|
104
|
+
@test = Factory.test("skip test", @context_info){ skip }
|
98
105
|
@test.run
|
99
106
|
end
|
100
107
|
subject{ @test }
|
101
108
|
|
102
|
-
should "
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
109
|
+
should "capture skip results" do
|
110
|
+
assert_skipped(subject)
|
111
|
+
end
|
112
|
+
|
113
|
+
should "capture skips in the context setup" do
|
114
|
+
test = Factory.test("setup skip test", @context_info){ }
|
115
|
+
test.context_class.setup{ skip }
|
116
|
+
test.run
|
117
|
+
|
118
|
+
assert_skipped(test)
|
119
|
+
end
|
120
|
+
|
121
|
+
should "capture skips in the context teardown" do
|
122
|
+
test = Factory.test("teardown skip test", @context_info){ }
|
123
|
+
test.context_class.teardown{ skip }
|
124
|
+
test.run
|
125
|
+
|
126
|
+
assert_skipped(test)
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
def assert_skipped(test)
|
132
|
+
with_backtrace(caller) do
|
133
|
+
assert_equal 1, test.skip_results.size, 'too many/few skip results'
|
134
|
+
test.skip_results.each do |result|
|
135
|
+
assert_kind_of Assert::Result::Skip, result, 'result is not a skip result'
|
136
|
+
end
|
137
|
+
assert_equal test.skip_results.size, test.result_count(:skip), 'skip result not counted'
|
107
138
|
end
|
108
|
-
assert_equal subject.skip_results.size, subject.result_count(:skip)
|
109
139
|
end
|
110
140
|
|
111
141
|
end
|
@@ -119,13 +149,64 @@ class Assert::Test
|
|
119
149
|
end
|
120
150
|
subject{ @test }
|
121
151
|
|
122
|
-
should "
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
152
|
+
should "capture error results" do
|
153
|
+
assert_errored(subject)
|
154
|
+
end
|
155
|
+
|
156
|
+
should "capture errors in the context setup" do
|
157
|
+
test = Factory.test("setup error test", @context_info){ }
|
158
|
+
test.context_class.setup{ raise 'an error' }
|
159
|
+
test.run
|
160
|
+
|
161
|
+
assert_errored(test)
|
162
|
+
end
|
163
|
+
|
164
|
+
should "capture errors in the context teardown" do
|
165
|
+
test = Factory.test("teardown error test", @context_info){ }
|
166
|
+
test.context_class.teardown{ raise 'an error' }
|
167
|
+
test.run
|
168
|
+
|
169
|
+
assert_errored(test)
|
170
|
+
end
|
171
|
+
|
172
|
+
private
|
173
|
+
|
174
|
+
def assert_errored(test)
|
175
|
+
with_backtrace(caller) do
|
176
|
+
assert_equal 1, subject.error_results.size, 'too many/few error results'
|
177
|
+
test.error_results.each do |result|
|
178
|
+
assert_kind_of Assert::Result::Error, result, 'result is not an error result'
|
179
|
+
end
|
180
|
+
assert_equal test.error_results.size, test.result_count(:error), 'error result not counted'
|
127
181
|
end
|
128
|
-
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
class SignalExceptionHandlingTests < BasicTests
|
187
|
+
setup do
|
188
|
+
@test = Factory.test("signal test", @context_info) do
|
189
|
+
raise SignalException, "USR1"
|
190
|
+
end
|
191
|
+
end
|
192
|
+
subject{ @test }
|
193
|
+
|
194
|
+
should "raise any signal exceptions and not capture as an error" do
|
195
|
+
assert_raises(SignalException){ subject.run }
|
196
|
+
end
|
197
|
+
|
198
|
+
should "raises signal exceptions in the context setup" do
|
199
|
+
test = Factory.test("setup signal test", @context_info){ }
|
200
|
+
test.context_class.setup{ raise SignalException, 'INT' }
|
201
|
+
|
202
|
+
assert_raises(SignalException){ test.run }
|
203
|
+
end
|
204
|
+
|
205
|
+
should "raises signal exceptions in the context teardown" do
|
206
|
+
test = Factory.test("teardown signal test", @context_info){ }
|
207
|
+
test.context_class.teardown{ raise SignalException, "TERM" }
|
208
|
+
|
209
|
+
assert_raises(SignalException){ test.run }
|
129
210
|
end
|
130
211
|
|
131
212
|
end
|
@@ -157,10 +238,10 @@ class Assert::Test
|
|
157
238
|
class CaptureOutTests < BasicTests
|
158
239
|
desc "when capturing std out"
|
159
240
|
setup do
|
160
|
-
@test = Factory.test("stdout")
|
241
|
+
@test = Factory.test("stdout") do
|
161
242
|
puts "std out from the test"
|
162
243
|
assert true
|
163
|
-
|
244
|
+
end
|
164
245
|
@orig_capture = Assert.config.capture_output
|
165
246
|
Assert.config.capture_output true
|
166
247
|
end
|
@@ -182,8 +263,8 @@ class Assert::Test
|
|
182
263
|
puts "std out from the test"
|
183
264
|
assert a_method_an_assert_calls
|
184
265
|
end
|
185
|
-
@test.context_class.setup
|
186
|
-
@test.context_class.teardown
|
266
|
+
@test.context_class.setup{ puts "std out from the setup" }
|
267
|
+
@test.context_class.teardown{ puts "std out from the teardown" }
|
187
268
|
@test.context_class.send(:define_method, "a_method_an_assert_calls") do
|
188
269
|
puts "std out from a method an assert called"
|
189
270
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 2.3.
|
9
|
+
- 2
|
10
|
+
version: 2.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-10-
|
19
|
+
date: 2013-10-29 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: ansi
|