2017-02-16 11 views
0

Ist es möglich, einen Capybara-Bereich zu definieren, der mehrere Tests (in RSpec) umfasst?Capybara 'innerhalb' über mehrere Tests hinweg

Zum Beispiel würde Ich mag diese drehen:

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

in diese:

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 

Ich habe versucht, einen around Block wie folgt aus:

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

Während das analysiert und ausführt, wendet es den Bereich within nicht auf das Beispiel an.

Antwort

0

Sie sollten in der Lage sein zu tun,

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 
Verwandte Themen