Skip to content

Instantly share code, notes, and snippets.

@sanjayginde
Last active December 18, 2015 14:49
Show Gist options
  • Save sanjayginde/5799903 to your computer and use it in GitHub Desktop.
Save sanjayginde/5799903 to your computer and use it in GitHub Desktop.
Example to 'disable' layouts in a Rails controller test. Uses an 'empty' layout, which can allow for testing that the the title tag and javascript is properly added...
-# Empty layout used as layout replacement for testing...
!!! 5
!= html5_haml_tag(:lang => 'en') do
%head
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
%title=h ((title=yield(:title)).blank?) ? "Contently" : "#{title} : Contently".html_safe
%body
=yield
=yield :javascript
=yield :jstemplates
describe PostsController
# Helper method...
def disable_layout
@controller.instance_eval do
def _process_options(options)
options[:layout] = '/layouts/empty.html'
end
end
end
# Call the helper method and render views...
before do
disable_layout
end
render_views
describe :show do
...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment