使用RSpec創建一些控制器測試,我發現自己爲每個可能的用戶角色重複多個測試用例。使用RSpec爲每個用戶角色重複測試描述
例如
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
這是一個簡單的例子,只是爲了讓我的觀點,但我有很多的測試,反覆強調......當然也有一些測試是爲每個上下文唯一,但這裏沒關係。
有沒有辦法只寫一次測試,然後在不同的上下文中運行它們?
非常感謝! – Ian 2011-11-02 18:22:40