gpt4 book ai didi

rspec - 在RSpec中,之前(:suite) and before(:all)?

转载 作者:行者123 更新时间:2023-12-03 07:17:11 30 4
gpt4 key购买 nike

The before and after hook documentation on Relish仅显示 before(:suite)before(:all) 之前调用。

我什么时候应该使用其中一种而不是另一种?

最佳答案

当在 RSpec.configure block 中定义 before(:all) 时,它会在每个顶级示例组之前调用,而 before(: suite) 代码块仅被调用一次。

这是一个例子:

RSpec.configure do |config|
config.before(:all) { puts 'Before :all' }
config.after(:all) { puts 'After :all' }
config.before(:suite) { puts 'Before :suite' }
config.after(:suite) { puts 'After :suite' }
end

describe 'spec1' do
example 'spec1' do
puts 'spec1'
end
end

describe 'spec2' do
example 'spec2' do
puts 'spec2'
end
end

输出:

Before :suite
Before :all
spec1
After :all
Before :all
spec2
After :all
After :suite

关于rspec - 在RSpec中,之前(:suite) and before(:all)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15445716/

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