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

Ensure Capybara.exact is set correctly for specific tests

This commit is contained in:
Thomas Walpole 2018-02-27 17:43:16 -08:00
parent e6b568268b
commit 4a7c4d2314
7 changed files with 37 additions and 40 deletions

View file

@ -26,7 +26,7 @@ Capybara::SpecHelper.spec "#all" do
expect(@session.all(:css, "a#has-been-clicked", minimum: 0)).to be_empty
end
it "should accept an XPath instance" do
it "should accept an XPath instance", :exact_false do
@session.visit('/form')
@xpath = Capybara::Selector.all[:fillable_field].call('Name')
expect(@xpath).to be_a(::XPath::Union)

View file

@ -108,7 +108,7 @@ Capybara::SpecHelper.spec "#attach_file" do
expect(extract_results(@session)['image']).to eq(File.basename(__FILE__))
end
it "not allow partial matches when true" do
it "should not allow partial matches when true" do
expect do
@session.attach_file "Imag", __FILE__, exact: true
end.to raise_error(Capybara::ElementNotFound)

View file

@ -151,25 +151,18 @@ Capybara::SpecHelper.spec '#click_button' do
end
end
context "with id given on a submit button" do
it "should submit the associated form" do
context "input type=submit button" do
it "should submit by button id" do
@session.click_button('awe123')
expect(extract_results(@session)['first_name']).to eq('John')
end
it "should work with partial matches" do
@session.click_button('Go')
expect(@session).to have_content('You landed')
end
end
context "with title given on a submit button" do
it "should submit the associated form" do
it "should submit by button title" do
@session.click_button('What an Awesome Button')
expect(extract_results(@session)['first_name']).to eq('John')
end
it "should work with partial matches" do
it "should submit by partial title", :exact_false do
@session.click_button('What an Awesome')
expect(extract_results(@session)['first_name']).to eq('John')
end
@ -250,7 +243,7 @@ Capybara::SpecHelper.spec '#click_button' do
expect(extract_results(@session)['first_name']).to eq('John')
end
it "should work with partial matches" do
it "should work with partial matches", :exact_false do
@session.click_button('hai')
expect(extract_results(@session)['first_name']).to eq('John')
end
@ -263,7 +256,7 @@ Capybara::SpecHelper.spec '#click_button' do
expect(extract_results(@session)['first_name']).to eq('John')
end
it "should work with partial matches" do
it "should work with partial matches", :exact_false do
@session.click_button('kay')
expect(extract_results(@session)['first_name']).to eq('John')
end
@ -282,7 +275,7 @@ Capybara::SpecHelper.spec '#click_button' do
expect(extract_results(@session)['first_name']).to eq('John')
end
it "should work with partial matches" do
it "should work with partial matches", :exact_false do
@session.click_button('Okay 556')
expect(extract_results(@session)['first_name']).to eq('John')
end
@ -290,11 +283,11 @@ Capybara::SpecHelper.spec '#click_button' do
context "with text given on a button defined by <button> tag" do
it "should submit the associated form" do
@session.click_button('Click me')
@session.click_button('Click me!')
expect(extract_results(@session)['first_name']).to eq('John')
end
it "should work with partial matches" do
it "should work with partial matches", :exact_false do
@session.click_button('Click')
expect(extract_results(@session)['first_name']).to eq('John')
end
@ -321,7 +314,7 @@ Capybara::SpecHelper.spec '#click_button' do
expect(extract_results(@session)['first_name']).to eq('John')
end
it "should work with partial matches" do
it "should work with partial matches", :exact_false do
@session.click_button('ck_me')
expect(extract_results(@session)['first_name']).to eq('John')
end
@ -333,7 +326,7 @@ Capybara::SpecHelper.spec '#click_button' do
expect(extract_results(@session)['first_name']).to eq('John')
end
it "should work with partial matches" do
it "should work with partial matches", :exact_false do
@session.click_button('Click Title')
expect(extract_results(@session)['first_name']).to eq('John')
end
@ -345,7 +338,7 @@ Capybara::SpecHelper.spec '#click_button' do
expect(extract_results(@session)['first_name']).to eq('John')
end
it "should work with partial matches" do
it "should work with partial matches", :exact_false do
@session.click_button('se eating h')
expect(extract_results(@session)['first_name']).to eq('John')
end

View file

