Skip to content

Instantly share code, notes, and snippets.

@davybrion
Created September 15, 2012 16:55
Show Gist options
  • Save davybrion/3728820 to your computer and use it in GitHub Desktop.
Save davybrion/3728820 to your computer and use it in GitHub Desktop.
code snippets for "Take Advantage Of Your BDD Framework" post
describe('given an existing customer', function() {
describe('when it is retrieved from the database', function() {
it('should contain the same values that have been inserted', function() {
var customer = new CustomerBuilder()
.withIncludeContactOnInvoice()
.build();
customer.save(function(err) {
Customer.findById(customer.id, function(err, result) {
helper.customersShouldBeEqual(result, customer);
asyncSpecDone();
});
});
asyncSpecWait();
});
});
});
describe('given an existing customer', function() {
var customer = null;
beforeEach(function(err) {
customer = new CustomerBuilder()
.withIncludeContactOnInvoice()
.build();
customer.save(function(err) {
expect(err).toBeNull();
asyncSpecDone();
});
asyncSpecWait();
});
describe('when it is retrieved from the database', function() {
var retrievedCustomer = null;
beforeEach(function() {
Customer.findById(customer.id, function(err, result) {
expect(err).toBeNull();
retrievedCustomer = result;
asyncSpecDone();
});
asyncSpecWait();
});
it('should contain the same values that have been inserted', function() {
helper.customersShouldBeEqual(retrievedCustomer, customer);
});
});
});
describe('given an existing customer', function() {
var customer = null;
beforeEach(function(err) {
customer = new CustomerBuilder()
.withIncludeContactOnInvoice()
.build();
customer.save(function(err) {
expect(err).toBeNull();
asyncSpecDone();
});
asyncSpecWait();
});
describe('when it is retrieved from the database', function() {
var retrievedCustomer = null;
beforeEach(function() {
Customer.findById(customer.id, function(err, result) {
expect(err).toBeNull();
retrievedCustomer = result;
asyncSpecDone();
});
asyncSpecWait();
});
it('should contain the same values that have been inserted', function() {
helper.customersShouldBeEqual(retrievedCustomer, customer);
});
});
describe('when it is modified and updated', function() {
beforeEach(function() {
customer.name = 'some other customer';
customer.vatNumber = '0456.876.235';
customer.address = {
street: 'some other street',
postalCode: '12345',
city: 'some other city'
};
customer.phoneNumber = '123456789';
customer.contact = {
name: 'some name',
email: '[email protected]'
};
customer.save(function(err) {
expect(err).toBeNull();
asyncSpecDone();
});
asyncSpecWait();
});
it('contains the updated values in the database', function() {
Customer.findById(customer.id, function(err, result) {
helper.customersShouldBeEqual(result, customer);
asyncSpecDone();
});
asyncSpecWait();
});
});
describe('when it is deleted', function() {
beforeEach(function() {
customer.remove(function(err) {
expect(err).toBeNull();
asyncSpecDone();
});
asyncSpecWait();
});
it('can no longer be retrieved', function() {
Customer.findById(customer.id, function(err, result) {
expect(result).toBeNull();
asyncSpecDone();
});
asyncSpecWait();
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment