【发布时间】:2018-08-04 15:37:08
【问题描述】:
您好,我正在使用 ruby-2.5.1 和 Rails 5 开发一个 ROR 项目。我有一个注册请求的 api 如下:
{
"data": {
"type": "users",
"attributes": {
"email": "test@gmail.com",
"password": "passwor",
"password-confirmation" : "password"
}
}
}
我想在我的 rails 应用程序中用黄瓜测试这个注册 api。 我从来没有做过黄瓜我试过的是:-
我的功能文件
Feature: Registration Endpoint
Scenario: User registration
When I send a POST request to "/api/registrations" with the following:
| email | test@gmail.com |
| password | password |
| password_confirmation | password |
Then the response status should be "200"
我的 steps.rb 文件:
When("I send a POST request to {string} with the following:") do |string, table|
# table is a Cucumber::MultilineArgument::DataTable
pending # Write code here that turns the phrase above into concrete actions
end
但我不确定如何实施步骤。请帮我。提前致谢。
【问题讨论】:
-
你为什么用黄瓜而不是RSpec?在我从事的所有项目中,我都使用 cucumber 来测试前端(业务逻辑),即登录某处,单击按钮显示某些内容,编辑记录。对于 API/请求规范,使用 RSpec 更容易。
-
是的,我使用 rspec 进行单元测试。但客户想要这个 api 的黄瓜。我们将调用其他 api 进行注册,我们不想使用现有的注册 api。
-
反正不急的话,明天我可以帮你
-
@MrShemek 你在吗?