小编Tom*_*tia的帖子

Rails 3 + Rspec 2:测试content_for

我正在运行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.rb
require '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)

haml rspec2 ruby-on-rails-3

14
推荐指数
2
解决办法
4824
查看次数

标签 统计

haml ×1

rspec2 ×1

ruby-on-rails-3 ×1