Skip to content

Instantly share code, notes, and snippets.

@stahnma
Last active October 23, 2018 19:45
Show Gist options
  • Save stahnma/29c40ccd36241aebe68852895d670167 to your computer and use it in GitHub Desktop.
Save stahnma/29c40ccd36241aebe68852895d670167 to your computer and use it in GitHub Desktop.
var expect, fs;
expect = require('chai').expect;
fs = require('fs');
// list all files in scripts
// check each script for a Category comment
// fail if it's missing
describe('category', function() {
var bool, f, re, results, text;
re = /[\#|\/\/]\s+category[:?]\s+(workflow|social)/i;
results = [];
fs.readdirSync('tt').forEach(function(f) {
describe("All scripts should have a category", function() {
it("Should have a known category for " + f, function(done) {
text = fs.readFileSync('./tt/' + f).toString();
bool = re.test(text);
results.push(expect(bool).to.eql(true));
done();
})
return results;
});
});
})
#/usr/bin/env coffee
Helper = require('hubot-test-helper')
expect = require('chai').expect
fs = require 'fs'
# Objective
# list all files in scripts
# check each script for a Category comment
# fail if it's missing
describe 'category', ->
context "All scripts should have a category", ->
files = fs.readdirSync('tt');
re = /category/i
for f in files
it "ensures a category exists for #{f}", ->
text = fs.readFileSync('./tt/' + f).toString(); # f is always the same value here, because non-blocking IO is dumb (or I am)
console.log(text)
bool = re.test(text)
expect(bool).to.eql(true)
@stephenyeargin
Copy link

describe 'category', ->
  context "All scripts should have a category", ->
    it "ensures a category exists for files", -> 
      files = fs.readdirSync('tt');
      re = /category/i
      for f in files
        text = fs.readFileSync('./tt/' + f).toString(); # f is always the same value here, because non-blocking IO is dumb (or I am)
        console.log(text)
        bool = re.test(text)
        expect(bool).to.eql(true, "File #{f} has a category")

@stephenyeargin
Copy link

Drawback: It will fail on first file that doesn't have a category
Positive: It works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment