[rspec-users] problems matching generated html output...

Pat Maddox patmaddox at me.com
Thu Nov 3 20:47:42 EDT 2011

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

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

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.



More information about the rspec-users mailing list