我正在尝试使用应该和上下文来避免我的测试重复。在以下测试中,我希望得到以下输出。
"dir created"
"dir removed"
但相反我有
"dir created"
"dir removed"
."dir created"
.
Finished tests in 0.001907s, 1048.7677 tests/s, 1048.7677 assertions/s.
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
我不明白为什么第一个测试要执行两次?
这是我的测试代码:
class FileDirTest < Test::Unit::TestCase
context "FileDir:" do
setup do
@fd = FileDir.new
@myDir = "dir1"
end
context "When dir is create:" do
setup do
@fd.create_dir(@myDir)
p "dir created"
end
should "be Dir1" do
assert_equal true, Dir.exist?(@myDir)
end
context "When delete a dir" do
setup do
@fd.remove_dir(@myDir)
p "dir removed"
end
should "be removed" do
assert_equal false, Dir.exist?(@myDir)
end
end
end
结束结束