Skip to content
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

[WIP] Update blueprints to take advantage of implicit Ember.run in beforeEach/afterEach #81

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ describe('Acceptance: <%= classifiedModuleName %>', function() {
});

afterEach(function() {
Ember.run(application, 'destroy');
application.destroy();
});

it('can visit /<%= dasherizedModuleName %>', function() {
beforeEach(function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems kinda weird to have two beforeEach blocks (maybe that is super common in mocha-land?)...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fairly common to separate setup concerns. In this case, application setup vs page navigation, but what I'd probably do IRL, is either extract the app setup into its own helper, or If I was feeling like a BDD purist that day, I'd introduce a new description coupled with the new setup. E.g.

describe('Acceptance: <%= classifiedModuleName %>', function() {
  beforeEach(function() {
    this.application = startApp();
  });

  afterEach(function() {
    this.application.destroy();
  });

  describe("visiting /<%= dasherizedModuleName %>", function() {
    beforeEach(function() {
      visit('/<%= dasherizedModuleName %>');
    });

    it("transitions successfully", function() {
      expect(currentPath()).to.equal('<%= dasherizedModuleName %>');
    });
  });
});

I always chafe at the amount of boilerplate in the acceptance tests anyhow, what about introducing a dedicated test helper for acceptance tests, so it could become something like:

describeAcceptance(' <%= classifiedModuleName %>', function() {
  beforeEach(function() {
    visit('/<%= dasherizedModuleName %>');
  });

  it("transitions successfully", function() {
    expect(currentPath()).to.equal('<%= dasherizedModuleName %>');
  });
});

Setting up and tearing down the application would just happen automatically.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a proposal in one (or all) of ember-test-helpers, ember-cli, ember-qunit to add moduleForAcceptance for exactly the reasons that it chafes. If you have time, poke around over there and chime in...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find anything explicitly mentioning moduleForAcceptance in terms of a formal proposal over at ember-test-helpers. Maybe I'm missing something? In any case, I can certainly have a look.

visit('/<%= dasherizedModuleName %>');
});

andThen(function() {
expect(currentPath()).to.equal('<%= dasherizedModuleName %>');
});
it('can visit /<%= dasherizedModuleName %>', function() {
expect(currentPath()).to.equal('<%= dasherizedModuleName %>');
});
});
2 changes: 1 addition & 1 deletion blueprints/ember-cli-mocha/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
var addonContext = this;

return this.addBowerPackagesToProject([
{ name: 'ember-mocha', source: 'ember-mocha', target: '~0.8.0' },
{ name: 'ember-mocha', source: 'ember-mocha', target: '~0.8.3' },
{ name: 'ember-cli-test-loader', source: 'ember-cli/ember-cli-test-loader', target: '0.1.3' },
{ name: 'ember-cli-shims', source: 'ember-cli/ember-cli-shims', target: '0.0.3' }
]).then(function() {
Expand Down