Skip to content

Instantly share code, notes, and snippets.

@bravoecho
Last active August 29, 2015 14:03
Show Gist options
  • Save bravoecho/a9fd4b4674e1e01698df to your computer and use it in GitHub Desktop.
Save bravoecho/a9fd4b4674e1e01698df to your computer and use it in GitHub Desktop.
# spec/spec_helper.rb
module RSpec::Rails::ViewExampleGroup::ExampleMethods
def render_once(*args, &block)
_rendered = self.class.instance_variable_get(:'@__rendered_once__')
_doc = self.class.instance_variable_get(:'@__doc_once__')
_view = self.class.instance_variable_get(:'@__view_once__')
if _rendered && _view
@rendered = _rendered
@view = _view
else
render(*args, &block)
self.class.instance_variable_set(:'@__rendered_once__', rendered)
self.class.instance_variable_set(:'@__view_once__', view)
end
if _doc
@doc = _doc
else
@doc = self.class.instance_variable_set(:'@__doc_once__', Nokogiri::HTML(@rendered))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment