ruby on rails - rspec expect condition OR condition -
how write rspec tests defensively, in scenario @ least 1 expectation must met yet failure of others accepted? (without input changing). and
easy enough listing multiple expectations, how or
expressed?
as example, user has many posts, , user bob hacks form when submits create post form sends id of user dunc. application ignores passed dunc id, , uses bob's id bob creating post. test newly created post has bob's user_id. however, if in future code refactored returns error message instead of assuming bob's id, test wrongly fail. want test intent, not implementation.
so need test either no post created, or if 1 created, bob.
this example simple can solved testing
expect { run }.not_to change( post.where(user_id: @other_user.id), :count )
however i'm looking general solution, in more complex cases there can many conditions. how "or" achieved in rspec? (or not possible?)
i don't think possible.
i think mistaken when testing implementation, instead of intent in example.
when write test, test whether comes out matches expectation.
creating user different returning error messages.
in opinion strange say: when this, expect this, or that, or that, or happen.
in opinion should write 1 test, tests whether user created when send correct parameters, , test deals happens when user tries send illegal parameters.
Comments
Post a Comment