Skip to content

Commit 7c05731

Browse files
committed
Remove satisfy() from stubbing store
I could not for the life of me figure out why app code was being invoked from a value object. Obviously it's a thing I (tell people to) avoid doing, but as I dove in I realized that this stupid unit test was also depending on this dummy implementation of satisfy() working in order to also pass. Not only was that unhelpful incidental coverage, it was obnoxious b/c I needed to delete that implementation to start driving out an actual satisfy() solution, and I didn't want to stare at this unrelated error.
1 parent 4064674 commit 7c05731

File tree

5 files changed

+15
-31
lines changed

5 files changed

+15
-31
lines changed

src/function/generate-fake-function.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import CallLog from '../value/call-log'
22
import Call from '../value/call'
3-
import StubbingRegister from '../value/stubbing-register'
3+
import satisfy from '../satisfy'
44

55
export default function generateFakeFunction (double) {
66
const testDouble = function testDouble (...args) {
77
const call = new Call(this, args)
88
CallLog.instance.log(double, call)
9-
return StubbingRegister.instance.satisfy(double, call)
9+
return satisfy(double, call)
1010
}
1111
testDouble.toString = double.toString.bind(double)
1212

src/satisfy/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// import _ from '../wrap/lodash'
22

3-
export default (call, stubbings) => {
3+
export default function satisfy (double, call) {
44
// TODO: dummy impl to drive create feature first
5-
return stubbings ? stubbings[0].outcomes[0] : undefined
65

76
// 1. find the last matching stubbing (args+conditions match + has values left)
87
// 2. six-way switch to execute the correct plan switching on the stubbing's `type`

src/value/stubbing-register.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import Map from 'es6-map'
22

3-
import satisfy from '../satisfy'
4-
53
let instance = null
64

75
export default class StubbingRegister {
@@ -27,10 +25,6 @@ export default class StubbingRegister {
2725
}
2826
}
2927

30-
satisfy (double, call) {
31-
return satisfy(call, this.stubbings.get(double))
32-
}
33-
3428
get (double) {
3529
return this.stubbings.get(double)
3630
}

test/unit/function/generate-fake-function.test.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import Double from '../../../src/value/double'
2+
import Call from '../../../src/value/call'
23
import CallLog from '../../../src/value/call-log'
3-
import StubbingRegister from '../../../src/value/stubbing-register'
4-
import Stubbing from '../../../src/value/stubbing'
5-
import subject from '../../../src/function/generate-fake-function'
64

5+
let satisfy, subject
76
module.exports = {
7+
beforeEach: () => {
8+
satisfy = td.replace('../../../src/satisfy').default
9+
10+
subject = require('../../../src/function/generate-fake-function').default
11+
},
812
'the fake function itself': {
913
'logs calls': () => {
1014
const double = Double.create()
@@ -18,12 +22,13 @@ module.exports = {
1822
},
1923
'registers stubbing': () => {
2024
const double = Double.create()
21-
const stubbing = new Stubbing('return', ['a', 'b'], ['c'])
22-
StubbingRegister.instance.add(double, stubbing)
25+
const self = {}
26+
const call = new Call(self, [42])
27+
td.when(satisfy(double, call)).thenReturn('woot')
2328

24-
const result = subject(double)('a', 'b')
29+
const result = subject(double).call(self, 42)
2530

26-
assert.equal(result, 'c')
31+
assert.equal(result, 'woot')
2732
}
2833
},
2934
'sets toString to that of the double': () => {
Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Double from '../../../src/value/double'
2-
import Call from '../../../src/value/call'
32
import Stubbing from '../../../src/value/stubbing'
43
import StubbingRegister from '../../../src/value/stubbing-register'
54

@@ -18,18 +17,5 @@ module.exports = {
1817
subject.add(double, stubbing)
1918

2019
assert.deepEqual(subject.get(double), [stubbing])
21-
},
22-
'delegates to another thing to satisfy': () => {
23-
const double = Double.create()
24-
const stubbing = new Stubbing()
25-
const call = new Call()
26-
const satisfy = td.replace('../../../src/satisfy').default
27-
td.when(satisfy(call, [stubbing])).thenReturn('pants')
28-
subject = require('../../../src/value/stubbing-register').default.instance
29-
subject.add(double, stubbing)
30-
31-
const result = subject.satisfy(double, call)
32-
33-
assert.equal(result, 'pants')
3420
}
3521
}

0 commit comments

Comments
 (0)