Skip to content

feat(gen): replace does templating syntax #1164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ var AngularFullstackGenerator = yeoman.generators.Base.extend({

this.filters = {};

// dynamic assertion statement
this.does = this.is = function(foo) {
foo = this.engine(foo.replace(/\(;>%%<;\)/g, '<%')
.replace(/\(;>%<;\)/g, '%>'), this);
if (this.filters.should) {
return foo + '.should';
} else {
return 'expect(' + foo + ').to';
}
// dynamic assertion statements
this.expect = function() {
return this.filters.expect ? 'expect(' : '';
}.bind(this);
this.to = function() {
return this.filters.expect ? ').to' : '.should';
}.bind(this);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ describe 'Controller: MainCtrl', ->
it 'should attach a list of things to the scope', ->
$httpBackend.flush()<% if (filters.jasmine) { %>
expect(scope.awesomeThings.length).toBe 4 <% } if (filters.mocha) { %>
<%= does("scope.awesomeThings.length") %>.equal 4<% } %>
<%= expect() %>scope.awesomeThings.length<%= to() %>.equal 4<% } %>
2 changes: 1 addition & 1 deletion app/templates/client/app/main/main.controller.spec(js).js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ describe('Controller: MainCtrl', function() {
it('should attach a list of things to the scope', function() {
$httpBackend.flush();<% if (filters.jasmine) { %>
expect(scope.awesomeThings.length).toBe(4);<% } if (filters.mocha) { %>
<%= does("scope.awesomeThings.length") %>.equal(4);<% } %>
<%= expect() %>scope.awesomeThings.length<%= to() %>.equal(4);<% } %>
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ angular.module('<%= scriptAppName %>')
id:'me'
}
}
});
});
});
20 changes: 10 additions & 10 deletions app/templates/e2e/account(auth)/login/login.spec(mocha).js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ describe('Login View', function() {
});

it('should include login form with correct inputs and submit button', function() {
<%= does("page.form.email.getAttribute('type')") %>.eventually.equal('email');
<%= does("page.form.email.getAttribute('name')") %>.eventually.equal('email');
<%= does("page.form.password.getAttribute('type')") %>.eventually.equal('password');
<%= does("page.form.password.getAttribute('name')") %>.eventually.equal('password');
<%= does("page.form.submit.getAttribute('type')") %>.eventually.equal('submit');
<%= does("page.form.submit.getText()") %>.eventually.equal('Login');
<%= expect() %>page.form.email.getAttribute('type')<%= to() %>.eventually.equal('email');
<%= expect() %>page.form.email.getAttribute('name')<%= to() %>.eventually.equal('email');
<%= expect() %>page.form.password.getAttribute('type')<%= to() %>.eventually.equal('password');
<%= expect() %>page.form.password.getAttribute('name')<%= to() %>.eventually.equal('password');
<%= expect() %>page.form.submit.getAttribute('type')<%= to() %>.eventually.equal('submit');
<%= expect() %>page.form.submit.getText()<%= to() %>.eventually.equal('Login');
});

describe('with local auth', function() {
Expand All @@ -50,8 +50,8 @@ describe('Login View', function() {

var navbar = require('../../components/navbar/navbar.po');

<%= does("browser.getCurrentUrl()") %>.eventually.equal(config.baseUrl + '/');
<%= does("navbar.navbarAccountGreeting.getText()") %>.eventually.equal('Hello ' + testUser.name);
<%= expect() %>browser.getCurrentUrl()<%= to() %>.eventually.equal(config.baseUrl + '/');
<%= expect() %>navbar.navbarAccountGreeting.getText()<%= to() %>.eventually.equal('Hello ' + testUser.name);
});

describe('and invalid credentials', function() {
Expand All @@ -65,10 +65,10 @@ describe('Login View', function() {
password: 'badPassword'
});

<%= does("browser.getCurrentUrl()") %>.eventually.equal(config.baseUrl + '/login');
<%= expect() %>browser.getCurrentUrl()<%= to() %>.eventually.equal(config.baseUrl + '/login');

var helpBlock = page.form.element(by.css('.form-group.has-error .help-block.ng-binding'));
<%= does("helpBlock.getText()") %>.eventually.equal('This password is not correct.');
<%= expect() %>helpBlock.getText()<%= to() %>.eventually.equal('This password is not correct.');
});

});
Expand Down
8 changes: 4 additions & 4 deletions app/templates/e2e/account(auth)/logout/logout.spec(mocha).js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ describe('Logout View', function() {
it('should logout a user and redirecting to "/"', function() {
var navbar = require('../../components/navbar/navbar.po');

<%= does("browser.getCurrentUrl()") %>.eventually.equal(config.baseUrl + '/');
<%= does("navbar.navbarAccountGreeting.getText()") %>.eventually.equal('Hello ' + testUser.name);
<%= expect() %>browser.getCurrentUrl()<%= to() %>.eventually.equal(config.baseUrl + '/');
<%= expect() %>navbar.navbarAccountGreeting.getText()<%= to() %>.eventually.equal('Hello ' + testUser.name);

browser.get(config.baseUrl + '/logout');

navbar = require('../../components/navbar/navbar.po');

<%= does("browser.getCurrentUrl()") %>.eventually.equal(config.baseUrl + '/');
<%= does("navbar.navbarAccountGreeting.isDisplayed()") %>.eventually.equal(false);
<%= expect() %>browser.getCurrentUrl()<%= to() %>.eventually.equal(config.baseUrl + '/');
<%= expect() %>navbar.navbarAccountGreeting.isDisplayed()<%= to() %>.eventually.equal(false);
});

});
Expand Down
26 changes: 13 additions & 13 deletions app/templates/e2e/account(auth)/signup/signup.spec(mocha).js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ describe('Signup View', function() {
});

it('should include signup form with correct inputs and submit button', function() {
<%= does("page.form.name.getAttribute('type')") %>.eventually.equal('text');
<%= does("page.form.name.getAttribute('name')") %>.eventually.equal('name');
<%= does("page.form.email.getAttribute('type')") %>.eventually.equal('email');
<%= does("page.form.email.getAttribute('name')") %>.eventually.equal('email');
<%= does("page.form.password.getAttribute('type')") %>.eventually.equal('password');
<%= does("page.form.password.getAttribute('name')") %>.eventually.equal('password');
<%= does("page.form.submit.getAttribute('type')") %>.eventually.equal('submit');
<%= does("page.form.submit.getText()") %>.eventually.equal('Sign up');
<%= expect() %>page.form.name.getAttribute('type')<%= to() %>.eventually.equal('text');
<%= expect() %>page.form.name.getAttribute('name')<%= to() %>.eventually.equal('name');
<%= expect() %>page.form.email.getAttribute('type')<%= to() %>.eventually.equal('email');
<%= expect() %>page.form.email.getAttribute('name')<%= to() %>.eventually.equal('email');
<%= expect() %>page.form.password.getAttribute('type')<%= to() %>.eventually.equal('password');
<%= expect() %>page.form.password.getAttribute('name')<%= to() %>.eventually.equal('password');
<%= expect() %>page.form.submit.getAttribute('type')<%= to() %>.eventually.equal('submit');
<%= expect() %>page.form.submit.getText()<%= to() %>.eventually.equal('Sign up');
});

describe('with local auth', function() {
Expand All @@ -51,8 +51,8 @@ describe('Signup View', function() {

var navbar = require('../../components/navbar/navbar.po');

<%= does("browser.getCurrentUrl()") %>.eventually.equal(config.baseUrl + '/');
<%= does("navbar.navbarAccountGreeting.getText()") %>.eventually.equal('Hello ' + testUser.name);
<%= expect() %>browser.getCurrentUrl()<%= to() %>.eventually.equal(config.baseUrl + '/');
<%= expect() %>navbar.navbarAccountGreeting.getText()<%= to() %>.eventually.equal('Hello ' + testUser.name);
});

describe('and invalid credentials', function() {
Expand All @@ -63,11 +63,11 @@ describe('Signup View', function() {
it('should indicate signup failures', function() {
page.signup(testUser);

<%= does("browser.getCurrentUrl()") %>.eventually.equal(config.baseUrl + '/signup');
<%= does("page.form.email.getAttribute('class')") %>.eventually.contain('ng-invalid-mongoose');
<%= expect() %>browser.getCurrentUrl()<%= to() %>.eventually.equal(config.baseUrl + '/signup');
<%= expect() %>page.form.email.getAttribute('class')<%= to() %>.eventually.contain('ng-invalid-mongoose');

var helpBlock = page.form.element(by.css('.form-group.has-error .help-block.ng-binding'));
<%= does("helpBlock.getText()") %>.eventually.equal('The specified email address is already in use.');
<%= expect() %>helpBlock.getText()<%= to() %>.eventually.equal('The specified email address is already in use.');
});

});
Expand Down
6 changes: 3 additions & 3 deletions app/templates/e2e/main/main.spec(mocha).js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ describe('Main View', function() {
});

it('should include jumbotron with correct data', function() {
<%= does("page.h1El.getText()") %>.eventually.equal('\'Allo, \'Allo!');
<%= does("page.imgEl.getAttribute('src')") %>.eventually.match(/yeoman.png$/);
<%= does("page.imgEl.getAttribute('alt')") %>.eventually.equal('I\'m Yeoman');
<%= expect() %>page.h1El.getText()<%= to() %>.eventually.equal('\'Allo, \'Allo!');
<%= expect() %>page.imgEl.getAttribute('src')<%= to() %>.eventually.match(/yeoman.png$/);
<%= expect() %>page.imgEl.getAttribute('alt')<%= to() %>.eventually.equal('I\'m Yeoman');
});
});
38 changes: 19 additions & 19 deletions app/templates/server/api/user(auth)/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,65 +41,65 @@ var userIndex = proxyquire('./index', {
describe('User API Router:', function() {

it('should return an express router instance', function() {
userIndex.should.equal(routerStub);
<%= expect() %>userIndex<%= to() %>.equal(routerStub);
});

describe('GET /api/users', function() {

it('should verify admin role and route to user.controller.index', function() {
routerStub.get
.withArgs('/', 'authService.hasRole.admin', 'userCtrl.index')
.should.have.been.calledOnce;
<%= expect() %>routerStub.get
.withArgs('/', 'authService.hasRole.admin', 'userCtrl.index')
<%= to() %>.have.been.calledOnce;
});

});

describe('DELETE /api/users/:id', function() {

it('should verify admin role and route to user.controller.destroy', function() {
routerStub.delete
.withArgs('/:id', 'authService.hasRole.admin', 'userCtrl.destroy')
.should.have.been.calledOnce;
<%= expect() %>routerStub.delete
.withArgs('/:id', 'authService.hasRole.admin', 'userCtrl.destroy')
<%= to() %>.have.been.calledOnce;
});

});

describe('GET /api/users/me', function() {

it('should be authenticated and route to user.controller.me', function() {
routerStub.get
.withArgs('/me', 'authService.isAuthenticated', 'userCtrl.me')
.should.have.been.calledOnce;
<%= expect() %>routerStub.get
.withArgs('/me', 'authService.isAuthenticated', 'userCtrl.me')
<%= to() %>.have.been.calledOnce;
});

});

describe('PUT /api/users/:id/password', function() {

it('should be authenticated and route to user.controller.changePassword', function() {
routerStub.put
.withArgs('/:id/password', 'authService.isAuthenticated', 'userCtrl.changePassword')
.should.have.been.calledOnce;
<%= expect() %>routerStub.put
.withArgs('/:id/password', 'authService.isAuthenticated', 'userCtrl.changePassword')
<%= to() %>.have.been.calledOnce;
});

});

describe('GET /api/users/:id', function() {

it('should be authenticated and route to user.controller.show', function() {
routerStub.get
.withArgs('/:id', 'authService.isAuthenticated', 'userCtrl.show')
.should.have.been.calledOnce;
<%= expect() %>routerStub.get
.withArgs('/:id', 'authService.isAuthenticated', 'userCtrl.show')
<%= to() %>.have.been.calledOnce;
});

});

describe('POST /api/users', function() {

it('should route to user.controller.create', function() {
routerStub.post
.withArgs('/', 'userCtrl.create')
.should.have.been.calledOnce;
<%= expect() %>routerStub.post
.withArgs('/', 'userCtrl.create')
<%= to() %>.have.been.calledOnce;
});

});
Expand Down
2 changes: 1 addition & 1 deletion app/templates/server/api/user(auth)/user.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('User API:', function() {
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
res.body._id.toString().should.equal(user._id.toString());
<%= expect() %>res.body._id.toString()<%= to() %>.equal(user._id.toString());
done();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ describe('User Model', function() {
});

it('should begin with no users', function() {
return User.findAsync({})
.should.eventually.have.length(0);
return <%= expect() %>User.findAsync({})<%= to() %>
.eventually.have.length(0);
});

it('should fail when saving a duplicate user', function() {
return user.saveAsync()
return <%= expect() %>user.saveAsync()
.then(function() {
var userDup = genUser();
return userDup.saveAsync();
}).should.be.rejected;
})<%= to() %>.be.rejected;
});

describe('#email', function() {
it('should fail when saving without an email', function() {
user.email = '';
return user.saveAsync().should.be.rejected;
return <%= expect() %>user.saveAsync()<%= to() %>.be.rejected;
});
});

Expand All @@ -53,19 +53,19 @@ describe('User Model', function() {
});

it('should authenticate user if valid', function() {
user.authenticate('password').should.be.true;
<%= expect() %>user.authenticate('password')<%= to() %>.be.true;
});

it('should not authenticate user if invalid', function() {
user.authenticate('blah').should.not.be.true;
<%= expect() %>user.authenticate('blah')<%= to() %>.not.be.true;
});

it('should remain the same hash unless the password is updated', function() {
user.name = 'Test User';
return user.saveAsync()
return <%= expect() %>user.saveAsync()
.spread(function(u) {
return u.authenticate('password');
}).should.eventually.be.true;
})<%= to() %>.eventually.be.true;
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ describe('User Model', function() {
});

it('should begin with no users', function() {
return User.findAll()
.should.eventually.have.length(0);
return <%= expect() %>User.findAll()<%= to() %>
.eventually.have.length(0);
});

it('should fail when saving a duplicate user', function() {
return user.save()
return <%= expect() %>user.save()
.then(function() {
var userDup = genUser();
return userDup.save();
}).should.be.rejected;
})<%= to() %>.be.rejected;
});

describe('#email', function() {
it('should fail when saving without an email', function() {
user.email = '';
return user.save().should.be.rejected;
return <%= expect() %>user.save()<%= to() %>.be.rejected;
});
});

Expand All @@ -55,19 +55,19 @@ describe('User Model', function() {
});

it('should authenticate user if valid', function() {
user.authenticate('password').should.be.true;
<%= expect() %>user.authenticate('password')<%= to() %>.be.true;
});

it('should not authenticate user if invalid', function() {
user.authenticate('blah').should.not.be.true;
<%= expect() %>user.authenticate('blah')<%= to() %>.not.be.true;
});

it('should remain the same hash unless the password is updated', function() {
user.name = 'Test User';
return user.save()
return <%= expect() %>user.save()
.then(function(u) {
return u.authenticate('password');
}).should.eventually.be.true;
})<%= to() %>.eventually.be.true;
});
});

Expand Down
Loading