为什么在第一个方案黄瓜测试后没有记录?

时间:2018-09-06 17:02:34

标签: ruby-on-rails cucumber

嗨,我正在研究Rails项目,我必须使用Cucumber测试API。我在第一种情况下创建一条记录,在第二种情况下我在验证该记录,但是在执行第二种情况下,先前创建的记录不在数据库中。

功能文件:

Feature: Bill Reminder

  Scenario: Validate POST bill_reminder API with valid parameters
    When I make POST bill_reminder API call
    Then It should return success for bill_reminder

  Scenario: Validate GET bill_reminder API with valid login token
    when I send a GET request to bill reminder details
    Then the json response should have title bill reminder

步骤文件:

When(/^I make POST bill_reminder API call$/) do
  @url = 'http://example.com/api/bill_reminders'
  @params = {
              data: {
                type: "bill-reminders",
                attributes: {
                  title: "bill reminder",
                  all_day: "0",
                  start_date: "1409175049",
                  end_date: "1409175049"
                }
              }
            }
  @login_token = 'nev4hPOqyVCXGnOXLYPUhQ'
  @user_id = 402
end

Then(/^It should return success for bill_reminder$/) do
  header 'login_token', @login_token
  header 'user-id', @user_id
  response = post @url, @params

  response_body = JSON response.body
  @id = response_body['data']['id']
  expect(response.status).to eq(200)
end

When(/^I send a GET request to bill reminder details$/) do
  @url = "http://example.com/api/bill_reminders/#{@id}"
  @user_id = 402
  @login_token = 'nev4hPOqyVCXGnOXLYPUhQ'
end

Then(/^the json response should have title bill reminder$/) do
  header 'login_token', @login_token
  header 'user-id', @user_id

  response = get @url
  expect(response.status).to eq(200)
end

在这里,当我调试第二个方案“我发送GET请求以记帐提醒详细信息”时,在第一个方案中创建的记录不存在。请帮助我修复它。预先感谢。

0 个答案:

没有答案