Creating some controller tests using RSpec, I find myself repeating a few test cases for every possible user role.
for instance
describe "GET 'index'" do context "for admin user" do login_user("admin") it "has the right title" do response.should have_selector("title", :content => "the title") end end context "for regular user" do login_user("user") it "has the right title" do response.should have_selector("title", :content => "the title") end end end
This is a simple example to express my point of view, but I have many tests that are repeated ... Of course, there are also some tests that are unique for each context, but it doesnโt matter here.
Is there a way to write tests only once and then run them in different contexts?
source share