# frozen_string_literal: trueCapybara::SpecHelper.spec'#select'dobeforedo@session.visit('/form')endit'should return value of the first option'doexpect(@session.find_field('Title').value).toeq('Mrs')endit'should return value of the selected option'do@session.select('Miss',from: 'Title')expect(@session.find_field('Title').value).toeq('Miss')endit'should allow selecting exact options where there are inexact matches',:exact_falsedo@session.select('Mr',from: 'Title')expect(@session.find_field('Title').value).toeq('Mr')endit'should allow selecting options where they are the only inexact match',:exact_falsedo@session.select('Mis',from: 'Title')expect(@session.find_field('Title').value).toeq('Miss')endit'should not allow selecting options where they are the only inexact match if `exact: true` is specified'dosel=@session.find(:select,'Title')expectdosel.select('Mis',exact: true)end.toraise_error(Capybara::ElementNotFound)endit'should not allow selecting an option if the match is ambiguous',:exact_falsedoexpectdo@session.select('M',from: 'Title')end.toraise_error(Capybara::Ambiguous)endit'should return the value attribute rather than content if present'doexpect(@session.find_field('Locale').value).toeq('en')endit'should select an option from a select box by id'do@session.select('Finish',from: 'form_locale')@session.click_button('awesome')expect(extract_results(@session)['locale']).toeq('fi')endit'should select an option from a select box by label'do@session.select('Finish',from: 'Locale')@session.click_button('awesome')expect(extract_results(@session)['locale']).toeq('fi')endit'should select an option without giving a select box'do@session.select('Swedish')@session.click_button('awesome')expect(extract_results(@session)['locale']).toeq('sv')endit'should escape quotes'do@session.select("John's made-up language",from: 'Locale')@session.click_button('awesome')expect(extract_results(@session)['locale']).toeq('jo')endit'should obey from'do@session.select('Miss',from: 'Other title')@session.click_button('awesome')results=extract_results(@session)expect(results['other_title']).toeq('Miss')expect(results['title']).not_toeq('Miss')endit'show match labels with preceding or trailing whitespace'do@session.select('Lojban',from: 'Locale')@session.click_button('awesome')expect(extract_results(@session)['locale']).toeq('jbo')endit'casts to string'do@session.select(:Miss,from: :Title)expect(@session.find_field('Title').value).toeq('Miss')endcontext'input with datalist'doit'should select an option'do@session.select('Audi',from: 'manufacturer')@session.click_button('awesome')expect(extract_results(@session)['manufacturer']).toeq('Audi')endit'should not find an input without a datalist'doexpectdo@session.select('Thomas',from: 'form_first_name')end.toraise_error(/Unable to find input box with datalist completion "form_first_name"/)endit"should not select an option that doesn't exist"doexpectdo@session.select('Tata',from: 'manufacturer')end.toraise_error(/Unable to find datalist option "Tata"/)endit'should not select a disabled option'doexpectdo@session.select('Mercedes',from: 'manufacturer')end.toraise_error(/Unable to find datalist option "Mercedes"/)endendcontext"with a locator that doesn't exist"doit'should raise an error'domsg=/Unable to find select box "does not exist"/expectdo@session.select('foo',from: 'does not exist')end.toraise_error(Capybara::ElementNotFound,msg)endendcontext"with an option that doesn't exist"doit'should raise an error'domsg=/^Unable to find option "Does not Exist" within/expectdo@session.select('Does not Exist',from: 'form_locale')end.toraise_error(Capybara::ElementNotFound,msg)endendcontext'on a disabled select'doit'should raise an error'doexpectdo@session.select('Should not see me',from: 'Disabled Select')end.toraise_error(Capybara::ElementNotFound)endendcontext'on a disabled option'doit'should not select'do@session.select('Other',from: 'form_title')expect(@session.find_field('form_title').value).not_toeq'Other'endit'should warn'doexpect_any_instance_of(Capybara::Node::Element).toreceive(:warn).once@session.select('Other',from: 'form_title')endendcontext'with multiple select'doit'should return an empty value'doexpect(@session.find_field('Languages').value).toeq([])endit'should return value of the selected options'do@session.select('Ruby',from: 'Languages')@session.select('Javascript',from: 'Languages')expect(@session.find_field('Languages').value).toinclude('Ruby','Javascript')endit'should select one option'do@session.select('Ruby',from: 'Languages')@session.click_button('awesome')expect(extract_results(@session)['languages']).toeq(['Ruby'])endit'should select multiple options'do@session.select('Ruby',from: 'Languages')@session.select('Javascript',from: 'Languages')@session.click_button('awesome')expect(extract_results(@session)['languages']).toinclude('Ruby','Javascript')endit'should remain selected if already selected'do@session.select('Ruby',from: 'Languages')@session.select('Javascript',from: 'Languages')@session.select('Ruby',from: 'Languages')@session.click_button('awesome')expect(extract_results(@session)['languages']).toinclude('Ruby','Javascript')endit'should return value attribute rather than content if present'doexpect(@session.find_field('Underwear').value).toinclude('thermal')endendcontext'with :exact option'docontext'when `false`'doit'can match select box approximately'do@session.select('Finish',from: 'Loc',exact: false)@session.click_button('awesome')expect(extract_results(@session)['locale']).toeq('fi')endit'can match option approximately'do@session.select('Fin',from: 'Locale',exact: false)@session.click_button('awesome')expect(extract_results(@session)['locale']).toeq('fi')endit'can match option approximately when :from not given'do@session.select('made-up language',exact: false)@session.click_button('awesome')expect(extract_results(@session)['locale']).toeq('jo')endendcontext'when `true`'doit'can match select box approximately'doexpectdo@session.select('Finish',from: 'Loc',exact: true)end.toraise_error(Capybara::ElementNotFound)endit'can match option approximately'doexpectdo@session.select('Fin',from: 'Locale',exact: true)end.toraise_error(Capybara::ElementNotFound)endit'can match option approximately when :from not given'doexpectdo@session.select('made-up language',exact: true)end.toraise_error(Capybara::ElementNotFound)endendendend