有没有办法可以在使用标签的特定测试之后/之前运行 after/before 块?
我有 3 个 it
块
describe "describe" do
it "test1" do
end
it "test2" do
end
after(<<what goes here??>>) do
end
end
如何仅在 test2 之后运行 after 块?那可能吗?
最佳答案
您应该使用 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
在 before/after 块中有 if/else 条件是一种代码味道。不要那样做。它只会使您的测试变得脆弱、容易出错且难以更改。
关于ruby - 在 Rspec 中进行特定测试后在块后运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50690703/