1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Style updates

This commit is contained in:
Thomas Walpole 2020-02-17 11:49:12 -08:00
parent 6dc1615504
commit a7cd97ed4d
6 changed files with 61 additions and 44 deletions

View file

@ -162,5 +162,8 @@ RSpec/FilePath:
RSpec/PredicateMatcher:
Enabled: false
# RSpec/InstanceVariable:
# Enabled: false
Capybara/FeatureMethods:
Enabled: false

View file

@ -451,32 +451,35 @@ Capybara::SpecHelper.spec '#find' do
context 'with spatial filters', requires: [:spatial] do
before do
@session.visit('/spatial')
@center = @session.find(:css, 'div.center')
end
let :center do
@session.find(:css, 'div.center')
end
it 'should find an element above another element' do
expect(@session.find(:css, 'div:not(.corner)', above: @center).text).to eq('2')
expect(@session.find(:css, 'div:not(.corner)', above: center).text).to eq('2')
end
it 'should find an element below another element' do
expect(@session.find(:css, 'div:not(.corner):not(.footer)', below: @center).text).to eq('8')
expect(@session.find(:css, 'div:not(.corner):not(.footer)', below: center).text).to eq('8')
end
it 'should find an element left of another element' do
expect(@session.find(:css, 'div:not(.corner)', left_of: @center).text).to eq('4')
expect(@session.find(:css, 'div:not(.corner)', left_of: center).text).to eq('4')
end
it 'should find an element right of another element' do
expect(@session.find(:css, 'div:not(.corner)', right_of: @center).text).to eq('6')
expect(@session.find(:css, 'div:not(.corner)', right_of: center).text).to eq('6')
end
it 'should combine spatial filters' do
expect(@session.find(:css, 'div', left_of: @center, above: @center).text).to eq('1')
expect(@session.find(:css, 'div', right_of: @center, below: @center).text).to eq('9')
expect(@session.find(:css, 'div', left_of: center, above: center).text).to eq('1')
expect(@session.find(:css, 'div', right_of: center, below: center).text).to eq('9')
end
it 'should find an element "near" another element' do
expect(@session.find(:css, 'div.distance', near: @center).text).to eq('2')
expect(@session.find(:css, 'div.distance', near: center).text).to eq('2')
end
end

View file

@ -234,18 +234,21 @@ Capybara::SpecHelper.spec '#has_css?' do
context 'with spatial requirements', requires: [:spatial] do
before do
@session.visit('/spatial')
@center = @session.find(:css, '.center')
end
let :center do
@session.find(:css, '.center')
end
it 'accepts spatial options' do
expect(@session).to have_css('div', above: @center).thrice
expect(@session).to have_css('div', above: @center, right_of: @center).once
expect(@session).to have_css('div', above: center).thrice
expect(@session).to have_css('div', above: center, right_of: center).once
end
it 'supports spatial sugar' do
expect(@session).to have_css('div').left_of(@center).thrice
expect(@session).to have_css('div').below(@center).right_of(@center).once
expect(@session).to have_css('div').near(@center).exactly(8).times
expect(@session).to have_css('div').left_of(center).thrice
expect(@session).to have_css('div').below(center).right_of(center).once
expect(@session).to have_css('div').near(center).exactly(8).times
end
end

View file

