Created
November 27, 2011 15:36
-
-
Save cblunt/1397705 to your computer and use it in GitHub Desktop.
Testing content_for Helper Methods with RSpec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This is save my life. thanks
Thank you. It was come in handy.
Using this now. Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@cblunt Thanks, this was helpful. Didn't think that
content_for
could be called in the verify phase of a test usinghelper.content_for
.