gpt4 book ai didi

ruby - 干燥 RSpec 中的重复规范

转载 作者:数据小太阳 更新时间:2023-10-29 07:18:08 26 4
gpt4 key购买 nike

在下面的测试中,Bar 和 Baz block 包含相同的规范。

首先撇开为什么需要这样的重复不谈,我想知道如何才能把它干掉。

我尝试将 block 转换为对象并在 Bar 和 Baz 下调用它们,但可能是因为我没有获得正确的范围,我无法使其工作。

describe Foo do
describe Bar do
before(:each) do
prepare
end

it "should do something" do
true
end

it "should do something else" do
true
end
end

describe Baz do
before(:each) do
prepare_something_else
end

it "should do something" do
true
end

it "should do something else" do
true
end
end
end

最佳答案

关于ruby - 干燥 RSpec 中的重复规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2611212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com