嗨,我正在做一个使用ruby-2.5.1和Rails 5的ROR项目。我有一个注册请求的api如下:
{
"data": {
"type": "users",
"attributes": {
"email": "test@gmail.com",
"password": "passwor",
"password-confirmation" : "password"
}
}
}我想在我的rails应用程序中使用cucumber测试这个registartion 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但我不确定如何实现这些步骤。请帮帮我。提前谢谢。
发布于 2018-08-06 02:01:55
我会这样做:
When(/^I send a POST request to "(.*)" with the following:$/) do |endpoint, table|
page.driver.post(endpoint, table.rows_hash)
end
Then(/^the response status should be "(.*)"$/) do |response_code|
expect(page.status_code).to eq(response_code.to_i)
end在步骤定义中,您始终可以对binding.pry进行调试,并使用save_and_open_page在浏览器中显示结果。我希望它能有所帮助!
https://stackoverflow.com/questions/51687121
复制相似问题