David Chelimsky
2009-Jun-06 03:40 UTC
[rspec-users] Missing template in helper specs with a render
On Thu, Jun 4, 2009 at 8:41 PM, Charlie Bowman <charlesmbowman at gmail.com> wrote:> I have a helper method that does a "render :partial".? The method works fine > within the app (Rails 2.3.2).? In rspec (1.2.6) I get an error ("Missing > template /comments/_comment.erb in view path" > It seems that rspec when running helper tests doesn''t set the view_path so > rails doens''t know where to look for the templates.? Is there a way to run > helper specs with the same setup as controller specs?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?> > Charlie > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Matt Wynne
2009-Jun-06 11:16 UTC
[rspec-users] Missing template in helper specs with a render
On 6 Jun 2009, at 04:40, David Chelimsky wrote:> On Thu, Jun 4, 2009 at 8:41 PM, Charlie Bowman <charlesmbowman at gmail.com > > wrote: >> I have a helper method that does a "render :partial". The method >> works fine >> within the app (Rails 2.3.2). In rspec (1.2.6) I get an error >> ("Missing >> template /comments/_comment.erb in view path" >> It seems that rspec when running helper tests doesn''t set the >> view_path so >> rails doens''t know where to look for the templates. Is there a way >> to run >> helper specs with the same setup as controller specs? > > 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?Yep, I quite often have helper methods that wrap a call to render_partial, but they''d just get tested as part of the main view render, or by the cukes. Matt Wynne http://blog.mattwynne.net http://www.songkick.com
Charlie Bowman
2009-Jun-06 22:34 UTC
[rspec-users] Missing template in helper specs with a render
I consider an if statement in the view layer a bug. 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. 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. > > Hans > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Zach Dennis
2009-Jun-07 05:02 UTC
[rspec-users] Missing template in helper specs with a render
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 application''s behaviour.> 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 view, Zach> > 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. >> >> Hans >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Zach Dennis http://www.continuousthinking.com (personal) http://www.mutuallyhuman.com (hire me) http://ideafoundry.info/behavior-driven-development (first rate BDD training) @zachdennis (twitter)
Charlie Bowman
2009-Jun-07 08:24 UTC
[rspec-users] Missing template in helper specs with a render
Sent from my iPhone On Jun 6, 2009, at 10:02 PM, Zach Dennis <zach.dennis at gmail.com> wrote:> 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 > application''s behaviour.Absolutely true. Not really a bug but I find it helpful to treat it as such.> > >> 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 > <% enddef foo_message "foo bar baz" if current_user.admin? end That''s how I handle that. If for no other reason but easier testing.> > > 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 > view, > > Zach > >> >> 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. >>> >>> Hans >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Zach Dennis > http://www.continuousthinking.com (personal) > http://www.mutuallyhuman.com (hire me) > http://ideafoundry.info/behavior-driven-development (first rate BDD > training) > @zachdennis (twitter) > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Rick DeNatale
2009-Jun-07 15:54 UTC
[rspec-users] Missing template in helper specs with a render
On Sun, Jun 7, 2009 at 4:24 AM, Charlie Bowman<charlesmbowman at gmail.com> wrote:> On Jun 6, 2009, at 10:02 PM, Zach Dennis <zach.dennis at gmail.com> wrote:>> 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 > > def foo_message > ?"foo bar baz" if current_user.admin? > end > > That''s how I handle that. If for no other reason but easier testing.But that refactoring is less intention revealing since it hides the fact than only admins will see that message. If I couldn''t come up with a better name for foo_message which revealed that, I''d probably prefer leaving the if test in the view. Resolving the tensions between things like "dumb views" and "intention revealing names" is why they pay us the big bucks! <G> -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale
Charlie Bowman
2009-Jun-07 17:52 UTC
[rspec-users] Missing template in helper specs with a render
Sent from my iPhone On Jun 7, 2009, at 8:54 AM, Rick DeNatale <rick.denatale at gmail.com> wrote:> On Sun, Jun 7, 2009 at 4:24 AM, Charlie Bowman<charlesmbowman at gmail.com > > wrote: >> On Jun 6, 2009, at 10:02 PM, Zach Dennis <zach.dennis at gmail.com> >> wrote: > >>> 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 >> >> def foo_message >> "foo bar baz" if current_user.admin? >> end >> >> That''s how I handle that. If for no other reason but easier testing. > > But that refactoring is less intention revealing since it hides the > fact than only admins will see that message. > > If I couldn''t come up with a better name for foo_message which > revealed that, I''d probably prefer leaving the if test in the view. > > Resolving the tensions between things like "dumb views" and "intention > revealing names" is why they pay us the big bucks! <G> >Agreed. Should be def foo_message_if_admin And yes I know im being extreme with my view on conditional logic in views. I''ve found it very helpful to think this way about my views. Just by refactoring old code this way I''ve found and fixed bugs that hadn''t even surfaced yet.> -- > Rick DeNatale > > Blog: http://talklikeaduck.denhaven2.com/ > Twitter: http://twitter.com/RickDeNatale > WWR: http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn: http://www.linkedin.com/in/rickdenatale > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Alex Pressberg
2010-Aug-24 09:19 UTC
[rspec-users] Missing template in helper specs with a render
Yes! We do use render in helpers to a great extent and are bitten by the "missing template in view path" error too. Any workarounds? Can the view path be easily fixed for helper specs in Rspec 1.3? Does Rspec 2 already support this? Cheers, Alex David Chelimsky wrote:> On Thu, Jun 4, 2009 at 8:41 PM, Charlie Bowman > <charlesmbowman at gmail.com> wrote: >> I have a helper method that does a "render :partial".? The method works fine >> within the app (Rails 2.3.2).? In rspec (1.2.6) I get an error ("Missing >> template /comments/_comment.erb in view path" >> It seems that rspec when running helper tests doesn''t set the view_path so >> rails doens''t know where to look for the templates.? Is there a way to run >> helper specs with the same setup as controller specs? > > 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?-- Posted via http://www.ruby-forum.com/.
Craig Demyanovich
2010-Aug-24 13:26 UTC
[rspec-users] Missing template in helper specs with a render
On Tue, Aug 24, 2010 at 5:19 AM, Alex Pressberg <lists at ruby-forum.com>wrote:> Yes! We do use render in helpers to a great extent and are bitten by the > "missing template in view path" error too. Any workarounds? Can the view > path be easily fixed for helper specs in Rspec 1.3? > Does Rspec 2 already support this? >If you''re doing it, it''s obviously possible, but it feels wrong to me. I think of a helper as a small piece of code that helps me decide what to render, gives me a CSS class name based on some condition, gives me a small chunk of markup whose generation would clutter up the view, etc. Have you considered that, though the framework allows you to do this, it may not be a good approach? In other words, instead of looking for a workaround, would it make more sense (at least in the long term) to change your application? I''m sorry I can''t offer actual help w/ current tools. I''m curious if Rails 3 still supports this or if RSpec 2 will support it. Regards, Craig> David Chelimsky wrote: > > On Thu, Jun 4, 2009 at 8:41 PM, Charlie Bowman > > <charlesmbowman at gmail.com> wrote: > >> I have a helper method that does a "render :partial".? The method works > fine > >> within the app (Rails 2.3.2).? In rspec (1.2.6) I get an error ("Missing > >> template /comments/_comment.erb in view path" > >> It seems that rspec when running helper tests doesn''t set the view_path > so > >> rails doens''t know where to look for the templates.? Is there a way to > run > >> helper specs with the same setup as controller specs? > > > > 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?-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100824/75ef3d38/attachment-0001.html>