Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit c3c4b5e

Browse files
committed
Asyncify the specs
Bring in `jasmine-fix` to allow the use of `async`/`await` in the specs and refactor them to take advantage of this.
1 parent c9f20d3 commit c3c4b5e

File tree

2 files changed

+29
-37
lines changed

2 files changed

+29
-37
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"devDependencies": {
4343
"eslint": "^4.6.0",
4444
"eslint-config-airbnb-base": "^12.0.0",
45-
"eslint-plugin-import": "^2.7.0"
45+
"eslint-plugin-import": "^2.7.0",
46+
"jasmine-fix": "^1.3.1"
4647
},
4748
"package-deps": [
4849
"linter"

spec/linter-ruby-spec.js

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
'use babel';
22

33
import { join } from 'path';
4+
// eslint-disable-next-line no-unused-vars
5+
import { it, fit, wait, beforeEach, afterEach } from 'jasmine-fix';
46

57
const goodPath = join(__dirname, 'fixtures', 'good.rb');
68
const badPath = join(__dirname, 'fixtures', 'bad.rb');
79
const { lint } = require('../lib/main.js').provideLinter();
810

911
describe('The Ruby provider for Linter', () => {
10-
beforeEach(() => {
12+
beforeEach(async () => {
1113
// Info about this beforeEach() implementation:
1214
// https://github.com/AtomLinter/Meta/issues/15
1315
const activationPromise = atom.packages.activatePackage('linter-ruby');
1416

15-
waitsForPromise(() =>
16-
atom.packages.activatePackage('language-ruby').then(() =>
17-
atom.workspace.open(goodPath)));
17+
await atom.packages.activatePackage('language-ruby');
18+
await atom.workspace.open(goodPath);
1819

1920
atom.packages.triggerDeferredActivationHooks();
20-
waitsForPromise(() => activationPromise);
21+
await activationPromise;
2122
});
2223

2324
it('should be in the packages list', () =>
@@ -26,38 +27,28 @@ describe('The Ruby provider for Linter', () => {
2627
it('should be an active package', () =>
2728
expect(atom.packages.isPackageActive('linter-ruby')).toBe(true));
2829

29-
describe('checks bad.rb and', () => {
30-
let editor = null;
31-
beforeEach(() => {
32-
waitsForPromise(() =>
33-
atom.workspace.open(badPath).then((openEditor) => { editor = openEditor; }));
34-
});
35-
36-
it('verifies the messages are correct', () =>
37-
waitsForPromise(() =>
38-
lint(editor).then((messages) => {
39-
expect(messages.length).toBe(2);
40-
41-
expect(messages[0].type).toBe('Warning');
42-
expect(messages[0].html).not.toBeDefined();
43-
expect(messages[0].text).toBe('assigned but unused variable - payload');
44-
expect(messages[0].filePath).toBe(badPath);
45-
expect(messages[0].range).toEqual([[1, 2], [1, 13]]);
46-
47-
expect(messages[1].type).toBe('Error');
48-
expect(messages[1].html).not.toBeDefined();
49-
expect(messages[1].text).toBe('unexpected keyword_end, expecting end-of-input');
50-
expect(messages[1].filePath).toBe(badPath);
51-
expect(messages[1].range).toEqual([[12, 0], [12, 18]]);
52-
})));
30+
it('checks bad.rb and verifies the messages are correct', async () => {
31+
const editor = await atom.workspace.open(badPath);
32+
const messages = await lint(editor);
33+
34+
expect(messages.length).toBe(2);
35+
36+
expect(messages[0].type).toBe('Warning');
37+
expect(messages[0].html).not.toBeDefined();
38+
expect(messages[0].text).toBe('assigned but unused variable - payload');
39+
expect(messages[0].filePath).toBe(badPath);
40+
expect(messages[0].range).toEqual([[1, 2], [1, 13]]);
41+
42+
expect(messages[1].type).toBe('Error');
43+
expect(messages[1].html).not.toBeDefined();
44+
expect(messages[1].text).toBe('unexpected keyword_end, expecting end-of-input');
45+
expect(messages[1].filePath).toBe(badPath);
46+
expect(messages[1].range).toEqual([[12, 0], [12, 18]]);
5347
});
5448

55-
describe('checks good.rb and', () => {
56-
it('reports nothing wrong', () =>
57-
waitsForPromise(() =>
58-
atom.workspace.open(goodPath).then(editor =>
59-
lint(editor).then((messages) => {
60-
expect(messages.length).toBe(0);
61-
}))));
49+
it('checks good.rb and reports nothing wrong', async () => {
50+
const editor = await atom.workspace.open(goodPath);
51+
const messages = await lint(editor);
52+
expect(messages.length).toBe(0);
6253
});
6354
});

0 commit comments

Comments
 (0)