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

Commit 4a6301c

Browse files
committed
Add basic specs
Add some basic specs to test that the provider is working properly.
1 parent 148a2be commit 4a6301c

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

spec/.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
env: {
3+
jasmine: true,
4+
atomtest: true
5+
}
6+
};

spec/fixtures/bad.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def example
2+
payload = {
3+
:meta => {
4+
:envelope => {
5+
:token => session.token,
6+
}
7+
}
8+
}
9+
end
10+
11+
fruit = ["mango", "apple", "orange"]
12+
13+
fruit.each end |e|
14+
puts e
15+
end

spec/fixtures/good.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
puts 'foo'

spec/linter-ruby-spec.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
'use babel';
2+
3+
import { join } from 'path';
4+
5+
const goodPath = join(__dirname, 'fixtures', 'good.rb');
6+
const badPath = join(__dirname, 'fixtures', 'bad.rb');
7+
const lint = require('../lib/main.js').provideLinter().lint;
8+
9+
describe('The Ruby provider for Linter', () => {
10+
beforeEach(() => {
11+
// Info about this beforeEach() implementation:
12+
// https://github.com/AtomLinter/Meta/issues/15
13+
const activationPromise = atom.packages.activatePackage('linter-ruby');
14+
15+
waitsForPromise(() =>
16+
atom.packages.activatePackage('language-ruby').then(() =>
17+
atom.workspace.open(goodPath)));
18+
19+
atom.packages.triggerDeferredActivationHooks();
20+
waitsForPromise(() => activationPromise);
21+
});
22+
23+
it('should be in the packages list', () =>
24+
expect(atom.packages.isPackageLoaded('linter-ruby')).toBe(true),
25+
);
26+
27+
it('should be an active package', () =>
28+
expect(atom.packages.isPackageActive('linter-ruby')).toBe(true),
29+
);
30+
31+
describe('checks bad.rb and', () => {
32+
let editor = null;
33+
beforeEach(() => {
34+
waitsForPromise(() =>
35+
atom.workspace.open(badPath).then(
36+
(openEditor) => { editor = openEditor; },
37+
),
38+
);
39+
});
40+
41+
it('verifies the messages are correct', () =>
42+
waitsForPromise(() =>
43+
lint(editor).then((messages) => {
44+
expect(messages.length).toBe(2);
45+
46+
expect(messages[0].type).toBe('warning');
47+
expect(messages[0].html).not.toBeDefined();
48+
expect(messages[0].text).toBe('assigned but unused variable - payload');
49+
expect(messages[0].filePath).toBe(badPath);
50+
expect(messages[0].range).toEqual([[1, 2], [1, 13]]);
51+
52+
expect(messages[1].type).toBe('syntax error');
53+
expect(messages[1].html).not.toBeDefined();
54+
expect(messages[1].text).toBe('unexpected keyword_end, expecting end-of-input');
55+
expect(messages[1].filePath).toBe(badPath);
56+
expect(messages[1].range).toEqual([[12, 0], [12, 18]]);
57+
}),
58+
),
59+
);
60+
});
61+
62+
describe('checks good.rb and', () => {
63+
it('reports nothing wrong', () =>
64+
waitsForPromise(() =>
65+
atom.workspace.open(goodPath).then(editor =>
66+
lint(editor).then((messages) => {
67+
expect(messages.length).toBe(0);
68+
}),
69+
),
70+
),
71+
);
72+
});
73+
});

0 commit comments

Comments
 (0)