我正在运行Rails 3.1.1,RSpec 2.7.0和HAML 3.1.3.
说我有以下视图文件:
应用程序/视图/布局/ application.html.haml!!!
%html
%head
%title Test
= stylesheet_link_tag "application"
= javascript_include_tag "application"
= csrf_meta_tags
%body
= content_for?(:content) ? yield(:content) : yield
Run Code Online (Sandbox Code Playgroud)
应用程序/视图/布局/ companies.html.haml
- content_for :content do
#main
= yield :main
#sidebar
= yield :sidebar
= render :template => 'layouts/application'
Run Code Online (Sandbox Code Playgroud)
应用程序/视图/公司/ index.html.haml
- content_for :main do
%h1 MainHeader
- content_for :sidebar do
%h1 SidebarHeader
Run Code Online (Sandbox Code Playgroud)
以下spec文件:
规格/视图/公司/ index_spec.rbrequire 'spec_helper'
describe 'companies/index.html.haml' do
it 'should show the headers' do
render
rendered.should contain('MainHeader')
rendered.should contain('SidebarHeader')
end …Run Code Online (Sandbox Code Playgroud)