2012-07-21 20:44:10 +00:00
|
|
|
Capybara::SpecHelper.spec '#find_field' do
|
|
|
|
before do
|
|
|
|
@session.visit('/form')
|
|
|
|
end
|
2009-12-15 19:58:51 +00:00
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
it "should find any field" do
|
2013-11-14 17:43:36 +00:00
|
|
|
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]')
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
2009-12-15 19:58:51 +00:00
|
|
|
|
2012-09-06 07:33:43 +00:00
|
|
|
it "casts to string" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session.find_field(:'Dog').value).to eq('dog')
|
2012-09-06 07:33:43 +00:00
|
|
|
end
|
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
it "should raise error if the field doesn't exist" do
|
2012-10-30 13:26:19 +00:00
|
|
|
expect do
|
2012-07-21 20:44:10 +00:00
|
|
|
@session.find_field('Does not exist')
|
2012-10-30 13:26:19 +00:00
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
2012-07-21 20:44:10 +00:00
|
|
|
end
|
2009-12-15 19:58:51 +00:00
|
|
|
|
2014-07-02 18:17:53 +00:00
|
|
|
it "should warn if filter option is invalid" do
|
|
|
|
expect_any_instance_of(Kernel).to receive(:warn).
|
|
|
|
with('Invalid value nil passed to filter disabled')
|
|
|
|
@session.find_field('Dog', disabled: nil)
|
|
|
|
end
|
|
|
|
|
2012-07-21 20:44:10 +00:00
|
|
|
it "should be aliased as 'field_labeled' for webrat compatibility" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session.field_labeled('Dog').value).to eq('dog')
|
2012-10-30 13:26:19 +00:00
|
|
|
expect do
|
2012-07-21 20:44:10 +00:00
|
|
|
@session.field_labeled('Does not exist')
|
2012-10-30 13:26:19 +00:00
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
2009-12-15 19:58:51 +00:00
|
|
|
end
|
2013-02-24 16:47:53 +00:00
|
|
|
|
|
|
|
context "with :exact option" do
|
|
|
|
it "should accept partial matches when false" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session.find_field("Explanation", :exact => false)[:name]).to eq("form[name_explanation]")
|
2013-02-24 16:47:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not accept partial matches when true" do
|
|
|
|
expect do
|
|
|
|
@session.find_field("Explanation", :exact => true)
|
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
|
|
|
end
|
2013-03-08 13:18:56 +00:00
|
|
|
|
|
|
|
context "with :disabled option" do
|
|
|
|
it "should find disabled fields when true" do
|
2013-11-14 17:43:36 +00:00
|
|
|
expect(@session.find_field("Disabled Checkbox", :disabled => true)[:name]).to eq("form[disabled_checkbox]")
|
2013-03-08 13:18:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should not find disabled fields when false" do
|
|
|
|
expect do
|
|
|
|
@session.find_field("Disabled Checkbox", :disabled => false)
|
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not find disabled fields by default" do
|
|
|
|
expect do
|
|
|
|
@session.find_field("Disabled Checkbox")
|
|
|
|
end.to raise_error(Capybara::ElementNotFound)
|
|
|
|
end
|
|
|
|
end
|
2015-08-25 21:25:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
it "should not find readonly fields when false" do
|
|
|
|
expect(@session.find_field('form[readonly_test]', readonly: false)[:id]).to eq 'not_readonly'
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2010-01-18 19:33:22 +00:00
|
|
|
end
|