| Conditions | 1 |
| Paths | 1 |
| Total Lines | 117 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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'; |
||
| 10 | describe(`[module] codingame/parse`, function() { |
||
| 11 | describe(`[method] parse`, function() { |
||
| 12 | it(`should succeed with a successful response and a successful test`, function() { |
||
| 13 | let output = `42`; |
||
| 14 | let response = { |
||
| 15 | success: { |
||
| 16 | "output": output, |
||
| 17 | "comparison": { |
||
| 18 | "success": true |
||
| 19 | } |
||
| 20 | } |
||
| 21 | }; |
||
| 22 | let parse = cgparse.parse(response); |
||
| 23 | return expect(parse).to.be.fulfilled |
||
| 24 | .and.to.eventually.be.equal(output); |
||
| 25 | }); |
||
| 26 | it(`should reject if success-like response is malformed`, function() { |
||
| 27 | let output = `42`; |
||
| 28 | let response = { |
||
| 29 | success: { |
||
| 30 | "output": output, |
||
| 31 | "comparison": { |
||
| 32 | "success": false |
||
| 33 | } |
||
| 34 | } |
||
| 35 | }; |
||
| 36 | let parse = cgparse.parse(response); |
||
| 37 | return expect(parse).to.be.rejected |
||
| 38 | .and.to.eventually.be.an.instanceof(Error); |
||
| 39 | }); |
||
| 40 | it(`should reject when found value is not the expected one`, function() { |
||
| 41 | let expected = `42`; |
||
| 42 | let found = `43`; |
||
| 43 | let response = { |
||
| 44 | "success": { |
||
| 45 | "output": found, |
||
| 46 | "comparison": { |
||
| 47 | "success": false, |
||
| 48 | "found": found, |
||
| 49 | "expected": expected |
||
| 50 | } |
||
| 51 | } |
||
| 52 | }; |
||
| 53 | let parse = cgparse.parse(response); |
||
| 54 | return expect(parse).to.be.rejected |
||
| 55 | .and.to.eventually.be.an.instanceof(CodingameError) |
||
| 56 | .and.to.have.property(`message`) |
||
| 57 | .with.string(expected) |
||
| 58 | .and.with.string(found); |
||
| 59 | }); |
||
| 60 | it(`should reject if expected-like response is malformed`, function() { |
||
| 61 | let found = `43`; |
||
| 62 | let response = { |
||
| 63 | "success": { |
||
| 64 | "output": found, |
||
| 65 | "comparison": { |
||
| 66 | "success": false, |
||
| 67 | "found": found |
||
| 68 | } |
||
| 69 | } |
||
| 70 | }; |
||
| 71 | let parse = cgparse.parse(response); |
||
| 72 | return expect(parse).to.be.rejected |
||
| 73 | .and.to.eventually.be.an.instanceof(Error); |
||
| 74 | }); |
||
| 75 | it(`should reject when bundle cannot compile`, function() { |
||
| 76 | let message = `SyntaxError: EOL while scanning string literal`; |
||
| 77 | let stacktrace = [{ |
||
| 78 | "location": `ANSWER`, |
||
| 79 | "container": `Answer.py`, |
||
| 80 | "function": ` not in a function`, |
||
| 81 | "line": 26 |
||
| 82 | }]; |
||
| 83 | let response = { |
||
| 84 | "success": { |
||
| 85 | "error": { |
||
| 86 | "message": message, |
||
| 87 | "stacktrace": stacktrace |
||
| 88 | } |
||
| 89 | } |
||
| 90 | }; |
||
| 91 | let parse = cgparse.parse(response); |
||
| 92 | return expect(parse).to.be.rejected |
||
| 93 | .and.to.eventually.be.an.instanceof(CodingameError) |
||
| 94 | .and.to.have.property(`message`) |
||
| 95 | .with.string(message); |
||
| 96 | }); |
||
| 97 | it(`should reject with an error when compile-like response is malformed`, function() { |
||
| 98 | let message = `SyntaxError: EOL while scanning string literal`; |
||
| 99 | let stacktrace = { |
||
| 100 | "location": `ANSWER`, |
||
| 101 | "container": `Answer.py`, |
||
| 102 | "function": ` not in a function`, |
||
| 103 | "line": 26 |
||
| 104 | }; |
||
| 105 | let response = { |
||
| 106 | "success": { |
||
| 107 | "error": { |
||
| 108 | "message": message, |
||
| 109 | "stacktrace": stacktrace |
||
| 110 | } |
||
| 111 | } |
||
| 112 | }; |
||
| 113 | let parse = cgparse.parse(response); |
||
| 114 | return expect(parse).to.be.rejected |
||
| 115 | .and.to.eventually.be.an.instanceof(Error) |
||
| 116 | .and.to.have.property(`message`); |
||
| 117 | }); |
||
| 118 | it(`should reject with an error when fail to parse the response`, function() { |
||
| 119 | let response = { "fakeproperty": false }; |
||
| 120 | let parse = cgparse.parse(response); |
||
| 121 | return expect(parse).to.be.rejected |
||
| 122 | .and.to.eventually.be.an.instanceof(Error) |
||
| 123 | .and.to.have.property(`message`); |
||
| 124 | }); |
||
| 125 | }); |
||
| 126 | }); |
||
| 127 |