Skip to content

Commit 29d7d7f

Browse files
committed
test: add test using 'capture_output'
1 parent 3aa6eb6 commit 29d7d7f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

test/test_xml_with_output.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class TestXmlWithOutput < Test::Unit::TestCase
99

1010
setup do
1111
test_case = Class.new(Test::Unit::TestCase) do
12+
include Test::Unit::Util::Output
13+
1214
test "success" do
1315
assert_equal(1, 1)
1416
puts("out 1")
@@ -38,6 +40,15 @@ def test_pending
3840
warn("warn 3")
3941
pend("pending 1")
4042
end
43+
44+
def test_with_capture_output
45+
out, err = capture_output do
46+
puts("out 4")
47+
warn("warn 4")
48+
end
49+
assert_equal("out 4\n", out)
50+
assert_equal("warn 4\n", err)
51+
end
4152
end
4253

4354
output = StringIO.new
@@ -57,7 +68,7 @@ def test_pending
5768
test "testsuite" do
5869
testsuite_array = @doc.get_elements("/testsuites/testsuite")
5970
assert_equal(1, testsuite_array.size)
60-
check_testsuite(testsuite_array.first, "", 5, 1, 1, 2)
71+
check_testsuite(testsuite_array.first, "", 6, 1, 1, 2)
6172
end
6273

6374
test "testcase success" do
@@ -94,4 +105,11 @@ def test_pending
94105
assert_equal(1, testcase_array.size)
95106
check_testcase_skipped(testcase_array.first, "", 0, "pending 1", nil, "warn 3")
96107
end
108+
109+
test "testcase test_with_capture_output" do
110+
testcase_array = @doc.get_elements(
111+
"/testsuites/testsuite/testcase[@name='test_with_capture_output()']")
112+
assert_equal(1, testcase_array.size)
113+
check_testcase_success(testcase_array.first, "", 2)
114+
end
97115
end

0 commit comments

Comments
 (0)