chai-backbone-rails 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +23 -2
- data/lib/chai-backbone-rails/version.rb +1 -1
- data/vendor/assets/javascripts/chai-backbone.js.coffee +7 -169
- data/vendor/assets/javascripts/chai-backbone_spec.js.coffee +1 -3
- data/vendor/assets/javascripts/chai-changes.js.coffee +183 -0
- data/vendor/assets/javascripts/spec/chai-backbone_spec.js.coffee +8 -64
- data/vendor/assets/javascripts/spec/chai-changes_spec.js.coffee +76 -0
- data/vendor/assets/javascripts/spec/chai-sinon_spec.js.coffee +1 -0
- data/vendor/assets/javascripts/spec/factory_spec.js.coffee +2 -0
- metadata +3 -1
data/README.md
CHANGED
@@ -39,12 +39,19 @@ this can also be chained further:
|
|
39
39
|
"page/3".should.route.to myRouter, "openPage", arguments: ["3"]
|
40
40
|
"page/3".should.route.to myRouter, "openPage", considering: [conflictingRouter]
|
41
41
|
|
42
|
-
|
42
|
+
Using Changes Chai matchers
|
43
|
+
---------------------------
|
44
|
+
|
45
|
+
#= require chai-changes
|
46
|
+
|
47
|
+
Plain change checking:
|
48
|
+
|
49
|
+
expect(-> result).to.change.when -> result += 1
|
50
|
+
expect(-> result).to.not.change.when -> somethingElse()
|
43
51
|
|
44
52
|
Changes by delta: 'change.by'
|
45
53
|
|
46
54
|
expect(-> view.$('p').length).to.change.by(4).when -> collection.add [{}, {}, {}, {}]
|
47
|
-
expect(-> result).to.not.change.when -> somethingElse()
|
48
55
|
|
49
56
|
Changes to end result: 'change.to'
|
50
57
|
|
@@ -129,6 +136,20 @@ You can also yield results:
|
|
129
136
|
Factory.create('abc') => 'a'
|
130
137
|
Factory.create('abc') => 'b'
|
131
138
|
|
139
|
+
Running the tests
|
140
|
+
=================
|
141
|
+
|
142
|
+
You can runn the tests by including:
|
143
|
+
|
144
|
+
#= require chai-backbone_spec
|
145
|
+
|
146
|
+
or you can run the suites seperately:
|
147
|
+
|
148
|
+
#= require spec/chai-backbone_spec
|
149
|
+
#= require spec/chai-sinon_spec
|
150
|
+
#= require spec/chai-changes_spec
|
151
|
+
#= require spec/factory_spec
|
152
|
+
|
132
153
|
|
133
154
|
Contributing
|
134
155
|
------------
|
@@ -1,4 +1,5 @@
|
|
1
1
|
#= require underscore
|
2
|
+
#= require ./chai-changes
|
2
3
|
|
3
4
|
((chaiBackbone) ->
|
4
5
|
# Module systems magic dance.
|
@@ -50,13 +51,6 @@
|
|
50
51
|
flag(context, 'negate', negate)
|
51
52
|
flag(this, 'whenActions', definedActions)
|
52
53
|
|
53
|
-
chai.Assertion.addMethod 'when', (val) ->
|
54
|
-
definedActions = flag(this, 'whenActions') || []
|
55
|
-
|
56
|
-
action.before?(this) for action in definedActions
|
57
|
-
val() # execute the 'when'
|
58
|
-
action.after?(this) for action in definedActions
|
59
|
-
|
60
54
|
# Verify if a url fragment is routed to a certain method on the router
|
61
55
|
# Options:
|
62
56
|
# - you can consider multiple routers to test routing priorities
|
@@ -113,168 +107,12 @@
|
|
113
107
|
"expected `#{methodName}` to be called with #{inspect options.arguments}, but was called with #{inspect spy.args[0]} instead",
|
114
108
|
"expected `#{methodName}` not to be called with #{inspect options.arguments}, but was"
|
115
109
|
|
116
|
-
chai.Assertion.
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
#
|
123
|
-
###
|
124
|
-
|
125
|
-
noChangeAssert = (context) ->
|
126
|
-
relevant = flag(context, 'no-change')
|
127
|
-
return unless relevant
|
128
|
-
|
129
|
-
negate = flag(context, 'negate')
|
130
|
-
flag(context, 'negate', @negate)
|
131
|
-
object = flag(context, 'object')
|
132
|
-
|
133
|
-
startValue = flag(context, 'changeStart')
|
134
|
-
endValue = object()
|
135
|
-
actualDelta = endValue - startValue
|
136
|
-
|
137
|
-
result = (0 is actualDelta)
|
138
|
-
result = !result if negate
|
139
|
-
context.assert result,
|
140
|
-
"not supported"
|
141
|
-
"expected `#{formatFunction object}` not to change, but it changed by #{actualDelta}",
|
142
|
-
flag(context, 'negate', negate)
|
143
|
-
|
144
|
-
changeByAssert = (context) ->
|
145
|
-
negate = flag(context, 'negate')
|
146
|
-
flag(context, 'negate', @negate)
|
147
|
-
object = flag(context, 'object')
|
148
|
-
|
149
|
-
startValue = flag(context, 'changeStart')
|
150
|
-
endValue = object()
|
151
|
-
actualDelta = endValue - startValue
|
152
|
-
|
153
|
-
result = (@expectedDelta is actualDelta)
|
154
|
-
result = !result if negate
|
155
|
-
context.assert result,
|
156
|
-
"expected `#{formatFunction object}` to change by #{@expectedDelta}, but it changed by #{actualDelta}",
|
157
|
-
"not supported"
|
158
|
-
flag(context, 'negate', negate)
|
159
|
-
|
160
|
-
changeToBeginAssert = (context) ->
|
161
|
-
negate = flag(context, 'negate')
|
162
|
-
flag(context, 'negate', @negate)
|
163
|
-
object = flag(context, 'object')
|
164
|
-
|
165
|
-
startValue = object()
|
166
|
-
|
167
|
-
result = !utils.eql(startValue, @expectedEndValue)
|
168
|
-
result = !result if negate
|
169
|
-
context.assert result,
|
170
|
-
"expected `#{formatFunction object}` to change to #{utils.inspect @expectedEndValue}, but it was already #{utils.inspect startValue}",
|
171
|
-
"not supported"
|
172
|
-
flag(context, 'negate', negate)
|
173
|
-
|
174
|
-
changeToAssert = (context) ->
|
175
|
-
negate = flag(context, 'negate')
|
176
|
-
flag(context, 'negate', @negate)
|
177
|
-
object = flag(context, 'object')
|
178
|
-
|
179
|
-
endValue = object()
|
180
|
-
|
181
|
-
result = utils.eql(endValue, @expectedEndValue)
|
182
|
-
result = !result if negate
|
183
|
-
context.assert result,
|
184
|
-
"expected `#{formatFunction object}` to change to #{utils.inspect @expectedEndValue}, but it changed to #{utils.inspect endValue}",
|
185
|
-
"not supported"
|
186
|
-
flag(context, 'negate', negate)
|
187
|
-
|
188
|
-
changeFromBeginAssert = (context) ->
|
189
|
-
negate = flag(context, 'negate')
|
190
|
-
flag(context, 'negate', @negate)
|
191
|
-
object = flag(context, 'object')
|
192
|
-
|
193
|
-
startValue = object()
|
194
|
-
|
195
|
-
result = utils.eql(startValue, @expectedStartValue)
|
196
|
-
result = !result if negate
|
197
|
-
context.assert result,
|
198
|
-
"expected `#{formatFunction object}` to change from #{utils.inspect @expectedStartValue}, but it changed from #{utils.inspect startValue}",
|
199
|
-
"not supported"
|
200
|
-
flag(context, 'negate', negate)
|
201
|
-
|
202
|
-
changeFromAssert = (context) ->
|
203
|
-
negate = flag(context, 'negate')
|
204
|
-
flag(context, 'negate', @negate)
|
205
|
-
object = flag(context, 'object')
|
206
|
-
|
207
|
-
startValue = flag(context, 'changeStart')
|
208
|
-
endValue = object()
|
209
|
-
|
210
|
-
result = !utils.eql(startValue, endValue)
|
211
|
-
result = !result if negate
|
212
|
-
context.assert result,
|
213
|
-
"expected `#{formatFunction object}` to change from #{utils.inspect @expectedStartValue}, but it did not change"
|
214
|
-
"not supported"
|
215
|
-
flag(context, 'negate', negate)
|
216
|
-
|
217
|
-
# Verifies if the subject return value changes by given delta 'when' events happen
|
218
|
-
#
|
219
|
-
# Examples:
|
220
|
-
# (-> resultValue).should.change.by(1).when -> resultValue += 1
|
221
|
-
#
|
222
|
-
chai.Assertion.addProperty 'change', ->
|
223
|
-
flag(this, 'no-change', true)
|
224
|
-
|
225
|
-
definedActions = flag(this, 'whenActions') || []
|
226
|
-
# Add a around filter to the when actions
|
227
|
-
definedActions.push
|
228
|
-
negate: flag(this, 'negate')
|
229
|
-
|
230
|
-
# set up the callback to trigger
|
231
|
-
before: (context) ->
|
232
|
-
startValue = flag(context, 'object')()
|
233
|
-
flag(context, 'changeStart', startValue)
|
234
|
-
after: noChangeAssert
|
235
|
-
|
236
|
-
flag(this, 'whenActions', definedActions)
|
237
|
-
|
238
|
-
formatFunction = (func) ->
|
239
|
-
func.toString().replace(/^\s*function \(\) {\s*/, '').replace(/\s+}$/, '').replace(/\s*return\s*/, '')
|
240
|
-
|
241
|
-
changeBy = (delta) ->
|
242
|
-
flag(this, 'no-change', false)
|
243
|
-
definedActions = flag(this, 'whenActions') || []
|
244
|
-
# Add a around filter to the when actions
|
245
|
-
definedActions.push
|
246
|
-
negate: flag(this, 'negate')
|
247
|
-
expectedDelta: delta
|
248
|
-
after: changeByAssert
|
249
|
-
flag(this, 'whenActions', definedActions)
|
250
|
-
|
251
|
-
chai.Assertion.addChainableMethod 'by', changeBy, -> this
|
252
|
-
|
253
|
-
changeTo = (endValue) ->
|
254
|
-
flag(this, 'no-change', false)
|
255
|
-
definedActions = flag(this, 'whenActions') || []
|
256
|
-
# Add a around filter to the when actions
|
257
|
-
definedActions.push
|
258
|
-
negate: flag(this, 'negate')
|
259
|
-
expectedEndValue: endValue
|
260
|
-
before: changeToBeginAssert
|
261
|
-
after: changeToAssert
|
262
|
-
flag(this, 'whenActions', definedActions)
|
263
|
-
|
264
|
-
chai.Assertion.addChainableMethod 'to', changeTo, -> this
|
265
|
-
|
266
|
-
changeFrom = (startValue) ->
|
267
|
-
flag(this, 'no-change', false)
|
268
|
-
definedActions = flag(this, 'whenActions') || []
|
269
|
-
# Add a around filter to the when actions
|
270
|
-
definedActions.push
|
271
|
-
negate: flag(this, 'negate')
|
272
|
-
expectedStartValue: startValue
|
273
|
-
before: changeFromBeginAssert
|
274
|
-
after: changeFromAssert
|
275
|
-
flag(this, 'whenActions', definedActions)
|
276
|
-
|
277
|
-
chai.Assertion.addChainableMethod 'from', changeFrom, -> this
|
110
|
+
chai.Assertion.overwriteProperty 'to', (_super) ->
|
111
|
+
->
|
112
|
+
if flag(this, 'routing')
|
113
|
+
routeTo
|
114
|
+
else
|
115
|
+
_super.apply(this, arguments)
|
278
116
|
|
279
117
|
)
|
280
118
|
|
@@ -0,0 +1,183 @@
|
|
1
|
+
|
2
|
+
((chaiChanges) ->
|
3
|
+
# Module systems magic dance.
|
4
|
+
if (typeof require == "function" && typeof exports == "object" && typeof module == "object")
|
5
|
+
# NodeJS
|
6
|
+
module.exports = chaiChanges
|
7
|
+
else if (typeof define == "function" && define.amd)
|
8
|
+
# AMD
|
9
|
+
define -> chaiChanges
|
10
|
+
else
|
11
|
+
# Other environment (usually <script> tag): plug in to global chai instance directly.
|
12
|
+
chai.use chaiChanges
|
13
|
+
)((chai, utils) ->
|
14
|
+
inspect = utils.inspect
|
15
|
+
flag = utils.flag
|
16
|
+
|
17
|
+
###
|
18
|
+
#
|
19
|
+
# Changes Matchers
|
20
|
+
#
|
21
|
+
###
|
22
|
+
|
23
|
+
chai.Assertion.addMethod 'when', (val) ->
|
24
|
+
definedActions = flag(this, 'whenActions') || []
|
25
|
+
|
26
|
+
action.before?(this) for action in definedActions
|
27
|
+
val() # execute the 'when'
|
28
|
+
action.after?(this) for action in definedActions
|
29
|
+
|
30
|
+
noChangeAssert = (context) ->
|
31
|
+
relevant = flag(context, 'no-change')
|
32
|
+
return unless relevant
|
33
|
+
|
34
|
+
negate = flag(context, 'negate')
|
35
|
+
flag(context, 'negate', @negate)
|
36
|
+
object = flag(context, 'object')
|
37
|
+
|
38
|
+
startValue = flag(context, 'changeStart')
|
39
|
+
endValue = object()
|
40
|
+
|
41
|
+
result = !utils.eql(endValue, startValue)
|
42
|
+
context.assert result,
|
43
|
+
"expected `#{formatFunction object}` to change, but it stayed #{utils.inspect startValue}",
|
44
|
+
"expected `#{formatFunction object}` not to change, but it changed from #{utils.inspect startValue} to #{utils.inspect endValue}",
|
45
|
+
flag(context, 'negate', negate)
|
46
|
+
|
47
|
+
changeByAssert = (context) ->
|
48
|
+
negate = flag(context, 'negate')
|
49
|
+
flag(context, 'negate', @negate)
|
50
|
+
object = flag(context, 'object')
|
51
|
+
|
52
|
+
startValue = flag(context, 'changeStart')
|
53
|
+
endValue = object()
|
54
|
+
actualDelta = endValue - startValue
|
55
|
+
|
56
|
+
result = (@expectedDelta is actualDelta)
|
57
|
+
result = !result if negate
|
58
|
+
context.assert result,
|
59
|
+
"expected `#{formatFunction object}` to change by #{@expectedDelta}, but it changed by #{actualDelta}",
|
60
|
+
"not supported"
|
61
|
+
flag(context, 'negate', negate)
|
62
|
+
|
63
|
+
changeToBeginAssert = (context) ->
|
64
|
+
negate = flag(context, 'negate')
|
65
|
+
flag(context, 'negate', @negate)
|
66
|
+
object = flag(context, 'object')
|
67
|
+
|
68
|
+
startValue = object()
|
69
|
+
|
70
|
+
result = !utils.eql(startValue, @expectedEndValue)
|
71
|
+
result = !result if negate
|
72
|
+
context.assert result,
|
73
|
+
"expected `#{formatFunction object}` to change to #{utils.inspect @expectedEndValue}, but it was already #{utils.inspect startValue}",
|
74
|
+
"not supported"
|
75
|
+
flag(context, 'negate', negate)
|
76
|
+
|
77
|
+
changeToAssert = (context) ->
|
78
|
+
negate = flag(context, 'negate')
|
79
|
+
flag(context, 'negate', @negate)
|
80
|
+
object = flag(context, 'object')
|
81
|
+
|
82
|
+
endValue = object()
|
83
|
+
|
84
|
+
result = utils.eql(endValue, @expectedEndValue)
|
85
|
+
result = !result if negate
|
86
|
+
context.assert result,
|
87
|
+
"expected `#{formatFunction object}` to change to #{utils.inspect @expectedEndValue}, but it changed to #{utils.inspect endValue}",
|
88
|
+
"not supported"
|
89
|
+
flag(context, 'negate', negate)
|
90
|
+
|
91
|
+
changeFromBeginAssert = (context) ->
|
92
|
+
negate = flag(context, 'negate')
|
93
|
+
flag(context, 'negate', @negate)
|
94
|
+
object = flag(context, 'object')
|
95
|
+
|
96
|
+
startValue = object()
|
97
|
+
|
98
|
+
result = utils.eql(startValue, @expectedStartValue)
|
99
|
+
result = !result if negate
|
100
|
+
context.assert result,
|
101
|
+
"expected `#{formatFunction object}` to change from #{utils.inspect @expectedStartValue}, but it changed from #{utils.inspect startValue}",
|
102
|
+
"not supported"
|
103
|
+
flag(context, 'negate', negate)
|
104
|
+
|
105
|
+
changeFromAssert = (context) ->
|
106
|
+
negate = flag(context, 'negate')
|
107
|
+
flag(context, 'negate', @negate)
|
108
|
+
object = flag(context, 'object')
|
109
|
+
|
110
|
+
startValue = flag(context, 'changeStart')
|
111
|
+
endValue = object()
|
112
|
+
|
113
|
+
result = !utils.eql(startValue, endValue)
|
114
|
+
result = !result if negate
|
115
|
+
context.assert result,
|
116
|
+
"expected `#{formatFunction object}` to change from #{utils.inspect @expectedStartValue}, but it did not change"
|
117
|
+
"not supported"
|
118
|
+
flag(context, 'negate', negate)
|
119
|
+
|
120
|
+
# Verifies if the subject return value changes by given delta 'when' events happen
|
121
|
+
#
|
122
|
+
# Examples:
|
123
|
+
# (-> resultValue).should.change.by(1).when -> resultValue += 1
|
124
|
+
#
|
125
|
+
chai.Assertion.addProperty 'change', ->
|
126
|
+
flag(this, 'no-change', true)
|
127
|
+
|
128
|
+
definedActions = flag(this, 'whenActions') || []
|
129
|
+
# Add a around filter to the when actions
|
130
|
+
definedActions.push
|
131
|
+
negate: flag(this, 'negate')
|
132
|
+
|
133
|
+
# set up the callback to trigger
|
134
|
+
before: (context) ->
|
135
|
+
startValue = flag(context, 'object')()
|
136
|
+
flag(context, 'changeStart', startValue)
|
137
|
+
after: noChangeAssert
|
138
|
+
|
139
|
+
flag(this, 'whenActions', definedActions)
|
140
|
+
|
141
|
+
formatFunction = (func) ->
|
142
|
+
func.toString().replace(/^\s*function \(\) {\s*/, '').replace(/\s+}$/, '').replace(/\s*return\s*/, '')
|
143
|
+
|
144
|
+
changeBy = (delta) ->
|
145
|
+
flag(this, 'no-change', false)
|
146
|
+
definedActions = flag(this, 'whenActions') || []
|
147
|
+
# Add a around filter to the when actions
|
148
|
+
definedActions.push
|
149
|
+
negate: flag(this, 'negate')
|
150
|
+
expectedDelta: delta
|
151
|
+
after: changeByAssert
|
152
|
+
flag(this, 'whenActions', definedActions)
|
153
|
+
|
154
|
+
chai.Assertion.addChainableMethod 'by', changeBy, -> this
|
155
|
+
|
156
|
+
changeTo = (endValue) ->
|
157
|
+
flag(this, 'no-change', false)
|
158
|
+
definedActions = flag(this, 'whenActions') || []
|
159
|
+
# Add a around filter to the when actions
|
160
|
+
definedActions.push
|
161
|
+
negate: flag(this, 'negate')
|
162
|
+
expectedEndValue: endValue
|
163
|
+
before: changeToBeginAssert
|
164
|
+
after: changeToAssert
|
165
|
+
flag(this, 'whenActions', definedActions)
|
166
|
+
|
167
|
+
chai.Assertion.addChainableMethod 'to', changeTo, -> this
|
168
|
+
|
169
|
+
changeFrom = (startValue) ->
|
170
|
+
flag(this, 'no-change', false)
|
171
|
+
definedActions = flag(this, 'whenActions') || []
|
172
|
+
# Add a around filter to the when actions
|
173
|
+
definedActions.push
|
174
|
+
negate: flag(this, 'negate')
|
175
|
+
expectedStartValue: startValue
|
176
|
+
before: changeFromBeginAssert
|
177
|
+
after: changeFromAssert
|
178
|
+
flag(this, 'whenActions', definedActions)
|
179
|
+
|
180
|
+
chai.Assertion.addChainableMethod 'from', changeFrom, -> this
|
181
|
+
|
182
|
+
)
|
183
|
+
|
@@ -1,3 +1,4 @@
|
|
1
|
+
#= require ./../chai-backbone
|
1
2
|
|
2
3
|
describe 'Chai-Backbone', ->
|
3
4
|
|
@@ -35,73 +36,16 @@ describe 'Chai-Backbone', ->
|
|
35
36
|
|
36
37
|
it 'checks if a method is trigger by route', ->
|
37
38
|
"route1/sub".should.route.to router, 'subRoute'
|
39
|
+
expect(->
|
40
|
+
"route1/ere".should.route.to router, 'subRoute'
|
41
|
+
).to.throw 'expected `route1/ere` to route to subRoute'
|
38
42
|
|
39
43
|
it 'verifies argument parsing', ->
|
40
|
-
"route2/argVal".should.route.to router, 'routeWithArg',
|
44
|
+
"route2/argVal".should.route.to router, 'routeWithArg', arguments: ['argVal']
|
45
|
+
expect(->
|
46
|
+
"route2/ere".should.route.to router, 'routeWithArg', arguments: ['argVal']
|
47
|
+
).to.throw 'expected `routeWithArg` to be called with [ \'argVal\' ], but was called with [ \'ere\' ] instead'
|
41
48
|
|
42
49
|
it 'leaves the `to` keyword working properly', ->
|
43
50
|
expect('1').to.be.equal '1'
|
44
51
|
|
45
|
-
describe 'change', ->
|
46
|
-
|
47
|
-
describe 'by delta', ->
|
48
|
-
|
49
|
-
it 'asserts the delta of a change', ->
|
50
|
-
result = 1
|
51
|
-
expect(-> result).to.change.by(3).when -> result += 3
|
52
|
-
|
53
|
-
it 'reports the contents of the subject method', ->
|
54
|
-
result = 1
|
55
|
-
expect(->
|
56
|
-
(-> 1 + 3; result).should.change.by(3).when -> result += 2
|
57
|
-
).to.throw 'expected `1 + 3;result;` to change by 3, but it changed by 2'
|
58
|
-
|
59
|
-
it 'can be negated to not.change', ->
|
60
|
-
result = 1
|
61
|
-
expect(->
|
62
|
-
expect(-> result).to.not.change.when -> result += 2
|
63
|
-
).to.throw 'expected `result;` not to change, but it changed by 2'
|
64
|
-
expect(-> result).to.not.change.when -> 1 + 3
|
65
|
-
|
66
|
-
describe 'to', ->
|
67
|
-
|
68
|
-
it 'asserts end values', ->
|
69
|
-
result = ['a']
|
70
|
-
expect(-> result).to.change.to(['b']).when -> result = ['b']
|
71
|
-
|
72
|
-
it 'reports the mismatched end value', ->
|
73
|
-
result = ['a']
|
74
|
-
expect(->
|
75
|
-
expect(-> result).to.change.to(['b']).when -> result = ['c']
|
76
|
-
).to.throw 'expected `result;` to change to [ \'b\' ], but it changed to [ \'c\' ]'
|
77
|
-
|
78
|
-
it 'raises an error if there was no change', ->
|
79
|
-
result = 'b'
|
80
|
-
expect(->
|
81
|
-
expect(-> result).to.change.to('b').when -> result = 'b'
|
82
|
-
).to.throw 'expected `result;` to change to \'b\', but it was already \'b\''
|
83
|
-
|
84
|
-
describe 'from', ->
|
85
|
-
|
86
|
-
it 'asserts start values', ->
|
87
|
-
result = ['a']
|
88
|
-
expect(-> result).to.change.from(['a']).when -> result = ['b']
|
89
|
-
|
90
|
-
it 'reports the mismatched start value', ->
|
91
|
-
result = ['a']
|
92
|
-
expect(->
|
93
|
-
expect(-> result).to.change.from(['b']).when -> result = ['c']
|
94
|
-
).to.throw 'expected `result;` to change from [ \'b\' ], but it changed from [ \'a\' ]'
|
95
|
-
|
96
|
-
it 'raises an error if there was no change', ->
|
97
|
-
result = 'b'
|
98
|
-
expect(->
|
99
|
-
expect(-> result).to.change.from('b').when -> result = 'b'
|
100
|
-
).to.throw 'expected `result;` to change from \'b\', but it did not change'
|
101
|
-
|
102
|
-
|
103
|
-
describe 'mix and match', ->
|
104
|
-
|
105
|
-
it 'can use from to and by in one sentence', ->
|
106
|
-
result = 3
|
107
|
-
expect(-> result).to.change.from(3).to(5).by(2).when -> result = 5
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#= require ./../chai-changes
|
2
|
+
|
3
|
+
describe 'Chai-Changes', ->
|
4
|
+
|
5
|
+
describe 'change', ->
|
6
|
+
|
7
|
+
describe 'at all', ->
|
8
|
+
|
9
|
+
it 'detects changes', ->
|
10
|
+
result = 1
|
11
|
+
expect(->
|
12
|
+
expect(-> result).to.change.when -> result = 1
|
13
|
+
).to.throw 'expected `result;` to change, but it stayed 1'
|
14
|
+
expect(-> result).to.change.when -> result += 1
|
15
|
+
|
16
|
+
it 'can be negated to not.change', ->
|
17
|
+
result = 1
|
18
|
+
expect(->
|
19
|
+
expect(-> result).to.not.change.when -> result += 2
|
20
|
+
).to.throw 'expected `result;` not to change, but it changed from 1 to 3'
|
21
|
+
expect(-> result).to.not.change.when -> 1 + 3
|
22
|
+
|
23
|
+
describe 'by delta', ->
|
24
|
+
|
25
|
+
it 'asserts the delta of a change', ->
|
26
|
+
result = 1
|
27
|
+
expect(-> result).to.change.by(3).when -> result += 3
|
28
|
+
|
29
|
+
it 'reports the contents of the subject method', ->
|
30
|
+
result = 1
|
31
|
+
expect(->
|
32
|
+
(-> 1 + 3; result).should.change.by(3).when -> result += 2
|
33
|
+
).to.throw 'expected `1 + 3;result;` to change by 3, but it changed by 2'
|
34
|
+
|
35
|
+
describe 'to', ->
|
36
|
+
|
37
|
+
it 'asserts end values', ->
|
38
|
+
result = ['a']
|
39
|
+
expect(-> result).to.change.to(['b']).when -> result = ['b']
|
40
|
+
|
41
|
+
it 'reports the mismatched end value', ->
|
42
|
+
result = ['a']
|
43
|
+
expect(->
|
44
|
+
expect(-> result).to.change.to(['b']).when -> result = ['c']
|
45
|
+
).to.throw 'expected `result;` to change to [ \'b\' ], but it changed to [ \'c\' ]'
|
46
|
+
|
47
|
+
it 'raises an error if there was no change', ->
|
48
|
+
result = 'b'
|
49
|
+
expect(->
|
50
|
+
expect(-> result).to.change.to('b').when -> result = 'b'
|
51
|
+
).to.throw 'expected `result;` to change to \'b\', but it was already \'b\''
|
52
|
+
|
53
|
+
describe 'from', ->
|
54
|
+
|
55
|
+
it 'asserts start values', ->
|
56
|
+
result = ['a']
|
57
|
+
expect(-> result).to.change.from(['a']).when -> result = ['b']
|
58
|
+
|
59
|
+
it 'reports the mismatched start value', ->
|
60
|
+
result = ['a']
|
61
|
+
expect(->
|
62
|
+
expect(-> result).to.change.from(['b']).when -> result = ['c']
|
63
|
+
).to.throw 'expected `result;` to change from [ \'b\' ], but it changed from [ \'a\' ]'
|
64
|
+
|
65
|
+
it 'raises an error if there was no change', ->
|
66
|
+
result = 'b'
|
67
|
+
expect(->
|
68
|
+
expect(-> result).to.change.from('b').when -> result = 'b'
|
69
|
+
).to.throw 'expected `result;` to change from \'b\', but it did not change'
|
70
|
+
|
71
|
+
describe 'mix and match', ->
|
72
|
+
|
73
|
+
it 'can use from to and by in one sentence', ->
|
74
|
+
result = 3
|
75
|
+
expect(-> result).to.change.from(3).to(5).by(2).when -> result = 5
|
76
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chai-backbone-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -28,10 +28,12 @@ files:
|
|
28
28
|
- lib/chai-backbone-rails/version.rb
|
29
29
|
- vendor/assets/javascripts/chai-backbone.js.coffee
|
30
30
|
- vendor/assets/javascripts/chai-backbone_spec.js.coffee
|
31
|
+
- vendor/assets/javascripts/chai-changes.js.coffee
|
31
32
|
- vendor/assets/javascripts/chai-sinon.js.coffee
|
32
33
|
- vendor/assets/javascripts/factories.js.coffee
|
33
34
|
- vendor/assets/javascripts/sinon-1.4.2.js
|
34
35
|
- vendor/assets/javascripts/spec/chai-backbone_spec.js.coffee
|
36
|
+
- vendor/assets/javascripts/spec/chai-changes_spec.js.coffee
|
35
37
|
- vendor/assets/javascripts/spec/chai-sinon_spec.js.coffee
|
36
38
|
- vendor/assets/javascripts/spec/factory_spec.js.coffee
|
37
39
|
homepage: https://github.com/matthijsgroen/chai-backbone-rails
|