Skip to content

Instantly share code, notes, and snippets.

@caulfield
Last active March 2, 2020 04:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caulfield/4e0feeb68213c20d43b2 to your computer and use it in GitHub Desktop.
Save caulfield/4e0feeb68213c20d43b2 to your computer and use it in GitHub Desktop.
Stub templates in rspec helper
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 here
it 'should render object' do
stub_template 'objects/_object.html.slim' => 'h1 object'
concat helper.render_object(object)
assert_select 'h1', text: 'object'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment