I want to write test for edit post I write something like:
Given I'm on "/post/1/edit" page
but in this time I haven't record with ID = 1, even if I created it in previous test开发者_JS百科
How to solve it?
Because it's a test database, you won't know what the id is exactly. I think you're better off to follow the edit link from the index after the post is created.
You could say:
Given a post exists
When I edit that post
And the steps defs could be:
Given /^a post exists$/ do
@post = Post.create!(:title => "...")
end
When /^I edit that post$/ do
visit edit_post_path(@post)
end
精彩评论