0

我在 application_helper.rb 中有一个简单的辅助方法,我正在尝试对其进行测试,但我一生都无法弄清楚我的规范失败的原因。我已经包含了下面的代码。规范打印出预期的“”得到了零,理智的响应?检查打印号 我错过了什么?

require 'spec_helper'

describe ApplicationHelper do
  describe "#tagline" do
    specify { helper.tagline('text').should == '<div class="tagline"><p>text</p></div>' }
    p helper.respond_to?(:tagline) ? "yes" : "no"
  end
end


------

module ApplicationHelper
  def tagline(text)
    content_for(:tagline) { %Q(<div class="tagline"><p>#{text}</p></div>).html_safe }
  end
end
4

1 回答 1

1

content_for 不返回字符串,它会将其存储在某处,以便在您返回时可以检索到它yield :tagline

于 2010-12-12T21:17:07.677 回答