我正在努力争取两个'之前'描述块下的块,但只有后者运行。
describe '#bunch_of_tests' do
before(:all) do
p 'do this before all tests'
end
before(:each) do
p 'do this before each test'
end
describe 'this is 1st test' do
it 'runs 1st test' do
end
end
describe 'this is 2nd test' do
it 'runs 2nd test' do
end
end
end
问题是这句话永远不会被打印出来: '在所有测试之前执行此操作'
我的期望是这应该在所有测试之前运行一次。 '前(:每个)'块正在按预期工作。
答案 0 :(得分:1)
这可能很笨拙,但您可以尝试:
RSpec.describe '#bunch_of_tests' do
before(:all) do
p 'do this before all tests'
end
describe "before each" do
before(:each) do
p 'do this before each test'
end
describe 'this is 1st test' do
it 'runs 1st test' do
end
end
describe 'this is 2nd test' do
it 'runs 2nd test' do
end
end
end
end
哪个收益率:
#bunch_of_tests
"do this before all tests"
before each
this is 1st test
"do this before each test"
runs 1st test
this is 2nd test
"do this before each test"
runs 2nd test
Finished in 0.40184 seconds (files took 3.5 seconds to load)
2 examples, 0 failures