Skip to content

Instantly share code, notes, and snippets.

@bclennox
Created January 24, 2009 04:28
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 bclennox/51333 to your computer and use it in GitHub Desktop.
Save bclennox/51333 to your computer and use it in GitHub Desktop.
describe ChildrenController do
before(:each) do
@parent = mock(Parent, :id => 1)
@children = mock("children")
@parent.stub!(:children).and_return(@children)
Parent.should_receive(:find).with(@parent.id.to_s).and_return(@parent)
end
def expect_children_build
@children.should_receive(:build).with(any_args()).and_return(@child)
end
def expect_utilities_find
@children.should_receive(:find).with(@child.id.to_s).and_return(@child)
end
describe "GET :new" do
def shared_request
get :new, :parent_id => @parent.id
end
before(:each) do
@child = stub_new(Child)
expect_children_build
end
it_should_assign :child
it_should_render_template "new"
end
describe "GET :edit" do
def shared_request
get :edit, :parent_id => @parent.id, :id => @child.id
end
before(:each) do
@child = stub_edit(Child)
expect_children_find
end
it_should_assign :child
it_should_render_template "edit"
end
# ... and so forth ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment