BDD with Cucumbers and MySQL - Auto Growth Problems

I am writing some Cucumber functions for my RoR application that insert records into a database and then send a request to my XML API. Due to the nature of my requests (hardcoded XML) I need to know what the string id will be. Here's 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 have Cuke configured with my _test database and I also noticed that it does not reload all tables before running my functions.

What's the correct way to fix this? Thank!

+2


source to share


1 answer


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

You can rewrite your script 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 a record by an attribute that is not primary.

Do you use lamps? If so, you can set the id for the entry there explicitly.

Depending on your application, you can run your tests using an in-memory sqlite3 database.

+1


source







All Articles