On Nov 3, 2011, at 4:07 PM, Patrick J. Collins wrote:

>> So, I am writing tests for a presenter class that outputs html markup.
>> 
> Actually now that I am thinking about it..  Would you guys recommend that I 
> use
> something like Nokogiri to parse the content and test for things like number 
> of
> children, classes, ids, etc, rather than just comparing the raw HTML?

Yes, definitely. Also you might be interested in 
https://github.com/nakajima/elementor although I haven't used it in a long time 
so I don't know how up to date it is.

As far as your other question goes about how to use presenters, you probably 
don't want them emitting HTML. Instead you want the presenter to provide a 
simpler interface to some commonly accessed data that you don't think belongs 
on the model. An example might be

class UserPresenter
  def initialize(user)
    @user = user
  end

  def full_name
    @user.first_name + ' ' + @user.last_name
  end
end

Ignoring whether this is an appropriate case for using a presenter, you can see 
what I'm accomplishing here. And hopefully you can imagine it being more useful 
if there are multiple models involved.

A presenter is basically the facade pattern used specifically for presentation 
logic.

Pat

http://c2.com/cgi/wiki?FacadePattern
http://blog.jayfields.com/2007/03/rails-presenter-pattern.html
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to