On Fri, Feb 13, 2009 at 1:53 PM, Phlip <phlip2...@gmail.com> wrote: > Yury Kotlyarov wrote: > >> it "should have form with input fields" do >> render ... >> response.should have_form(users_path) do >> with_field_set 'Personal Information' do >> with_text_field 'First name', 'user[first_name]' >> ... >> end >> end >> end > > The minor problem with that system is it forces your test to say exactly > what the code says. That's not "driven" development! > > If you can forbear to use matchers (shocked gasp!), at my day-job we match > blocks all the time with assert2's new xpath system: > > require 'assert2/xpath' > > assert_xhtml response > > xpath :form, :action => users_path do > xpath :fieldset, ?. => 'Personal Information' do > xpath :input, :type => 'text', :name => 'user[first_name]' and > xpath :input, :type => 'text', :name => 'user[last_name]' > end > end
Hey Philip, This looks pretty cool. I wonder if you'd have any interest in making this a bit more rspec-friendly? Something like an option to run it like this: expect_xpath do xpath :form, :action => users_path do xpath :fieldset, ?. => 'Personal Information' do xpath :input, :type => 'text', :name => 'user[first_name]' and xpath :input, :type => 'text', :name => 'user[last_name]' end end end > > From there, wrapping the xpath() calls up into kewt with_text_field() macros > would be trivial. They could also absolves the redundant 'user[]' text on > the names, for example. > > If any inner xpath() fails, there, the fault diagnostic contains a formatted > & indented copy of the HTML block under inspection. The entire page would > not spew out! Only the <form> or <fieldset> would. > > -- > Phlip > > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users