开发者

How to write cucumber test?

开发者 https://www.devze.com 2023-04-01 05:22 出处:网络
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百科

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
0

精彩评论

暂无评论...
验证码 换一张
取 消