chai-backbone-rails 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -41,7 +41,8 @@ this can also be chained further:
|
|
41
41
|
|
42
42
|
### Changes
|
43
43
|
|
44
|
-
(-> view.$('p').length).
|
44
|
+
expect(-> view.$('p').length).to.change.by(4).when -> collection.add [{}, {}, {}, {}]
|
45
|
+
expect(-> result).to.not.change.when -> somethingElse()
|
45
46
|
|
46
47
|
Using Sinon Chai Matchers
|
47
48
|
-------------------------
|
@@ -104,14 +104,14 @@
|
|
104
104
|
|
105
105
|
# now assert if everything went according to spec
|
106
106
|
@assert spy.calledOnce,
|
107
|
-
"expected
|
108
|
-
"expected
|
107
|
+
"expected `#{route}` to route to #{methodName}",
|
108
|
+
"expected `#{route}` not to route to #{methodName}"
|
109
109
|
|
110
110
|
# verify arguments if they were provided
|
111
111
|
if options.arguments?
|
112
112
|
@assert spy.calledWith(options.arguments...),
|
113
|
-
"expected
|
114
|
-
"expected
|
113
|
+
"expected `#{methodName}` to be called with #{inspect options.arguments}, but was called with #{inspect spy.args[0]} instead",
|
114
|
+
"expected `#{methodName}` not to be called with #{inspect options.arguments}, but was"
|
115
115
|
|
116
116
|
chai.Assertion.addChainableMethod 'to', routeTo, -> this
|
117
117
|
|
@@ -123,10 +123,6 @@
|
|
123
123
|
chai.Assertion.addProperty 'change', ->
|
124
124
|
flag(this, 'change', true)
|
125
125
|
|
126
|
-
formatFunction = (func) ->
|
127
|
-
func.toString().replace(/^\s*function \(\) {\s*/, '').replace(/\s+}$/, '').replace(/\s*return\s*/, '')
|
128
|
-
|
129
|
-
changeBy = (delta) ->
|
130
126
|
definedActions = flag(this, 'whenActions') || []
|
131
127
|
|
132
128
|
# Add a around filter to the when actions
|
@@ -137,19 +133,35 @@
|
|
137
133
|
before: (context) ->
|
138
134
|
@startValue = flag(context, 'object')()
|
139
135
|
|
136
|
+
expectedChange: 0
|
137
|
+
|
140
138
|
# verify if our callback is triggered
|
141
139
|
after: (context) ->
|
142
140
|
negate = flag(context, 'negate')
|
143
141
|
flag(context, 'negate', @negate)
|
144
142
|
object = flag(context, 'object')
|
145
143
|
@endValue = object()
|
146
|
-
|
147
|
-
|
148
|
-
|
144
|
+
actualChange = @endValue - @startValue
|
145
|
+
|
146
|
+
result = (@expectedChange is actualChange)
|
147
|
+
result = !result if negate
|
148
|
+
context.assert result,
|
149
|
+
"expected `#{formatFunction object}` to change by #{@expectedChange} but it changed by #{actualChange}",
|
150
|
+
"expected `#{formatFunction object}` not to change, but it changed by #{actualChange}",
|
149
151
|
|
150
152
|
flag(context, 'negate', negate)
|
151
153
|
flag(this, 'whenActions', definedActions)
|
152
154
|
|
155
|
+
formatFunction = (func) ->
|
156
|
+
func.toString().replace(/^\s*function \(\) {\s*/, '').replace(/\s+}$/, '').replace(/\s*return\s*/, '')
|
157
|
+
|
158
|
+
changeBy = (delta) ->
|
159
|
+
definedActions = flag(this, 'whenActions') || []
|
160
|
+
if definedActions.length > 0
|
161
|
+
action = definedActions[definedActions.length - 1]
|
162
|
+
action.expectedChange = delta
|
163
|
+
flag(this, 'whenActions', definedActions)
|
164
|
+
|
153
165
|
chai.Assertion.addChainableMethod 'by', changeBy, -> this
|
154
166
|
|
155
167
|
)
|
@@ -42,3 +42,23 @@ describe 'Chai-Backbone', ->
|
|
42
42
|
it 'leaves the `to` keyword working properly', ->
|
43
43
|
expect('1').to.be.equal '1'
|
44
44
|
|
45
|
+
describe 'change', ->
|
46
|
+
|
47
|
+
it 'asserts the delta of a change', ->
|
48
|
+
result = 1
|
49
|
+
expect(-> result).to.change.by(3).when -> result += 3
|
50
|
+
|
51
|
+
it 'reports the contents of the subject method', ->
|
52
|
+
result = 1
|
53
|
+
expect(->
|
54
|
+
(-> 1 + 3; result).should.change.by(3).when -> result += 2
|
55
|
+
).to.throw 'expected `1 + 3;result;` to change by 3 but it changed by 2'
|
56
|
+
|
57
|
+
it 'can be negated to not.change', ->
|
58
|
+
result = 1
|
59
|
+
expect(->
|
60
|
+
expect(-> result).to.not.change.when -> result += 2
|
61
|
+
).to.throw 'expected `result;` not to change, but it changed by 2'
|
62
|
+
expect(-> result).to.not.change.when -> 1 + 3
|
63
|
+
|
64
|
+
|
metadata
CHANGED
@@ -1,23 +1,33 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: chai-backbone-rails
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Matthijs Groen
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
17
|
+
|
18
|
+
date: 2012-09-26 00:00:00 Z
|
13
19
|
dependencies: []
|
20
|
+
|
14
21
|
description: Chai.js matchers for Backbone.js framework
|
15
|
-
email:
|
22
|
+
email:
|
16
23
|
- matthijs.groen@gmail.com
|
17
24
|
executables: []
|
25
|
+
|
18
26
|
extensions: []
|
27
|
+
|
19
28
|
extra_rdoc_files: []
|
20
|
-
|
29
|
+
|
30
|
+
files:
|
21
31
|
- .gitignore
|
22
32
|
- Gemfile
|
23
33
|
- LICENSE
|
@@ -34,28 +44,38 @@ files:
|
|
34
44
|
- vendor/assets/javascripts/spec/chai-backbone_spec.js.coffee
|
35
45
|
- vendor/assets/javascripts/spec/chai-sinon_spec.js.coffee
|
36
46
|
- vendor/assets/javascripts/spec/factory_spec.js.coffee
|
37
|
-
homepage:
|
47
|
+
homepage: ""
|
38
48
|
licenses: []
|
49
|
+
|
39
50
|
post_install_message:
|
40
51
|
rdoc_options: []
|
41
|
-
|
52
|
+
|
53
|
+
require_paths:
|
42
54
|
- lib
|
43
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
56
|
none: false
|
45
|
-
requirements:
|
46
|
-
- -
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
|
49
|
-
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
55
73
|
requirements: []
|
74
|
+
|
56
75
|
rubyforge_project:
|
57
|
-
rubygems_version: 1.8.
|
76
|
+
rubygems_version: 1.8.15
|
58
77
|
signing_key:
|
59
78
|
specification_version: 3
|
60
79
|
summary: A set of assertion matchers to test Backbone code using Konacha in Rails
|
61
80
|
test_files: []
|
81
|
+
|