Skip to content

Instantly share code, notes, and snippets.

@jqr
Created November 26, 2008 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jqr/29614 to your computer and use it in GitHub Desktop.
Save jqr/29614 to your computer and use it in GitHub Desktop.
# 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