1 | **experimental/unstable** api changes will still occur (without deprecation warnings)
|
2 | `npm install ipso` 0.0.4 [license](./license)
|
3 |
|
4 |
|
5 | Bits and bobs. For testing.
|
6 |
|
7 | ipso
|
8 | ====
|
9 |
|
10 | Spec integrations
|
11 | -----------------
|
12 |
|
13 | A test decorator. (for [mocha](https://github.com/visionmedia/mocha))
|
14 |
|
15 |
|
16 |
|
17 | ```coffee
|
18 | ipso = require 'ipso'
|
19 |
|
20 | it 'does something', ipso (done) ->
|
21 |
|
22 | #
|
23 | # as usual
|
24 | #
|
25 |
|
26 | done()
|
27 |
|
28 | ```
|
29 |
|
30 | ### mode nodule injection
|
31 |
|
32 | ```coffee
|
33 | # thing = require 'thing'
|
34 |
|
35 | it 'does something for which it needs the thing', ipso (done, thing) ->
|
36 |
|
37 | #
|
38 | # then, as usual...
|
39 | #
|
40 |
|
41 | thing with: 'stuff', (err) ->
|
42 |
|
43 | err.message.should.equal 'incorrect stuff'
|
44 | done()
|
45 |
|
46 | ```
|
47 |
|
48 | * `done` can only be injected at position1
|
49 | * it must literally be called ""done""
|
50 | * there is currently no way to inject node modules with-dashes.or dots in their names.
|
51 | * injecting a module that is not already installed will not automatically install it in the 'background' and conveniently update the package file, yet.
|
52 |
|
53 |
|
54 | ### using promises
|
55 |
|
56 | #### it solves the chain problem
|
57 |
|
58 | These (↓) tests do not fail... Instead they timeout.
|
59 |
|
60 | ```coffee
|
61 |
|
62 | it 'does something ...', (done) ->
|
63 |
|
64 | functionThatReturnsAPromise().then ->
|
65 |
|
66 | true.should.equal false
|
67 | done()
|
68 |
|
69 | ```
|
70 |
|
71 | The problem is that `should` is throwing an [`AssertionError`](http://nodejs.org/api/assert.html) that is being caught by the promise handler instead of the `it()` function. This catch is a necessary component of the promise API - enabling `then()` chains to reject as designed.
|
72 |
|
73 | One possible solution is to chain in the test...
|
74 |
|
75 | ```coffee
|
76 |
|
77 | it 'does something ...', (done) ->
|
78 |
|
79 | functionThatReturnsAPromise().then ->
|
80 |
|
81 | true.should.equal false
|
82 | done()
|
83 |
|
84 | .then (->), done
|
85 |
|
86 | #
|
87 | # with the second done as the rejection handler, resulting in the throw being
|
88 | # passed to mocha's test resolver, causing the fail to be received by that
|
89 | # alternative to it's regular catcher.
|
90 | #
|
91 |
|
92 | ```
|
93 |
|
94 | ipso does the chain internally if the test returns a promise
|
95 |
|
96 |
|
97 | ```coffee
|
98 |
|
99 | it 'fails without timeout', ipso (done) ->
|
100 |
|
101 | functionThatReturnsAPromise().then ->
|
102 |
|
103 | true.should.equal false
|
104 | done()
|
105 |
|
106 | #
|
107 | # Note: this will still timeout if functionThatReturnsAPromise() rejects
|
108 | # TODO: it still times out on longer chains! grrr
|
109 | #
|
110 |
|
111 | ```
|
112 |
|
113 | ### `LocalNodule` injection
|
114 |
|
115 | later...
|
116 |
|
117 |
|
118 | ### active stubs / spy decorated injectables
|
119 |
|
120 | later...
|
121 |
|
122 | * set function and property expectations (rspec style)
|
123 |
|
124 |
|
125 | ### incidentally
|
126 |
|
127 | ```coffee
|
128 |
|
129 | it 'does something ...', ipso (facto) ->
|
130 |
|
131 | facto meta: 'data'
|
132 |
|
133 | #
|
134 | # also resolves the test
|
135 | #
|
136 |
|
137 | ```
|