Any ideas how I would go about writing specs for views which make use of content_for? I''d like, for example, to be able to specify that ABC view places XYZ in the sidebar, which I do using content_for(:sidebar). Am I missing something obvious? Kyle
On 5/23/07, Kyle Hargraves <philodespotos at gmail.com> wrote:> Any ideas how I would go about writing specs for views which make use > of content_for? > > I''d like, for example, to be able to specify that ABC view places XYZ > in the sidebar, which I do using content_for(:sidebar). > > Am I missing something obvious? > > KyleI have the same problem, several of my views use content_for to populate a sidebar. How can I write examples for them? / CJ
What we usually do in this case is render the view with the layout and then check the contents of the sidebar div. However, this does lead to having to stub out additional things you don''t care about in your example. If anyone has a better plan I''d like to know, too. Moses On 6/4/07, Carl-Johan Kihlbom <kihlbom at gmail.com> wrote:> > On 5/23/07, Kyle Hargraves <philodespotos at gmail.com> wrote: > > Any ideas how I would go about writing specs for views which make use > > of content_for? > > > > I''d like, for example, to be able to specify that ABC view places XYZ > > in the sidebar, which I do using content_for(:sidebar). > > > > Am I missing something obvious? > > > > Kyle > > I have the same problem, several of my views use content_for to > populate a sidebar. How can I write examples for them? > > / CJ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070604/4a88e440/attachment-0001.html
On 6/4/07, Moses Hohman <moses.hohman at gmail.com> wrote:> What we usually do in this case is render the view with the layout and then > check the contents of the sidebar div. However, this does lead to having to > stub out additional things you don''t care about in your example. If anyone > has a better plan I''d like to know, too. > > MosesMoses, this doesn''t work for me. I tried the following: response.should have_tag("div#sidebar") That didn''t work (no matching tag found). I also tried similar approaches to matching tags within the sidebar, without any luck. Any ideas?
Okey, here''s how I solved it: In spec_helper.rb I defined the following method: def content_for(name) response.template.instance_variable_get("@content_for_#{name}") end Then in my examples I can just use this: content_for(:sidebar).should have_tag(''ul.people li.person'', 2) If anyone has a cleaner solution, please let me know. / CJ