Rspec testing application_helper.rb
I have a simple helper method in application_helper.rb that I am trying to test and can't for the life of me figure out why my spec is failing. I've included the code below. The spec prints out expected "" got nil, and the sanity respond_to? check prints no. What am I missing?
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)
con开发者_StackOverflow中文版tent_for(:tagline) { %Q(<div class="tagline"><p>#{text}</p></div>).html_safe }
end
end
content_for doesn't return a string, it stores it somewhere so that it can be retrieved when you do yield :tagline
.
精彩评论