lib/capybara/spec/session/find_field_spec.rb in capybara-2.7.1 vs lib/capybara/spec/session/find_field_spec.rb in capybara-2.8.0
- old
+ new
@@ -6,12 +6,27 @@
it "should find any field" do
expect(@session.find_field('Dog').value).to eq('dog')
expect(@session.find_field('form_description').text).to eq('Descriptive text goes here')
expect(@session.find_field('Region')[:name]).to eq('form[region]')
+
end
+ context "aria_label attribute with Capybara.enable_aria_label" do
+ it "should find when true" do
+ Capybara.enable_aria_label = true
+ expect(@session.find_field('Unlabelled Input')[:name]).to eq('form[which_form]')
+ # expect(@session.find_field('Emergency Number')[:id]).to eq('html5_tel')
+ end
+
+ it "should not find when false" do
+ Capybara.enable_aria_label = false
+ expect { @session.find_field('Unlabelled Input') }.to raise_error(Capybara::ElementNotFound)
+ # expect { @session.find_field('Emergency Number') }.to raise_error(Capybara::ElementNotFound)
+ end
+ end
+
it "casts to string" do
expect(@session.find_field(:'Dog').value).to eq('dog')
end
it "should raise error if the field doesn't exist" do
@@ -69,11 +84,10 @@
it "should find enabled fields when :all" do
expect(@session.find_field('Dog', :disabled => :all).value).to eq('dog')
end
end
-
context 'with :readonly option' do
it "should find readonly fields when true" do
expect(@session.find_field('form[readonly_test]', readonly: true)[:id]).to eq 'readonly'
end
@@ -83,8 +97,14 @@
it "should ignore readonly by default" do
expect do
@session.find_field('form[readonly_test]')
end.to raise_error(Capybara::Ambiguous, /found 2 elements/)
+ end
+ end
+
+ context 'with no locator' do
+ it 'should use options to find the field' do
+ expect(@session.find_field(with: 'dog')['id']).to eq "form_pets_dog"
end
end
end