2017-02-16 1 views
0

RSpecの複数のテストにまたがるCapybaraスコープを定義できますか?複数のテストにまたがるCapybara 'within'スコープ

例えば、私はこのターンしたいと思います。その一方

around :each do |example| 
    within('.some-div') do 
    example.run 
    end 
end 

:私はこのようなaroundブロックを使用してみました

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 

:この中

it 'has two things' do 
    within('.some-div') do 
    expect(page).to have_text('foo') 
    expect(page).to have_text('bar') 
    end 
end 

をパースして実行すると、実際にはwithinスコープがこの例に適用されるわけではありません。

答えて

0

あなたが行うことができるはず

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 
関連する問題