views:

86

answers:

1

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!

+1  A: 

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.

jonnii
Had no idea I could use fixtures with Cucumber, just found that page in the Cucumber wiki. Thanks! Makes my life a whole lot easier.
Bloudermilk
For anyone else that might need it: http://wiki.github.com/aslakhellesoy/cucumber/fixtures
Bloudermilk
I use factory girl with cucumber, I find it easier than fixtures.
jonnii