@ -808,7 +808,10 @@ Capybara::SpecHelper.spec 'node' do
context 'offset', requires: [:js] do
before do
@session.visit('/offset')
@clicker = @session.find(:id, 'clicker')
end
let :clicker do
@session.find(:id, 'clicker')
end
context 'when w3c_click_offset is false' do
@ -817,17 +820,17 @@ Capybara::SpecHelper.spec 'node' do
end
it 'should offset from top left of element' do
@clicker.click(x: 10, y: 5)
clicker.click(x: 10, y: 5)
expect(@session).to have_text(/clicked at 110,105/)
end
it 'should offset outside the element' do
@clicker.click(x: -15, y: -10)
clicker.click(x: -15, y: -10)
expect(@session).to have_text(/clicked at 85,90/)
end
it 'should default to click the middle' do
@clicker.click
clicker.click
expect(@session).to have_text(/clicked at 150,150/)
end
end
@ -838,17 +841,17 @@ Capybara::SpecHelper.spec 'node' do
end
it 'should offset from center of element' do
@clicker.click(x: 10, y: 5)
clicker.click(x: 10, y: 5)
expect(@session).to have_text(/clicked at 160,155/)
end
it 'should offset outside from center of element' do
@clicker.click(x: -65, y: -60)
clicker.click(x: -65, y: -60)
expect(@session).to have_text(/clicked at 85,90/)
end
it 'should default to click the middle' do
@clicker.click
clicker.click
expect(@session).to have_text(/clicked at 150,150/)
end
end
@ -891,7 +894,10 @@ Capybara::SpecHelper.spec 'node' do
context 'offset', requires: [:js] do
before do
@session.visit('/offset')
@clicker = @session.find(:id, 'clicker')
end
let :clicker do
@session.find(:id, 'clicker')
end
context 'when w3c_click_offset is false' do
@ -900,17 +906,17 @@ Capybara::SpecHelper.spec 'node' do
end
it 'should offset from top left of element' do
@clicker.double_click(x: 10, y: 5)
clicker.double_click(x: 10, y: 5)
expect(@session).to have_text(/clicked at 110,105/)
end
it 'should offset outside the element' do
@clicker.double_click(x: -15, y: -10)
clicker.double_click(x: -15, y: -10)
expect(@session).to have_text(/clicked at 85,90/)
end
it 'should default to click the middle' do
@clicker.double_click
clicker.double_click
expect(@session).to have_text(/clicked at 150,150/)
end
end
@ -921,17 +927,17 @@ Capybara::SpecHelper.spec 'node' do
end
it 'should offset from center of element' do
@clicker.double_click(x: 10, y: 5)
clicker.double_click(x: 10, y: 5)
expect(@session).to have_text(/clicked at 160,155/)
end
it 'should offset outside from center of element' do
@clicker.double_click(x: -65, y: -60)
clicker.double_click(x: -65, y: -60)
expect(@session).to have_text(/clicked at 85,90/)
end
it 'should default to click the middle' do
@clicker.double_click
clicker.double_click
expect(@session).to have_text(/clicked at 150,150/)
end
end
@ -974,7 +980,10 @@ Capybara::SpecHelper.spec 'node' do
context 'offset', requires: [:js] do
before do
@session.visit('/offset')
@clicker = @session.find(:id, 'clicker')
end
let :clicker do
@session.find(:id, 'clicker')
end
context 'when w3c_click_offset is false' do
@ -983,17 +992,17 @@ Capybara::SpecHelper.spec 'node' do
end
it 'should offset from top left of element' do
@clicker.right_click(x: 10, y: 5)
clicker.right_click(x: 10, y: 5)
expect(@session).to have_text(/clicked at 110,105/)
end
it 'should offset outside the element' do
@clicker.right_click(x: -15, y: -10)
clicker.right_click(x: -15, y: -10)
expect(@session).to have_text(/clicked at 85,90/)
end
it 'should default to click the middle' do
@clicker.right_click
clicker.right_click
expect(@session).to have_text(/clicked at 150,150/)
end
end
@ -1004,17 +1013,17 @@ Capybara::SpecHelper.spec 'node' do
end
it 'should offset from center of element' do
@clicker.right_click(x: 10, y: 5)
clicker.right_click(x: 10, y: 5)
expect(@session).to have_text(/clicked at 160,155/)
end
it 'should offset outside from center of element' do
@clicker.right_click(x: -65, y: -60)
clicker.right_click(x: -65, y: -60)
expect(@session).to have_text(/clicked at 85,90/)
end
it 'should default to click the middle' do
@clicker.right_click
clicker.right_click
expect(@session).to have_text(/clicked at 150,150/)
end
end

View file

@ -141,12 +141,12 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
end
describe '#maximize' do
before do
@initial_size = @session.current_window.size
let! :initial_size do
@session.current_window.size
end
after do
@session.current_window.resize_to(*@initial_size)
@session.current_window.resize_to(*initial_size)
sleep 0.5
end
@ -176,7 +176,7 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
expect(@session.current_window).to eq(orig_window)
# Maximizing the browser affects all tabs so this may not be valid in real browsers
# expect(@session.current_window.size).to eq(@initial_size)
# expect(@session.current_window.size).to eq(initial_size)
ow_width, ow_height = other_window.size
expect(ow_width).to be > 400
@ -185,12 +185,12 @@ Capybara::SpecHelper.spec Capybara::Window, requires: [:windows] do
end
describe '#fullscreen' do
before do
@initial_size = @session.current_window.size
let! :initial_size do
@session.current_window.size
end
after do
@session.current_window.resize_to(*@initial_size)
@session.current_window.resize_to(*initial_size)
sleep 1
end

View file

@ -60,7 +60,7 @@ module Capybara
RSpec.describe Capybara::Session, name, options do # rubocop:disable RSpec/EmptyExampleGroup
include Capybara::SpecHelper
include Capybara::RSpecMatchers
# rubocop:disable RSpec/ScatteredSetup
before do |example|
@session = session
instance_exec(example, &filter_block) if filter_block
@ -81,7 +81,6 @@ module Capybara
before :each, :exact_false do
Capybara.exact = false
end
# rubocop:enable RSpec/ScatteredSetup
specs.each do |spec_name, spec_options, block|
describe spec_name, *spec_options do # rubocop:disable RSpec/EmptyExampleGroup