This hints at another extension I've wanted to write for us for a while.
Common html selector strings, Labels, input fields, textareas, forms,
links, etc
Really just rolling up something like:
response.should have_tag("input[type=text][name=?][value=?][id=company-
name]", "user[company_name]", "Some Company Inc.")
into something like:
respose.should have_text_input(:user, :company_name, :id => "company-
name", "Some Company Inc.")
It feels closer to the Rails view helpers. Not a huge win, but we have
so many selectors than abstracting up one would make our specs more
readable.
Damn "To Code" list...
-Zach
Begin forwarded message:
From: Zach Moazeni <[EMAIL PROTECTED]>
Date: March 13, 2008 1:46:34 PM GMT-04:00
To: rspec-users <rspec-users@rubyforge.org>
Subject: Re: [rspec-users] Problems with form_for and partials
We've been going down this route:
http://pastie.caboo.se/165265
We use mocha for our mocking and originally we mocked out the form
builder, but the specs felt crufty. We then converted to
instantiating the FormBuilder and passing it to partials that needed
it.
For the views that send in the FormBuilder, we use the #with passing
a block and assert the "is_a?" inside (I'm still not too keen on
using the param helper/matchers). This looks a bit more bulky (and
is kinda ugly in having assertions in a setup) but it really greased
the wheels for us.
We ended up preferring to assert the presence of html vs
expectations on a FormBuilder stub, and it made the view specs feel
a bit more natural.
One last note: we hacked the #render in rspec_on_rails to output the
contents of a partial (which is why the template stubbing the render
returns "form partial") and we assert the presence of that text in
the response. Helps catch those rascally <% %> instead of <%= %>.
I've been meaning to form together a patch and submit a proper
extension, but it's as time allows.
Perhaps a bit more than you were asking for, but I hope this helps
-Zach
On Mar 13, 2008, at 1:25 PM, Jonathan Linowes wrote:
Thank you!
for the record, I refactored my code so the view does a form_for, and
any partials that render fields with the form builder does its own
fields_for. This makes the design cleaner and more testable. However,
I'm not sure if there's any performance cost in doing it this way
instead of passing the form builder around, anyone?
On Mar 13, 2008, at 5:05 AM, David Chelimsky wrote:
On Wed, Mar 12, 2008 at 10:19 PM, Jonathan Linowes
<[EMAIL PROTECTED]> wrote:
On Mar 12, 2008, at 5:47 PM, David Chelimsky wrote:
On Wed, Mar 12, 2008 at 9:43 PM, Zach Dennis
<[EMAIL PROTECTED]> wrote:
You can use mocha parameter matching to match on "anything" where
your
form builder would be passed in. You could also use Mocha's
"kind_of"
parameter matcher to ensure that what you expect is a FormBuilder
object.
Another way to do this is to not pass in your form builder,
but the
object needed, and then use fields_for inside the partial itself.
This
works well in some scenarios.
You could also use rspec's parameter matching, which also supports
"anything" but not "kind_of" ;)
how would i use that in stub_render? eg if my view has
<%= render :partial => 'pages/foo', :layout =>
'bar', :locals =>
{ :f => f } %>
what's the stub?
As of 1.1.3:
stub_render(:partial => 'pages/foo', :layout => 'bar', :locals =>
{:f => })
There is now, in trunk, hash_including matcher, so you *should* (I
haven't tried yet) be able to do this:
stub_render(hash_including(:locals => {:f => }))
That keeps it a bit less brittle, as the previous version will
fail if
you add anything else to the actual render call this won't fail.
Cheers,
David
_______________________________________________
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
_______________________________________________
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