Jonathan Rochkind
2010-Jul-13 22:43 UTC
[rspec-users] spec for a rails helper that renders a partial template
So the stock answer to this is "don''t do it". But I''m in a situation where it''s really what I want to do to test what I want to test. a helper method: def some_helper render(:partial => "some/partial", :locals => {:some => some} end or even: def some_helper content = "" some_loop.each do |something| content << render(:partial => "some/partial", :locals => {:something => something} end end Is there any way to write a spec where I can test this kind of helper, and it really will render it''s partial(s), and I can really write specs against the return strings? Any way at all? I''ve been trying for a while with no success. Thanks for any advice. Jonathan -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2010-Jul-13 23:02 UTC
[rspec-users] spec for a rails helper that renders a partial template
On Jul 13, 2010, at 5:43 PM, Jonathan Rochkind wrote:> So the stock answer to this is "don''t do it". But I''m in a situation > where it''s really what I want to do to test what I want to test. > > a helper method: > > def some_helper > render(:partial => "some/partial", :locals => {:some => some} > end > > or even: > > def some_helper > content = "" > some_loop.each do |something| > content << render(:partial => "some/partial", :locals => > {:something => something} > end > end > > Is there any way to write a spec where I can test this kind of helper, > and it really will render it''s partial(s), and I can really write specs > against the return strings? > > Any way at all? I''ve been trying for a while with no success. Thanks for > any advice.RSpec version?
Jonathan Rochkind
2010-Jul-13 23:05 UTC
[rspec-users] spec for a rails helper that renders a partial template
David Chelimsky wrote:> On Jul 13, 2010, at 5:43 PM, Jonathan Rochkind wrote: > >> >> against the return strings? >> >> Any way at all? I''ve been trying for a while with no success. Thanks for >> any advice. > > RSpec version?Good point. Rails2, rspec 1.3.0. Thanks. -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2010-Jul-13 23:41 UTC
[rspec-users] spec for a rails helper that renders a partial template
On Jul 13, 2010, at 6:05 PM, Jonathan Rochkind wrote:> David Chelimsky wrote: >> On Jul 13, 2010, at 5:43 PM, Jonathan Rochkind wrote: >> >>> >>> against the return strings? >>> >>> Any way at all? I''ve been trying for a while with no success. Thanks for >>> any advice. >> >> RSpec version? > > Good point. Rails2, rspec 1.3.0. Thanks.Do you know about integrate_views? http://rspec.info/rails/writing/controllers.html
Jonathan Rochkind
2010-Jul-13 23:59 UTC
[rspec-users] spec for a rails helper that renders a partial template
David Chelimsky wrote:> On Jul 13, 2010, at 6:05 PM, Jonathan Rochkind wrote: > > Do you know about integrate_views? > > http://rspec.info/rails/writing/controllers.htmlI read about it in my quest through the documentation for a solution. This isn''t actually a controller spec I''m trying to write, it''s a helper spec. If I actually set it up as a helper spec... I don''t seem to get "integrate_views", if I try to call it I get a method missing exception. Can I set it up as a controller spec, but then somehow still spec a helper method, rather than a controller? I thought of that, and tried to do it, but couldn''t quite figure out how to do that. Any advice? Jonathan -- Posted via http://www.ruby-forum.com/.
David Chelimsky
2010-Jul-15 13:16 UTC
[rspec-users] spec for a rails helper that renders a partial template
On Jul 13, 2010, at 6:59 PM, Jonathan Rochkind wrote:> David Chelimsky wrote: >> On Jul 13, 2010, at 6:05 PM, Jonathan Rochkind wrote: >> >> Do you know about integrate_views? >> >> http://rspec.info/rails/writing/controllers.html > > I read about it in my quest through the documentation for a solution. > > This isn''t actually a controller spec I''m trying to write, it''s a helper > spec. If I actually set it up as a helper spec... I don''t seem to get > "integrate_views", if I try to call it I get a method missing exception. > > Can I set it up as a controller spec, but then somehow still spec a > helper method, rather than a controller? I thought of that, and tried > to do it, but couldn''t quite figure out how to do that. Any advice?I don''t think there''s a good way to do that in RSpec-1. In RSpec-2, however, you should be able to do this in a regular helper spec. HTH, David> Jonathan
Jonathan Rochkind
2010-Jul-15 14:57 UTC
[rspec-users] spec for a rails helper that renders a partial template
David Chelimsky wrote:> > I don''t think there''s a good way to do that in RSpec-1. In RSpec-2, > however, you should be able to do this in a regular helper spec.Okay, thanks. Can''t wait until I get my app migrated to Rails3, glad that Rspec has improved in flexibility in a great many ways, it appears, in Rspec2/Rails3. -- Posted via http://www.ruby-forum.com/.