-
Get a monthly update on best practices for delivering successful software.
On pretty much every project I've ever been on, there have always been various roles in the system that experience different behavior. Admins can generally do everything, end users get the least functionality, and there are always a few in between that vary based on requirements. Unfortunately, all too often all possible scenarios aren't tested, or they test only positive cases for each role.
In my current Ruby on Rails project, I am checking all roles and ensuring those who should be able to do certain things are able to, and those that shouldn't are unable to. What I have found, is that usually, the Admin and one other role can usually do a set of things, and every other role can't. So, I find that I set up my tests the following manner:
['root','hr'].each do |role_name| context "logged in as #{role_name}" do setup do login_as_user(role_name) end should 'index' do get :index assert_response :success # other assertions end end end
Topics: Ruby on Rails testing role, Testing