2010-12-12 165 views
0

我在application_helper.rb中有一個簡單的幫助方法,我試圖測試,並且不能爲我的生活弄清楚爲什麼我的規範失敗。我已經包含下面的代碼。該規範打印出預期的「」無零,而理智respon_to?檢查打印號碼。我錯過了什麼?Rspec測試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 

回答

1

content_for不返回一個字符串,它存儲的地方,以便它可以當你yield :tagline檢索。