有没有一种方法可以在使用标签的特定测试之后/之前运行之后/之前的 block ?
我有 3 个 it
block
describe "describe" do
it "test1" do
end
it "test2" do
end
after(<<what goes here??>>) do
end
end
如何仅在 test2 之后运行 after block ?这可能吗?
最佳答案
您应该使用 context
来执行此操作。像这样的东西:
describe "describe" do
context 'logged in' do
before(:each) do
# thing that happens in logged in context
end
after(:each) do
# thing that happens in logged in context
end
it "test1" do
end
end
context 'not logged in' do
# No before/after hooks here. Just beautiful test isolation
it "test2" do
end
end
end
在 block 之前/之后有 if/else 条件是一种代码味道。不要那样做。它只会让您的测试变得脆弱、容易出错并且难以更改。
关于ruby - 在 Rspec 中进行特定测试后在 block 后运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50690703/