Reputation: 3216
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
How to solve it?
Upvotes: 0
Views: 331
Reputation: 11086
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
Upvotes: 1
Reputation: 13621
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.
Upvotes: 2