Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Commit

Permalink
Rspec BDD Generation
Browse files Browse the repository at this point in the history
  • Loading branch information
HarishRaj11 committed Apr 8, 2019
1 parent e6da03b commit 3ba11e7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
3 changes: 3 additions & 0 deletions bin/swagger-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var execute = cli.execute;
var frameworks = Object.keys(project.frameworks).join('|');
var assertiontypes = project.assertiontypes.join('|');
var testmodules = project.testmodules.join('|');
var lang = project.lang.join('|');

app
.command('create [name]')
Expand Down Expand Up @@ -65,6 +66,7 @@ app
.option('-d, --debug [port]', 'start in remote debug mode')
.option('-b, --debug-brk [port]', 'start in remote debug mode, wait for debugger connect')
.option('-m, --mock', 'run in mock mode')
.option('-o, --host <server>', 'test server')
.action(execute(project.test));

app
Expand All @@ -75,6 +77,7 @@ app
.option('-t, --assertion-format <type>', 'one of: ' + assertiontypes)
.option('-o, --force', 'allow overwriting of all existing test files matching those generated')
.option('-l, --load-test [path]', 'generate load-tests for specified operations')
.option('-n, --lang <language>', 'one of: ' + lang)
.action(execute(project.generateTest));

app.parse(process.argv);
Expand Down
3 changes: 2 additions & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ var debug = require('debug')('swagger');
var config = {
rootDir: path.resolve(__dirname, '..'),
userHome: process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'],
debug: !!process.env.DEBUG
debug: !!process.env.DEBUG,
language: 'js'
};
config.nodeModules = path.resolve(config.rootDir, 'node_modules');

Expand Down
40 changes: 26 additions & 14 deletions lib/commands/project/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var swaggerSpec = require('../../util/spec');
var spec = require('swagger-tools').specs.v2;
var inquirer = require('inquirer');

var LANGUAGE = ['js', 'rb'];
var FRAMEWORKS = {
connect: { source: 'connect' },
express: { source: 'connect', overlay: 'express' },
Expand Down Expand Up @@ -61,6 +62,8 @@ module.exports = {
read: readProject,
assertiontypes: TEST_ASSERTION_TYPES,
testmodules: TEST_MODULES,
lang: LANGUAGE,


// for testing stub generating
generateTest: testGenerate
Expand All @@ -77,8 +80,9 @@ function create(name, options, cb) {
}

if (name) {
var valid = validateName(name);
if (typeof valid === 'string') { return cb(new Error(valid)); }
var valid = validateName(name);
if (typeof valid === 'string') { return cb(new Error(valid)); }

}

if (options.framework && !FRAMEWORKS[options.framework]) {
Expand Down Expand Up @@ -220,6 +224,14 @@ function test(directory, options, cb) {
if (options.mock) {
process.env.swagger_mockMode = true;
}

var server_config = require('../../../../../config.json')
process.env.swagger_host = server_config[options.host].protocol + "://";
process.env.swagger_host += server_config[options.host].host;
if(server_config[options.host].port != ""){
process.env.swagger_host += ":" + server_config[options.host].port;
}

mocha.run(function(failures) {
process.exit(failures);
});
Expand Down Expand Up @@ -456,7 +468,8 @@ function testGenerate(directory, options, cb) {
var config = {
pathName: desiredPaths,
testModule: testModule,
assertionFormat: assertionFormat
assertionFormat: assertionFormat,
lang: options.lang
};

// pass list of paths targeted for load testing
Expand Down Expand Up @@ -523,17 +536,16 @@ function testGenerate(directory, options, cb) {
}
}
}, function(filteredResult) {

async.each(filteredResult, function(file, cb) {
if (file.name === '.env') {
fs.outputFile(path.join(directory, file.name), file.test, cb);
} else {
fs.outputFile(path.join(directory, '/test/api/client', file.name), file.test, cb);
}
}, function(err) {
if (runInstall) {
installDependencies(directory, 'Success! You may now run your tests.', cb);
}
async.each(filteredResult, function(file, cb) {
if (file.name === '.env') {
fs.outputFile(path.join(directory, file.name), file.test, cb);
} else {
fs.outputFile(path.join(directory, '/test/api/client', file.name), file.test.replace(/x-enum/g, "enum"), cb);
}
}, function(err) {
if (runInstall) {
installDependencies(directory, 'Success! You may now run your tests.', cb);
}
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"serve-static": "^1.9.2",
"swagger-converter": "^1.4.1",
"swagger-editor": "^2.9.2",
"swagger-test-templates": "^1.2.0",
"swagger-test-templates": "git+https://github.com/HarishRaj11/swagger-test-templates.git#freshworks-bdd-spec-generation",
"swagger-tools": "^0.10.1"
},
"devDependencies": {
Expand All @@ -54,4 +54,4 @@
"swagger": "bin/swagger.js",
"swagger-project": "bin/swagger-project.js"
}
}
}
4 changes: 2 additions & 2 deletions test/util/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ describe('cli', function() {

it('should print the result of the command', function() {

cli.execute(executeNoError)(1);
cli.execute(executeNoError)('1');
exitCode.should.equal(0);
capture.output().should.equal('1\n');
});

it('should print the result with header', function() {

cli.execute(executeNoError, 'whatever')(1);
cli.execute(executeNoError, 'whatever')('1');
exitCode.should.equal(0);
capture.output().should.equal('whatever\n========\n1\n');
});
Expand Down

0 comments on commit 3ba11e7

Please sign in to comment.