Skip to content

Instantly share code, notes, and snippets.

@jferris
Created August 5, 2009 21:38
Show Gist options
  • Select an option

  • Save jferris/162991 to your computer and use it in GitHub Desktop.

Select an option

Save jferris/162991 to your computer and use it in GitHub Desktop.
module PostHelpers
def stub_post(post_attrs = {})
post_attrs = {
:to_param => '1',
:published? => true,
:title => 'a title'
}.update(post_attrs)
stub('a post', post_attrs)
end
def stub_post!(post_attrs = {})
returning stub_post do |post|
Post.stubs(:find => post)
end
end
end
describe PostsController do
include PostHelpers
it "should show a published post on GET show" do
post = stub_post!
get :show, :id => post.to_param
Post.should have_received(:find).with(post.to_param)
post.should have_received(:published?)
should render_template(:show)
should assign_to(:post).with(post)
end
end
describe "/posts/show" do
include PostHelpers
it "should a post" do
assigns[:post] = stub_post
render '/posts/show'
template.should have_tag('h1', assigns[:post].title)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment