1 | {ipso, mock, define} = require '../lib/ipso'
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | define ipso: -> require __dirname + '../../ipso'
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | describe 'define', ipso (should) ->
|
17 |
|
18 |
|
19 | it 'is exported by ipso',
|
20 |
|
21 | ipso (Define) -> Define.should.eql define
|
22 |
|
23 | context 'replaces fs readFileSync, lstatSync and statSync', ->
|
24 |
|
25 | it 'to trick require into loading non existant modules',
|
26 |
|
27 | ipso (Define, fs) ->
|
28 |
|
29 | Define 'nodule': ->
|
30 |
|
31 | fs.readFileSync.toString().should.match /MODIFIED BY ipso.define/
|
32 | fs.lstatSync.toString().should.match /MODIFIED BY ipso.define/
|
33 | fs.statSync.toString().should.match /MODIFIED BY ipso.define/
|
34 |
|
35 | require 'nodule'
|
36 |
|
37 | xit 'it does not replace fs functions unless necessary - ipso.define() was used',
|
38 |
|
39 | ipso (Define, fs) ->
|
40 |
|
41 |
|
42 |
|
43 | fs.readFileSync.toString().should.not.match /MODIFIED BY ipso.define/
|
44 | fs.lstatSync.toString().should.not.match /MODIFIED BY ipso.define/
|
45 | fs.statSync.toString().should.not.match /MODIFIED BY ipso.define/
|
46 |
|
47 |
|
48 | xit 'calls activate (to replace fs functions) only once',
|
49 |
|
50 | ipso (Define) ->
|
51 |
|
52 | count = 0
|
53 | Define.does _activate: -> count++
|
54 |
|
55 | Define 'xmodule': ->
|
56 | Define 'ymodule': ->
|
57 | Define 'zmodule': ->
|
58 |
|
59 | count.should.equal 1
|
60 |
|
61 |
|
62 |
|
63 | context 'modules that export a single function', ->
|
64 |
|
65 | it 'can be defined',
|
66 |
|
67 | ipso (Define) ->
|
68 |
|
69 | Define 'non-existant': -> ->
|
70 |
|
71 | function1: -> 'RESULT1'
|
72 | function2: -> 'RESULT2'
|
73 |
|
74 | non = require('non-existant')()
|
75 | non.function1().should.equal 'RESULT1'
|
76 | non.function2().should.equal 'RESULT2'
|
77 |
|
78 |
|
79 | xit 'has get() in scope (at require time) to return previously defined mock object',
|
80 |
|
81 | ipso (Define) ->
|
82 |
|
83 | mock( 'mock_object' ).does
|
84 |
|
85 | expectedFunction: -> 'RESULT'
|
86 |
|
87 | Define
|
88 |
|
89 | 'object': -> get 'mock_object'
|
90 |
|
91 |
|
92 |
|
93 | obj = require('object')()
|
94 | console.log obj
|
95 | obj.expectedFunction().should.equal 'RESULT'
|
96 |
|
97 |
|
98 |
|
99 | context 'modules that export a list of functions', ->
|
100 |
|
101 | it 'can be defined',
|
102 |
|
103 | ipso (Define) ->
|
104 |
|
105 | Define missing1: ->
|
106 | m = require 'missing1'
|
107 |
|
108 |
|
109 | it 'runs the function to create the module definition',
|
110 |
|
111 | ipso (Define) ->
|
112 |
|
113 | Define missing2: -> 'value'
|
114 | m = require 'missing2'
|
115 | m.should.equal 'value'
|
116 |
|
117 |
|
118 | xcontext 'defines mock() in the module scope', ->
|
119 |
|
120 | before ipso (Define) ->
|
121 |
|
122 | Define missing3: ->
|
123 |
|
124 | SubClass1: mock 'SubClass1'
|
125 |
|
126 |
|
127 | it 'can inject the mocks that compose the new module',
|
128 |
|
129 | ipso (SubClass1) ->
|
130 |
|
131 | SubClass1.does function: ->
|
132 |
|
133 | r = require 'missing3'
|
134 | r.SubClass1.function()
|
135 |
|
136 |
|
137 | context 'modules that export a class', ->
|
138 |
|
139 |
|