Skip to content

Instantly share code, notes, and snippets.

@cblunt
Created November 27, 2011 15:36
Show Gist options
  • Save cblunt/1397705 to your computer and use it in GitHub Desktop.
Save cblunt/1397705 to your computer and use it in GitHub Desktop.
Testing content_for Helper Methods with RSpec
# Solution from http://www.jamiepenney.co.nz/2011/09/23/testing-content_for-in-rails-3-x-helpers-with-rspec/
describe ApplicationHelper do
describe "title" do
it "should return an h2 tag with the given title" do
helper.title("Lorem Ipsum")
helper.content_for(:page_title).should eql "<h2>Lorem Ipsum</h2>"
end
it "should return the supplied block if a block was given" do
helper.title { "Some Block" }
helper.content_for(:page_title).should eql "Some Block"
end
end
end
@boddhisattva
Copy link

@cblunt Thanks, this was helpful. Didn't think that content_for could be called in the verify phase of a test using helper.content_for .

@hendragunz
Copy link

This is save my life. thanks

@thesunwave
Copy link

Thank you. It was come in handy.

@perryqh
Copy link

perryqh commented Nov 8, 2018

Using this now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment