ruby - Writing a negative test by using exception handling -
let have login
method that's working swimmingly. it's used in quite number of places , saves plenty of lines of retyped code. intents , purposes, not make sense make method shorter.
is proper write negative test using exception handling? example, if wanted ensure disabled user not able log system, awkward write like:
begin login(username, password) fail rescue exception page.should have_text('sorry, account disabled!') end
if login succeeds, test should fail. , if reach exception, find our error message , test passes.
i'm wondering if "clever" , may cause confusion. what's best way of handling negative test case here?
you testing expected behavior there no rescuing within specs. in case, want disable account in before
caluse , ensure exception raised when attempt perform operation (login, etc.).
testing generic exception
bad idea - want specific expected exception different issue cause specs pass.
the code like
expect { login(username, password) }.to raise_error loginexception
Comments
Post a Comment