wildfireapp/zuora — pull request #3 by loz (2012-03-30 16:12:12+00:00)
Title: Made SOAP backend replaceable for tests

We found that it was difficult to write TDD using the SOAP backend without having to mock http and xml responses.

So we moved it all out into a connector which can be replaced. Then we wrote an SQLite in memory connector to allow simulating Zuora in the db. This allows you to populate using Factories, fixtures or whatever else using Zuora::Objects

This is done quite simply in a spec like so:

```ruby
before :each
Zuora::Objects::Base.connector_class = Zuora::SqliteConnector
Zuora::SqliteConnector.build_schema
end
```

This will build an in memory sqlite db with a schema based on the definitions in the Zuora::Objects defined.

Any tests after the before will have an empty db, and Zuora::Objects will use this.

The original behavior is unchanged, and simply factored out. If you want to restore the original behavior in a set of tests then use an around :each :

```ruby
around :each |example|
original = Zuora::Objects::Base.connector_class
Zuora::Objects::Base.connector_class = Zuora::SqliteConnector
Zuora::SqliteConnector.build_schema
example.run
Zuora::Objects::Base.connector_class = original
end
```

We found this to be perfect for TDD using this gem, and hope that it will prove useful to others too.