[rspec-users] how to spec views

Andrew WC Brown omen.king at gmail.com
Mon Oct 1 01:26:15 EDT 2007


I'm trying to spec a view but haven't done much view specing.

This view render different partials depending on authentication of the user:
annon, admin, player
So I I'll write if conditionals in the view with the partials


  it "should render signup propaganda for annon users trying to view games"
do
    render "/games/index.rhtml"
    @logged_in?.should eql(false)
    response.should render_template('_signup_propaganda')
  end

Now for my partial I know it'll be wrapped all in a div with a
class="signup_propaganda"
Should I be testing for that instead? Can I write expectations for partials
similar to above?

When your specing views are you testing for the outputted results?

  it "should render signup propaganda for annon users trying to view games"
do
    render "/games/index.rhtml"
    @logged_in?.should eql(false)
    response.should have_tag(div, "class=/"signup_propaganda/"")
  end

How should I be writing my spec?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071001/86fc22d4/attachment.html 


More information about the rspec-users mailing list