geddy / model

Datastore-agnostic ORM in JavaScript
265 stars 55 forks source link

Why do the adapter tests drop tables in the before each #185

Open sugendran opened 10 years ago

sugendran commented 10 years ago

I'm writing an adapter for azure table storage and I noticed the tests delete tables in the before each. Why is this? Shouldn't they create the tables in the before and delete in the after?

mde commented 10 years ago

I'm not in a place where I can see the code, but I believe the beforeEach and afterEach just create and remove all the fixture instances, not the actual tables. We do this for atomicity, so we don't have tests depending on state set up in a previous test.

On Monday, April 14, 2014, Sugendran Ganess notifications@github.com wrote:

I'm writing an adapter for azure table storage and I noticed the tests delete tables in the before each. Why is this? Shouldn't they create the tables in the before and delete in the after?

Reply to this email directly or view it on GitHubhttps://github.com/geddy/model/issues/185 .

sugendran commented 10 years ago

From the mongo tests...

    adapter.once('connect', function () {
      adapter.dropTable(['Zooby', 'User'], next);
    });
    adapter.connect();

Which if I copy and paste to test my adapter I get errors because we're trying to drop tables that aren't there already.

mde commented 10 years ago

This may be old code. Probably doesn't break in Mongo because it doesn't actually have tables, just collections. The LevelDB tests might be a better example.

On Monday, April 14, 2014, Sugendran Ganess notifications@github.com wrote:

From the mongo tests...

adapter.once('connect', function () {
  adapter.dropTable(['Zooby', 'User'], next);
});
adapter.connect();

Which if I copy and paste to test my adapter I get errors because we're trying to drop tables that aren't there already.

Reply to this email directly or view it on GitHubhttps://github.com/geddy/model/issues/185#issuecomment-40421640 .

sugendran commented 10 years ago

level db tests do the same thing

mde commented 10 years ago

Okay, I've had a look at this. First off, the drops happen in the before/after -- the before and after are pretty much adapter-specific setup for each suite. The beforeEach/afterEach are mixed in from the shared adapter tests, and just create and destroy a bunch of fixture instances that each test can use.

I need to do some investigation to figure out why the Mongo and Level tests want those two particular collections removed at the end of their respective suites (and why the Level one wants it also done before running the suite -- that's really confusing).

But for your purposes, all you need to do is make sure your tests work. Do any adapter-specific setup in the 'before,' and teardown in the 'after.' The only thing that should be going on in beforeEach/afterEach is the creation/destruction of the instances.

Hope that helps.

I'm on vacation with the family for the next day or so -- but I'll check in again at the end of the day. The guys in IRC can likely help too, if there's time overlap when you're awake. :)

Matthew

On Mon, Apr 14, 2014 at 11:25 PM, Sugendran Ganess <notifications@github.com

wrote:

level db tests do the same thing

Reply to this email directly or view it on GitHubhttps://github.com/geddy/model/issues/185#issuecomment-40449595 .