Last Updated: February 25, 2016
·
535
· caulfield

Right way to stub views in helper specs

No more allow(helper).to receive(:render)

This short gist show you how to add stub_template to helper tests


module HelperExamplesExtensions
  # Copy of stub_template from view specs
  # @see RSpec::Rails::ViewExampleGroup::ExampleMethods#stub_template
  def stub_template(hash)           view.view_paths.unshift(ActionView::FixtureResolver.new(hash))
  end
end

RSpec.configure do |config|
  config.include HelperExamplesExtensions, type: :helper
end

green example:

it 'should render object' do
   stub_template 'objects/_object.html.slim' => 'h1 object'
   concat helper.render_object(object)
   assert_select 'h1', text: 'object' 
end