简体   繁体   English

如何写黄瓜测试?

[英]How to write cucumber test?

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 但这次我没有记录ID = 1,即使我在之前的测试中创建了它

How to solve it? 怎么解决呢?

Because it's a test database, you won't know what the id is exactly. 因为它是一个测试数据库,所以您将不知道ID到底是什么。 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: 步骤defs可以是:

Given /^a post exists$/ do
  @post = Post.create!(:title => "...")
end

When /^I edit that post$/ do
  visit edit_post_path(@post)
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM