Created
April 17, 2016 15:50
-
-
Save codebeige/86905eb7dd7cef33230223ae456fe2f0 to your computer and use it in GitHub Desktop.
Assign locals context-wide when testing partials with rspec-rails
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
RSpec.configure do |config| | |
config.include TemplateLocals, type: :view | |
end |
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 TemplateLocals | |
def assign_locals(locals) | |
@_default_locals = _default_locals.merge locals | |
end | |
private | |
def _default_locals | |
@_default_locals || {} | |
end | |
def _default_render_options | |
super.merge locals: _default_locals | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment