iensu / mocha-cakes-2

A BDD plugin for Mocha testing framework
MIT License
43 stars 10 forks source link

Reduce blank lines in steps #1

Closed sygint closed 7 years ago

sygint commented 8 years ago

Awesome job porting this project from CoffeeScript, I really liked it but was having trouble with using CoffeeScript to write my tests. I've modified the code slightly to clean the output a bit by giving the Feature a new line before it and removing the one after, but I'd really like to reduce the lines required for the step to a having no spaces, any idea how I can do this?

  === User model ===

Feature: Unit: #register

    Scenario: failure, ValidationError

          ✓ Given: a failing email and password combination
          ✓  When: account registration is attempted
          ✓  Then: the registration should fail with a ValidationError for a missing em
ail and password
sygint commented 8 years ago

I got it working, very hacky, needs a rewrite:

function describeItNested(mochaInstance, command, message, callback, options) {
  if (command === 'it') {
    mochaInstance.it(message, callback);
  } else {
    mochaInstance.describe(command, nestedFunc(mochaInstance, command, message, callback));
  }
}
describeItNested.only = function (mochaInstance, command, message, callback, options) {
  // only relies on grep against test labels,
  // using non-breaking space as describe label to enable `only`
  mochaInstance.describe.only(' ', nestedFunc(mochaInstance, command, message, callback));
};
describeItNested.skip = function (mochaInstance, command, message, callback, options) {
  mochaInstance.describe.skip('', nestedFunc(mochaInstance, command, message, callback));
};

function nestedFunc(mochaInstance, command, message, callback) {
  return function () {
    mochaInstance.describe('', function () {
      mochaInstance.describe(message, callback);
    });
  };
}
iensu commented 8 years ago

Hi @gnarmedia, thanks a lot for your input.

I agree that the output could use a cleanup, so I did that here, borrowing a bit from your snippet there: https://github.com/iensu/mocha-cakes-2/commit/060670565b5a825419119ff6c87530f964c53543

Alright to close this issue?

Best regards,

Jens

sygint commented 8 years ago

I made a pull request for a few things I forgot to include.

sygint commented 8 years ago

Have you had any time to look it over? Would you prefer it as a branch? Let me know.

iensu commented 7 years ago

Sorry about the late response.

I've converted mocha cakes into a proper Mocha interface, so I'll close this issue for now.

sygint commented 7 years ago

Very cool, will check it out again soon :]

iensu commented 7 years ago

Yea, it reduced quite a bit of complexity from the code base :)