zendesk/curly

How to test a presenter?

diegotoral opened this issue · 4 comments

Hi folks!

I'm trying to test (with RSpec) a simple presenter class that uses a bunch of helper methods (button_to, t and sign_out_url) and I don't know how to setup the presenter in a way it access these methods.

class Dashboard::IndexPresenter < Curly::Presenter
  def sign_out
    button_to t('layouts.application.sign_out'), sign_out_url, method: :delete
  end
end

Thanks!

dasch commented

Typically, you'd include RSpec::Rails::ViewExampleGroup into your spec:

describe Dashboard::IndexPresenter do
  include RSpec::Rails::ViewExampleGroup
  let(presenter) { described_class.new(view, view_assigns) }
end

Let me know if that works for you.

That worked for me! Thanks for the answer @dasch!

dasch commented

No problem :-)

dasch commented

@diegotoral I'm adding directly RSpec support in the next Curly release: #149.