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",
member_context_path(member, context)))
functions.each do | function |
case function.name
when "ManageZone"
contents << content_tag(:li, link_to("Manage zone",
edit_member_context_path(member, context)))
when "RemoveZone"
....
'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!
Thanks.
On 5 June, 22:36, Stephen Eley <[email protected]> wrote:
> On Fri, Jun 5, 2009 at 4:53 PM, Charlie Bowman<[email protected]>
> 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 ([email protected])
> ESCAPE POD - The Science Fiction Podcast Magazine
> http://www.escapepod.org
> _______________________________________________
> rspec-users mailing list
> [email protected]http://rubyforge.org/mailman/listinfo/rspec-users
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users