1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/coverage/test_coverage.rb

44 lines
922 B
Ruby
Raw Normal View History

require "test/unit"
require "coverage"
require "tmpdir"
class TestCoverage < Test::Unit::TestCase
def test_result_without_start
assert_raise(RuntimeError) {Coverage.result}
end
def test_result_with_nothing
Coverage.start
result = Coverage.result
assert_kind_of(Hash, result)
result.each do |key, val|
assert_kind_of(String, key)
assert_kind_of(Array, val)
end
end
def test_restarting_coverage
loaded_features = $".dup
Dir.mktmpdir {|tmp|
Dir.chdir(tmp) {
File.open("test.rb", "w") do |f|
f.puts <<-EOS
def coverage_test_method
:ok
end
EOS
end
Coverage.start
require tmp + '/test.rb'
Coverage.result
Coverage.start
coverage_test_method
assert_equal 1, Coverage.result.size
}
}
ensure
$".replace loaded_features
end
end