Created
November 26, 2008 22:29
-
-
Save jqr/29614 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# How I might test this helper | |
module SomeHelper | |
def title(page_title) | |
content_for(:title) { page_title } | |
end | |
end | |
describe SomeHelper | |
include SomeHelper | |
describe "title" do | |
# We've made a fake content_for that is super easy to test because it | |
# immediately yields the block. | |
def content_for(section) | |
yield | |
end | |
# ensure it puts it in the right "section" | |
it "should call content_for with section title" do | |
should_receive(:content_for).with(:title) | |
title('testing') | |
end | |
# ensure the argument is passed | |
it "should call content_for with the page_title attribute in a block" do | |
# We could figure out where content_for stores it's blocks but we'd be | |
# coupling ourselves to it's implementation. We can trust that content_for | |
# works, we only need to test our usage of it. | |
title('testing').should == 'testing' | |
end | |
# that's all the logic in the method... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment