[rspec-users] Missing template in helper specs with a render
zach.dennis at gmail.com
Sun Jun 7 01:02:07 EDT 2009
On Sat, Jun 6, 2009 at 6:34 PM, Charlie Bowman<charlesmbowman at gmail.com> wrote:
> I consider an if statement in the view layer a bug.
Perhaps we can consider it a possible code smell? It's not really a
bug unless it's producing incorrect or unexpected result in the
> I often need to
> conditionally render a partial and a helper is a great way to construct that
> condition. Im currently stubing the call to render but I only like stub
> when absolutely necessary.
Helpers can be a great way to organize some of the view's
implementation, although my goal isn't to move every conditional out
of the view, it's to avoid having unnecessary logic in the view. When
I work outside-in I'm able to push logic that doesn't belong in the
view into a presenter or further down to a model with a good method
name. The logic that is left in the view is very minimal and
ultra-simple. I find it easy to spec and it doesn't impede the life or
maintainability of the view.
For example, if I need to display a piece of information for an admin,
but not a normal user then I have no problem doing the "if
current_user.admin?" check in a view:
<% if current_user.admin? %>
Foo bar baz
<% end %>
The check itself is already ultra-simple and it reads very well. What
value would we get from moving this to a helper method? It's currently
easy to open the view and know that "Foo bar baz" will only be
rendered for an admin. Does moving this to
"display_foo_bar_baz_for_admin" really give us anything?
There's a cost to creating a helper method for every one-off
condition. There's also a cost for turning every snippet of markup
that shows up in a simple view condition into a partial. The cost is
in the disconnect and separation that comes from doing separating
these pieces that go together as well as the organization nightmare of
a plethora of helper methods and partials.
I like extracting helpers when it provides more value than burden.
When it doesn't I will leave the small, ultra-simple logic in the
> Sent from my iPhone
> On Jun 6, 2009, at 12:00 AM, Hans de Graaff <hans at degraaff.org> wrote:
>> On Fri, 2009-06-05 at 22:40 -0500, David Chelimsky wrote:
>>> There is no support for rendering in helper specs as of yet. Please
>>> file a feature request if you think there should be. I have,
>>> personally, never rendered from a helper. Anybody else?
>> We do this for example to render a set of unrelated items into a single
>> timeline-based view. The helper sorts out the ordering and renders each
>> object in it using a specific partial.
>> rspec-users mailing list
>> rspec-users at rubyforge.org
> rspec-users mailing list
> rspec-users at rubyforge.org
http://www.mutuallyhuman.com (hire me)
http://ideafoundry.info/behavior-driven-development (first rate BDD training)
More information about the rspec-users