Eric M.
Eric M.

Reputation: 5529

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)
    content_for(:tagline) { %Q(<div class="tagline"><p>#{text}</p></div>).html_safe }
  end
end

Upvotes: 0

Views: 436

Answers (1)

iain
iain

Reputation: 16274

content_for doesn't return a string, it stores it somewhere so that it can be retrieved when you do yield :tagline.

Upvotes: 1

Related Questions