Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import chai from 'chai'; |
||
17 | describe(`[module] utils`, function() { |
||
18 | describe(`[method] kill`, function() { |
||
19 | let exit; |
||
20 | beforeEach(function() { |
||
21 | exit = sinon.stub(process, `exit`); |
||
22 | }); |
||
23 | afterEach(function() { |
||
24 | exit.restore(); |
||
25 | }); |
||
26 | it(`should call process.exit with an negative value`, mute(function() { |
||
27 | let message = `Some error message`; |
||
28 | utils.kill(new Error(message)); |
||
29 | expect(exit).to.have.been.calledOnce; |
||
|
|||
30 | expect(exit.getCall(0).args[0]).to.be.below(0); |
||
31 | })); |
||
32 | }); |
||
33 | describe(`[method] login`, function() { |
||
34 | let sandbox; |
||
35 | beforeEach(function() { |
||
36 | sandbox = sinon.sandbox.create(); |
||
37 | }) |
||
38 | afterEach(function() { |
||
39 | sandbox.restore(); |
||
40 | }); |
||
41 | it(`should resolve if login is successfull`, function() { |
||
42 | let login = sinon.stub(cgapi, `login`, function() {return Promise.resolve(true)}); |
||
43 | let get = sinon.stub(configure, `get`, function(property) {return Promise.resolve(property);}); |
||
44 | let log = utils.login(`username`, `password`) |
||
45 | let calls = log.then(function() { |
||
46 | expect(login).to.have.been.calledOnce; |
||
47 | expect(get).to.have.been.calledTwice; |
||
48 | return Promise.resolve(true); |
||
49 | }); |
||
50 | return Promise.all([ |
||
51 | expect(log).to.eventually.be.fullfilled, |
||
52 | calls |
||
53 | ]); |
||
54 | }); |
||
55 | it(`should reject after 3 tries if authentication failed`, mute(function() { |
||
56 | login = sandbox.stub(cgapi, `login`, function() { |
||
57 | return Promise.resolve({ |
||
58 | "error": new Error(`Cannot authenticate`) |
||
59 | }); |
||
60 | }); |
||
61 | get = sandbox.stub(configure, `get`, function(property) {return Promise.resolve(property);}); |
||
62 | let log = utils.login(`username`, `password`) |
||
63 | let calls = log.catch(function() { |
||
64 | expect(login).to.have.been.calledThrice; |
||
65 | return Promise.resolve(true); |
||
66 | }); |
||
67 | return Promise.all([ |
||
68 | expect(log).to.eventually.be.rejected, |
||
69 | calls |
||
70 | ]); |
||
71 | })); |
||
72 | }); |
||
73 | describe(`[method] tests`, function() { |
||
74 | }); |
||
75 | }); |
||
76 |