[rspec-users] Driving Out A View - Am I specifying too much?
Lee.Longmore at googlemail.com
Sat Jun 6 01:23:02 EDT 2009
Thank you everyone for your helpful insights.
I had already gone down the route suggested by Zach but it was
nevertheless very re-assuring to have my approach validated as I am a
newbie to RSpec. I did however consolidate my expectations e.g.:
context "when the member is a privileged member of a zone" do
it "should display links for functions (Create sub-zone, Invite
member, Invite non-member)" do
.... "a" tag expectations for each expected link as well as the
use of :count to check the number of links e.g. function_links.should
have_selector("li", :count => 4)
To Charlie's point, I do call a helper from my view to avoid
cluttering the view e.g.
def function_links_for(functions, member, context)
contents = content_tag(:li, link_to("Enter zone",
functions.each do | function |
contents << content_tag(:li, link_to("Manage zone",
'functions' is an array of Function objects valid for member and his/
her role for a given context (item).
But I opted not to test this explicitly but, I confess, on the basis
that Chapter 22 "Rails Helpers" in The RSpec Book is not yet written!
On 5 June, 22:36, Stephen Eley <sfe... at gmail.com> wrote:
> On Fri, Jun 5, 2009 at 4:53 PM, Charlie Bowman<charlesmbow... at gmail.com> wrote:
> > I never spec my views. I also never put conditional logic in the views. If
> > you have links that should show up sometimes and not others why not just
> > move that logic into a helper or other associated class and test the method?
> Good point. But if one is really being completionist, it still makes
> sense to check that the view is calling that helper.
> Have Fun,
> Steve Eley (sfe... at gmail.com)
> ESCAPE POD - The Science Fiction Podcast Magazine
> rspec-users mailing list
> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
More information about the rspec-users