我在rspec主页上找到了更好的解决方案.显然,它支持共享示例组.从https://www.relishapp.com/rspec/rspec-core/v/2-13/docs/example-groups/shared-examples开始!
共享示例组
您可以创建共享示例组
假设你有这样的行为
首先,找出"共享的"
shared_examples_for "all editions" do
it "should behave like all editions" do
end
end
然后当你需要定义行为时
describe "SmallEdition" do
it_should_behave_like "all editions"
it "should also behave like a small edition" do
end
end