[rspec-users] how to write complex matchers
dchelimsky at gmail.com
Fri Feb 13 15:05:40 EST 2009
On Fri, Feb 13, 2009 at 1:53 PM, Phlip <phlip2005 at 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]'
> 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]'
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
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]'
> 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.
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users