Ashley Moran
2007-Jan-16 16:51 UTC
[rspec-users] Specifying the contents of a date selector
Another n00b question (can you tell I don''t normally write view code yet???)... I''m using the date_select form helper to give me three select popups, (day, month, year). I want to specify that these exist and are set to today''s date I''ve tried this: response.should_have ''form > p > select [name="gap_quick_quote_parameters[purchase_date(3i)]"] > option'', :attributes => { :value => ''16'', :selected => ''selected'' }, :content => ''16'' But it fails, saying: Invalid selector: "] > option Is this a limitation of the CSS selector? I can''t think of a way of phrasing the spec without trying to select children of the select elements. I want to avoid specifying that SOME select popup on the page has a value equal to today''s day, month, or year. Ashley
David Chelimsky
2007-Jan-16 17:27 UTC
[rspec-users] Specifying the contents of a date selector
On 1/16/07, Ashley Moran <work at ashleymoran.me.uk> wrote:> Another n00b question (can you tell I don''t normally write view code > yet???)... > > I''m using the date_select form helper to give me three select popups, > (day, month, year). I want to specify that these exist and are set > to today''s date > > I''ve tried this: > > response.should_have ''form > p > select > [name="gap_quick_quote_parameters[purchase_date(3i)]"] > option'', > :attributes => { :value => ''16'', :selected > => ''selected'' }, > :content => ''16'' > > But it fails, saying: > > Invalid selector: "] > option > > Is this a limitation of the CSS selector? I can''t think of a way of > phrasing the spec without trying to select children of the select > elements. I want to avoid specifying that SOME select popup on the > page has a value equal to today''s day, month, or year.The syntax you are using invokes a preliminary port of assert_select that is not officially supported yet. That said, take a look at the tests for the selector. All the examples that use double quotes have them escaped: "form>p>select[name=\"gap_quick_quote_parameters[purchase_date(3i)]\"]>option" I''m guessing you could also do this: "form>p>select[name=''gap_quick_quote_parameters[purchase_date(3i)]'']>option" or even this: "form>p>select[name=gap_quick_quote_parameters[purchase_date(3i)]]>option" Let us know what works, if any of those suggestions. Cheers, David> Ashley > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Ashley Moran
2007-Jan-16 17:52 UTC
[rspec-users] Specifying the contents of a date selector
On 16 Jan 2007, at 17:27, David Chelimsky wrote:> "form>p>select[name=''gap_quick_quote_parameters[purchase_date(3i)]''] > >option"Hi David Thanks for the pointer - that works fine. I found this out playing around with it: This fails (this is the original one I posted): response.should_have "''orm > p > select [name="gap_quick_quote_parameters[purchase_date(3i)]"] > option'' This succeeds (obviously the penultimate ]-character is interpreted as closing the *first* [-character): response.should_have ''form > p > select [name^="gap_quick_quote_parameters[purchase_date(3i)"] > option'' So apparently, using double quotes inside the CSS selector breaks bracket matching. I wouldn''t like to guess why it does that. Anyway it''s working now so I''m happy. Cheers Ashley PS I edited those code lines by hand in case they contains errors