Skip to content

Instantly share code, notes, and snippets.

@codebeige
Created April 17, 2016 15:50
Show Gist options
  • Save codebeige/86905eb7dd7cef33230223ae456fe2f0 to your computer and use it in GitHub Desktop.
Save codebeige/86905eb7dd7cef33230223ae456fe2f0 to your computer and use it in GitHub Desktop.
Assign locals context-wide when testing partials with rspec-rails
RSpec.configure do |config|
config.include TemplateLocals, type: :view
end
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