Last active
March 2, 2020 04:27
-
-
Save caulfield/4e0feeb68213c20d43b2 to your computer and use it in GitHub Desktop.
Stub templates in rspec helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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