【发布时间】:2011-02-09 15:05:13
【问题描述】:
我正在学习 TDD,同时编写一些小型 ruby 程序。我有以下课程:
class MyDirectory
def check(dir_name)
unless File.directory?(dir_name) then
raise RuntimeError, "#{dir_name} is not a directory"
end
end
end
我正在尝试用这个 rspec 测试来测试它。
describe MyDirectory do
it "should error if doesn't exist" do
one = MyDirectory.new
one.check("donee").should raise_exception(RuntimeError, "donee is not a directory")
end
end
它永远不会起作用,我不明白 rspec 输出有什么问题。
Failures:
1) MyDirectory should error if doesn't exist
Failure/Error: one.check("donee").should raise_error(RuntimeError, "donee is not a directory")
RuntimeError:
donee is not a directory
# ./lib/directory.rb:4:in `check'
# ./spec/directory_spec.rb:9:in `block (2 levels) in <top (required)>'
我希望这是我缺少的一些简单的东西,但我只是没有看到它。
【问题讨论】: