RSpec cleanup

This commit is contained in:
Thomas Walpole 2018-08-27 09:34:33 -07:00
parent fcc94a43f5
commit 4ebb92dfdd
8 changed files with 22 additions and 15 deletions

View File

@ -208,11 +208,12 @@ Capybara::SpecHelper.spec '#find' do
context 'with css as default selector' do
before { Capybara.default_selector = :css }
after { Capybara.default_selector = :xpath }
it 'should find the first element using the given locator' do
expect(@session.find('h1').text).to eq('This is a test')
expect(@session.find("input[id='test_field']").value).to eq('monkey')
end
after { Capybara.default_selector = :xpath }
end
it 'should raise ElementNotFound with a useful default message if nothing was found' do

View File

@ -545,6 +545,8 @@ Capybara::SpecHelper.spec 'node' do
context 'without automatic reload' do
before { Capybara.automatic_reload = false }
after { Capybara.automatic_reload = true }
it 'should reload the current context of the node' do
@session.visit('/with_js')
node = @session.find(:css, '#reload-me')
@ -574,7 +576,6 @@ Capybara::SpecHelper.spec 'node' do
expect(error).to be_an_invalid_element_error(@session)
end)
end
after { Capybara.automatic_reload = true }
end
context 'with automatic reload' do

View File

@ -87,6 +87,10 @@ Capybara::SpecHelper.spec '#reset_session!' do
Capybara.reuse_server = false
end
after do
Capybara.reuse_server = @reuse_server
end
it 'raises any standard errors caught inside the server during a second session', requires: [:server] do
Capybara.using_driver(@session.mode) do
Capybara.using_session(:another_session) do
@ -100,10 +104,6 @@ Capybara::SpecHelper.spec '#reset_session!' do
end
end
end
after do
Capybara.reuse_server = @reuse_server
end
end
it 'raises configured errors caught inside the server', requires: [:server] do

View File

@ -45,11 +45,12 @@ Capybara::SpecHelper.spec '#text' do
context 'with css as default selector' do
before { Capybara.default_selector = :css }
after { Capybara.default_selector = :xpath }
it 'should print the text of the page' do
@session.visit('/with_simple_html')
expect(@session.text).to eq('Bar')
end
after { Capybara.default_selector = :xpath }
end
it 'should be correctly normalized when visible' do

View File

@ -9,11 +9,12 @@ Capybara::SpecHelper.spec '#title' do
context 'with css as default selector' do
before { Capybara.default_selector = :css }
after { Capybara.default_selector = :xpath }
it 'should get the title of the page' do
@session.visit('/with_title')
expect(@session.title).to eq('Test Title')
end
after { Capybara.default_selector = :xpath }
end
context 'within iframe', requires: [:frames] do

View File

@ -60,13 +60,14 @@ Capybara::SpecHelper.spec '#within' do
context 'with the default selector set to CSS' do
before { Capybara.default_selector = :css }
after { Capybara.default_selector = :xpath }
it 'should use CSS' do
@session.within('#for_bar li', text: 'With Simple HTML') do
@session.click_link('Go')
end
expect(@session).to have_content('Bar')
end
after { Capybara.default_selector = :xpath }
end
context 'with nested scopes' do

View File

@ -40,6 +40,10 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
end
describe '#click_link' do
after do
@session.driver.options[:respect_data_method] = false
end
it 'should use data-method if option is true' do
@session.driver.options[:respect_data_method] = true
@session.visit '/with_html'
@ -60,10 +64,6 @@ RSpec.describe Capybara::Session do # rubocop:disable RSpec/MultipleDescribes
@session.click_link 'A link with capitalized data-method'
expect(@session.html).to include('The requested object was deleted')
end
after do
@session.driver.options[:respect_data_method] = false
end
end
describe '#fill_in' do

View File

@ -325,12 +325,13 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
context 'with default selector CSS' do
before { Capybara.default_selector = :css }
after { Capybara.default_selector = :xpath }
it 'fails if has_content? returns false' do
expect do
expect(page).to have_content('No such Text')
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
end
after { Capybara.default_selector = :xpath }
end
end
@ -461,12 +462,13 @@ RSpec.shared_examples Capybara::RSpecMatchers do |session, _mode|
context 'with default selector CSS' do
before { Capybara.default_selector = :css }
after { Capybara.default_selector = :xpath }
it 'fails if has_text? returns false' do
expect do
expect(page).to have_text('No such Text')
end.to raise_error(/expected to find text "No such Text" in "(.*)This is a test(.*)"/)
end
after { Capybara.default_selector = :xpath }
end
end