@ -37,7 +37,7 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
end
context "with :exact option" do
context "when `true`" do
context "when `false`" do
it "clicks on approximately matching link" do
@session.visit('/with_html')
@session.click_link_or_button('abore', exact: false)
@ -46,12 +46,12 @@ Capybara::SpecHelper.spec '#click_link_or_button' do
it "clicks on approximately matching button" do
@session.visit('/form')
@session.click_link_or_button('awe')
@session.click_link_or_button('awe', exact: false)
expect(extract_results(@session)['first_name']).to eq('John')
end
end
context "when `false`" do
context "when `true`" do
it "does not click on link which matches approximately" do
@session.visit('/with_html')
msg = "Unable to find visible link or button \"abore\""

View file

@ -35,7 +35,7 @@ Capybara::SpecHelper.spec '#click_link' do
expect(@session).to have_content('Bar')
end
it "should accept partial matches" do
it "should accept partial matches", :exact_false do
@session.click_link('abo')
expect(@session).to have_content('Bar')
end
@ -47,7 +47,7 @@ Capybara::SpecHelper.spec '#click_link' do
expect(@session).to have_content('Bar')
end
it "should accept partial matches" do
it "should accept partial matches", :exact_false do
@session.click_link('some titl')
expect(@session).to have_content('Bar')
end
@ -59,7 +59,7 @@ Capybara::SpecHelper.spec '#click_link' do
expect(@session).to have_content('Bar')
end
it "should accept partial matches" do
it "should accept partial matches", :exact_false do
@session.click_link('some imag')
expect(@session).to have_content('Bar')
end

View file

@ -13,12 +13,12 @@ Capybara::SpecHelper.spec "#select" do
expect(@session.find_field('Title').value).to eq('Miss')
end
it "should allow selecting exact options where there are inexact matches" do
it "should allow selecting exact options where there are inexact matches", :exact_false do
@session.select("Mr", from: 'Title')
expect(@session.find_field('Title').value).to eq('Mr')
end
it "should allow selecting options where they are the only inexact match" do
it "should allow selecting options where they are the only inexact match", :exact_false do
@session.select("Mis", from: 'Title')
expect(@session.find_field('Title').value).to eq('Miss')
end
@ -30,7 +30,7 @@ Capybara::SpecHelper.spec "#select" do
end.to raise_error(Capybara::ElementNotFound)
end
it "should not allow selecting an option if the match is ambiguous" do
it "should not allow selecting an option if the match is ambiguous", :exact_false do
expect do
@session.select("M", from: 'Title')
end.to raise_error(Capybara::Ambiguous)
@ -123,32 +123,32 @@ Capybara::SpecHelper.spec "#select" do
context "with multiple select" do
it "should return an empty value" do
expect(@session.find_field('Language').value).to eq([])
expect(@session.find_field('Languages').value).to eq([])
end
it "should return value of the selected options" do
@session.select("Ruby", from: 'Language')
@session.select("Javascript", from: 'Language')
expect(@session.find_field('Language').value).to include('Ruby', 'Javascript')
@session.select("Ruby", from: 'Languages')
@session.select("Javascript", from: 'Languages')
expect(@session.find_field('Languages').value).to include('Ruby', 'Javascript')
end
it "should select one option" do
@session.select("Ruby", from: 'Language')
@session.select("Ruby", from: 'Languages')
@session.click_button('awesome')
expect(extract_results(@session)['languages']).to eq(['Ruby'])
end
it "should select multiple options" do
@session.select("Ruby", from: 'Language')
@session.select("Javascript", from: 'Language')
@session.select("Ruby", from: 'Languages')
@session.select("Javascript", from: 'Languages')
@session.click_button('awesome')
expect(extract_results(@session)['languages']).to include('Ruby', 'Javascript')
end
it "should remain selected if already selected" do
@session.select("Ruby", from: 'Language')
@session.select("Javascript", from: 'Language')
@session.select("Ruby", from: 'Language')
@session.select("Ruby", from: 'Languages')
@session.select("Javascript", from: 'Languages')
@session.select("Ruby", from: 'Languages')
@session.click_button('awesome')
expect(extract_results(@session)['languages']).to include('Ruby', 'Javascript')
end

View file

@ -67,6 +67,10 @@ module Capybara
SpecHelper.reset_threadsafe(false, @session)
end
before :each, :exact_false do
Capybara.exact = false
end
specs.each do |spec_name, spec_options, block|
describe spec_name, *spec_options do
class_eval(&block)