I’m learning rails and have come across a problem with an Rspec. I have the following test for a controller:
describe PostsController, "creating a new post" do
it "should redirect and show the post" do
Post.stub!(:save).and_return(true)
post "create"
response.should redirect_to :action => "show"
end
end
When I run this test I get the following failure:
PostsController creating a new post should redirect and show the post
Failure/Error: response.should redirect_to :action => "show"
ActionController::RoutingError:
No route matches {:action=>"show", :controller=>"posts"}
# ./spec/controllers/posts_controller_spec.rb:8:in `block (2 levels) in <top (required)>'
Yet my when I check my routes I see my show action for my posts controller:
post GET /posts/:id(.:format) {:action=>"show", :controller=>"posts"}
I’m probably missing something very simple but struggling to find it.
Thanks.
You forgot the
id.I usually write