|
| 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