forked from minutebase/ember-can
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Autogenerate a test when generating an ability
Fixes minutebase#11, Resolves minutebase#8, Resolves minutebase#13.
- Loading branch information
Showing
7 changed files
with
130 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
blueprints/ability-test/files/tests/unit/abilities/__name__-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<%= imports %> | ||
|
||
<%= test %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/*jshint node:true*/ | ||
var EOL = require('os').EOL; | ||
|
||
module.exports = { | ||
description: 'Generates an ability unit test.', | ||
|
||
_getTestStyle: function() { | ||
if ('ember-cli-mocha' in this.project.addonPackages) { | ||
return 'mocha'; | ||
} else if ('ember-cli-qunit' in this.project.addonPackages) { | ||
return 'qunit'; | ||
} | ||
}, | ||
|
||
locals: function(options) { | ||
var name = options.entity.name; | ||
|
||
var testStyle = this._getTestStyle(); | ||
if (!testStyle) { | ||
this.ui.writeLine('Couldn\'t determine test style - using QUnit'); | ||
testStyle = 'qunit'; | ||
} | ||
|
||
var imports, test; | ||
if (testStyle === 'qunit') { | ||
imports = | ||
"import { moduleFor, test } from 'ember-qunit';"; | ||
test = | ||
"moduleFor('ability:" + name + "', 'Unit | Ability | " + name + "', {" + EOL + | ||
" // Specify the other units that are required for this test." + EOL + | ||
" // needs: ['service:foo']" + EOL + | ||
"});" + EOL + EOL + | ||
"// Replace this with your real tests." + EOL + | ||
"test('it exists', function(assert) {" + EOL + | ||
" var ability = this.subject();" + EOL + | ||
" assert.ok(ability);" + EOL + | ||
"});"; | ||
} else if (testStyle === 'mocha') { | ||
imports = | ||
"/* jshint expr:true */" + EOL + | ||
"import { expect } from 'chai';" + EOL + | ||
"import {" + EOL + | ||
" describeModule," + EOL + | ||
" it" + EOL + | ||
"} from 'ember-mocha';"; | ||
test = | ||
"describeModule(" + EOL + | ||
" 'ability:" + name + "'," + EOL + | ||
" '" + name + " Ability'," + EOL + | ||
" {" + EOL + | ||
" // Specify the other units that are required for this test." + EOL + | ||
" // needs: ['service:foo']" + EOL + | ||
" }," + EOL + | ||
" function() {" + EOL + | ||
" // Replace this with your real tests." + EOL + | ||
" it('exists', function() {" + EOL + | ||
" var ability = this.subject();" + EOL + | ||
" expect(ability).to.be.ok;" + EOL + | ||
" });" + EOL + | ||
" }" + EOL + | ||
");"; | ||
} | ||
|
||
return { | ||
imports: imports, | ||
test: test | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/*jshint node:true*/ | ||
|
||
var EOL = require('os').EOL; | ||
|
||
module.exports = { | ||
name: 'ember-can', | ||
|
||
normalizeEntityName: function() {}, | ||
|
||
afterInstall: function() { | ||
return this.insertIntoFile( | ||
'tests/helpers/resolver.js', | ||
"resolver.pluralizedTypes.ability = 'abilities';" + EOL, | ||
{ | ||
before: "export default resolver" | ||
} | ||
); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters