【发布时间】:2011-10-20 00:46:07
【问题描述】:
如何重用这些示例,以便只覆盖嵌套上下文的详细信息?
类似这样的东西(我使用thee 代替它,表示它是在嵌套上下文中执行的。它不在 RSpec 中,正是我想要的):
describe "Abilities" do
subject { Abilities.new user }
context "allowed" do
let(:user) { Factory(:power_user) }
thee { should be_able_to :create, object }
thee { should be_able_to :read, object }
thee { should be_able_to :update, object }
context "comment" do
let(:object) { Factory(:comment) }
end
context "post" do
let(:object) { Factory(:post) }
end
context "blog" do
let(:object) { Factory(:blog) }
end
end
end
这个示例最终会包含 3 个示例(创建、读取、更新),用于 3 个上下文(评论、帖子、博客),总共产生 9 个示例。
如何实现(无需编写共享示例)?
【问题讨论】:
标签: ruby-on-rails ruby testing rspec