2

我正在为我的 RoR 应用程序编写一些 Cucumber 功能,这些功能将记录插入数据库,然后向我的 XML API 发送查询。由于我的请求(硬编码 XML)的性质,我需要知道一行的 ID 是什么。这是我的场景:

Scenario: Client requests call info
  Given There is a call like:
    | id         | caller_phone_number |
    | 1          | 3103937123          |
  When I head over to call info
  And Post this XML:
    """
    <?xml version="1.0" encoding="UTF-8"?>
    <request-call-info>
      <project-code>1000000001</project-code>
    </request-call-info>
    """
  Then The call info should match
  And The status code should be 0

我已经用我的 _test 数据库设置了 Cuke,而且我还注意到它并没有在运行我的功能之前重置所有表。

设置它的正确方法是什么?谢谢!

4

1 回答 1

1

首先,请原谅我,因为这将是一个大脑转储,但希望它应该帮助或至少给你一些想法:

你可以像这样重写你的场景:

Scenario: Client requests call info
    Given There is a call with the phone number "3102320"
    When I post "request-call-info" xml to "call info" for the phone number "3102320"
    Then the call info for phone number "3102320" should match
        And the status code for phone number "3102320" should be 0

这样,您可以通过不是主键的属性来引用记录。

你在使用固定装置吗?如果是这样,您可以在那里明确设置记录的 ID。

根据您的应用程序,您可能能够使用内存中的 sqlite3 数据库运行测试。

于 2009-10-22T22:51:28.477 回答