ruby - Rspec not working, or raise not raising? -
i'm working on learning tdd while writing small ruby programs. have following class:
class mydirectory def check(dir_name) unless file.directory?(dir_name) raise runtimeerror, "#{dir_name} not directory" end end end
and i'm trying test rspec test.
describe mydirectory "should error if doesn't exist" 1 = mydirectory.new one.check("donee").should raise_exception(runtimeerror, "donee not directory") end end
it never works, , don't understand wrong rspec output.
failures: 1) mydirectory should error if doesn't exist failure/error: one.check("donee").should raise_error(runtimeerror, "donee not directory") runtimeerror: donee not directory # ./lib/directory.rb:4:in `check' # ./spec/directory_spec.rb:9:in `block (2 levels) in <top (required)>'
i'm hoping simple i'm missing, i'm not seeing it.
if checking exception, have separate test lambda or exception bubble up.
lambda {one.check("donee")}.should raise_error(runtimeerror, "donee not directory")
edit: since people still use answer, here in rspec 3:
expect{one.check("donee")}.to raise_error(runtimeerror, "donee not directory")
the lambda no longer necessary because expect syntax takes optional block.
Comments
Post a Comment