Question

I am writing some Cucumber features for my RoR app that insert records into the database then send a query to my XML API. Because of the nature of my requests (hardcoded XML) I need to know what the ID of a row is going to be. Here is my Scenario:

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

I've got Cuke set up with my _test database, and I also noticed that it isn't resetting all of the tables prior to running my features.

What is the right way to set this up? Thanks!

Was it helpful?

Solution

Firstly, forgive me as this is going to be a bit of a brain dump, but hopefully it should help or at least give you some ideas:

You could rewrite your scenario like this:

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

This way you can refer to the record by an attribute that isn't the primary key.

Are you using fixtures? If so you can set the ID for the record there explicitly.

Depending on your application you might be able to run your tests using an in memory sqlite3 database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top