Reputation: 2689
I'm trying to use Shoulda and context to avoid duplication on my tests. In the following test I would like to expect the following output.
"dir created"
"dir removed"
but instead I've got
"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
I don't understand why the first test is executed twice?
This is my test code:
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
end end
Upvotes: 1
Views: 84
Reputation: 3508
Like in any testing framework the setup is run before every test. Since one context is nested in another you see "dir created" twice.
Upvotes: 2