Rspec 水豚';在';跨多个测试的范围
是否可以定义一个跨越多个测试的Capybara范围(在RSpec中) 例如,我想将此转换为:Rspec 水豚';在';跨多个测试的范围,rspec,capybara,Rspec,Capybara,是否可以定义一个跨越多个测试的Capybara范围(在RSpec中) 例如,我想将此转换为: it 'has two things' do within('.some-div') do expect(page).to have_text('foo') expect(page).to have_text('bar') end end 为此: context 'with two things' do before :each do within('.some-d
it 'has two things' do
within('.some-div') do
expect(page).to have_text('foo')
expect(page).to have_text('bar')
end
end
为此:
context 'with two things' do
before :each do
within('.some-div') # pseudo-code - this doesn't work
end
it 'has foo' do
expect(page).to have_text('foo')
end
it 'has bar' do
expect(page).to have_text('bar')
end
end
我试着在块周围使用,如下所示:
around :each do |example|
within('.some-div') do
example.run
end
end
虽然它会解析并运行,但实际上并没有将
范围内的应用到示例中。您应该能够这样做
before :each do
@section = page.find('.some-div')
end
it 'has foo' do
expect(@section).to have_text('foo')
end
it 'has bar' do
expect(@section).to have_text('bar')
end