|
2 | 2 | const expect = require('chai').expect;
|
3 | 3 | const sinon = require('sinon');
|
4 | 4 |
|
5 |
| -const RestartCommand = require('../../../lib/commands/restart'); |
| 5 | +const modulePath = '../../../lib/commands/restart'; |
| 6 | +const RestartCommand = require(modulePath); |
6 | 7 | const Instance = require('../../../lib/instance');
|
7 | 8 |
|
8 | 9 | describe('Unit: Command > Restart', function () {
|
9 |
| - it('throws error if instance is not running', function () { |
10 |
| - class TestInstance extends Instance { |
11 |
| - running() { return false; } |
| 10 | + it('warns of stopped instance and starts instead', function () { |
| 11 | + const instance = {running: () => false}; |
| 12 | + const logStub = sinon.stub(); |
| 13 | + const ctx = { |
| 14 | + ui: {log: logStub}, |
| 15 | + system: {getInstance: () => instance}, |
| 16 | + runCommand: sinon.stub().resolves() |
12 | 17 | }
|
13 |
| - const testInstance = new TestInstance(); |
14 |
| - |
15 |
| - const command = new RestartCommand({}, { |
16 |
| - getInstance: () => testInstance |
17 |
| - }); |
| 18 | + const command = new RestartCommand({}, {}); |
18 | 19 |
|
19 |
| - return command.run().then(() => { |
20 |
| - throw new Error('Run method should have thrown'); |
21 |
| - }).catch((error) => { |
22 |
| - expect(error.message).to.match(/instance is not currently running/); |
| 20 | + return command.run.call(ctx).then(() => { |
| 21 | + expect(ctx.runCommand.calledOnce).to.be.true; |
| 22 | + expect(ctx.runCommand.args[0][0].description).to.equal('Start an instance of Ghost'); |
| 23 | + expect(logStub.calledOnce).to.be.true; |
| 24 | + expect(logStub.args[0][0]).to.match(/not running!/); |
23 | 25 | });
|
24 | 26 | });
|
25 | 27 |
|
|
0 commit comments