Validating Nested Layout Helper with RSpec and Haml

In ApplicationHelper, I have this code:

def inside_layout layout = 'application', &block
  @template.instance_variable_set '@content_for_layout', capture(&block)
  concat \
    @template.render :file => "layouts/#{layout}", :use_full_path => true
end

which behaves as follows:

application.html.haml:

!!!
%html
  %head
    ...
  %body
    = yield

common_pages.html.haml:

- inside_layout do
  ...

Then the layout_pages layout is displayed in the application layout.

How can I check this helper with RSpec?

When I call in_layout from the spec file:

helper.inside_layout { }

RSpec says the error:

ActionView::MissingTemplate in 'ApplicationHelper inside_layout should render nested layout within application layout'
Missing layout layouts/application.erb in view path

But the application works fine.

+5
source share
1 answer

You cannot use render calls directly in rspecs for helpers, since the view path is not set in this context.

Suggestions:

  • use layout to invoke rendering.
  • - -, - inside_layout.

: http://pivotallabs.com/users/john/blog/articles/854-friday-5-11-standup-view-paths-in-rspec-helper-tests-write-attribute-for-type-inference-

+3

All Articles