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
Written by sergey kuchmistov
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#