chai-backbone-rails 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
window.Factory =
|
3
|
+
factories: {}
|
4
|
+
|
5
|
+
define: (factoryName, builder) ->
|
6
|
+
if factoryName.indexOf('-') > 0
|
7
|
+
throw "Factory name '#{factoryName}' can't use - in name. It clashes with the traits construct"
|
8
|
+
if @factories[factoryName]?
|
9
|
+
throw "Factory #{factoryName} is already defined"
|
10
|
+
@factories[factoryName] = builder
|
11
|
+
|
12
|
+
create: (nameWithTraits, options) ->
|
13
|
+
traits = nameWithTraits.split '-'
|
14
|
+
factoryName = traits.pop()
|
15
|
+
unless @factories[factoryName]?
|
16
|
+
throw "Factory #{factoryName} does not exist"
|
17
|
+
@factories[factoryName] options, traits...
|
18
|
+
|
19
|
+
resetFactories: ->
|
20
|
+
@factories = []
|
21
|
+
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
describe 'Factory', ->
|
2
|
+
|
3
|
+
beforeEach ->
|
4
|
+
Factory.define 'user', (options = {}, traits...) ->
|
5
|
+
[options, traits]
|
6
|
+
|
7
|
+
afterEach ->
|
8
|
+
Factory.resetFactories()
|
9
|
+
|
10
|
+
describe '::define', ->
|
11
|
+
|
12
|
+
it 'registers a factory', ->
|
13
|
+
result = Factory.create 'user'
|
14
|
+
result[0].should.deep.equal {}
|
15
|
+
result[1].should.deep.equal []
|
16
|
+
|
17
|
+
it 'raises an error on existing factory', ->
|
18
|
+
expect(-> Factory.define('user', ->)).to.throw 'Factory user is already defined'
|
19
|
+
|
20
|
+
it 'raises an error on naming conflict with traits', ->
|
21
|
+
expect(-> Factory.define('admin-user', ->)).to.throw 'Factory name \'admin-user\' can\'t use - in name. It clashes with the traits construct'
|
22
|
+
|
23
|
+
describe '::create', ->
|
24
|
+
|
25
|
+
it 'delivers options to the callback', ->
|
26
|
+
result = Factory.create 'user'
|
27
|
+
hello: 'world'
|
28
|
+
other: 'value'
|
29
|
+
result[0].should.deep.equal { hello: 'world', other: 'value' }
|
30
|
+
|
31
|
+
it 'delivers traits to the callback', ->
|
32
|
+
result = Factory.create 'male-admin-user'
|
33
|
+
result[1].should.deep.equal ['male', 'admin']
|
34
|
+
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chai-backbone-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 27
|
5
4
|
prerelease:
|
6
|
-
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
5
|
+
version: 0.0.3
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Matthijs Groen
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2012-
|
13
|
+
date: 2012-09-26 00:00:00 Z
|
19
14
|
dependencies: []
|
20
15
|
|
21
16
|
description: Chai.js matchers for Backbone.js framework
|
@@ -39,9 +34,11 @@ files:
|
|
39
34
|
- vendor/assets/javascripts/chai-backbone.js.coffee
|
40
35
|
- vendor/assets/javascripts/chai-backbone_spec.js.coffee
|
41
36
|
- vendor/assets/javascripts/chai-sinon.js.coffee
|
37
|
+
- vendor/assets/javascripts/factories.js.coffee
|
42
38
|
- vendor/assets/javascripts/sinon-1.4.2.js
|
43
39
|
- vendor/assets/javascripts/spec/chai-backbone_spec.js.coffee
|
44
40
|
- vendor/assets/javascripts/spec/chai-sinon_spec.js.coffee
|
41
|
+
- vendor/assets/javascripts/spec/factory_spec.js.coffee
|
45
42
|
homepage: ""
|
46
43
|
licenses: []
|
47
44
|
|
@@ -55,23 +52,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
55
52
|
requirements:
|
56
53
|
- - ">="
|
57
54
|
- !ruby/object:Gem::Version
|
58
|
-
hash: 3
|
59
|
-
segments:
|
60
|
-
- 0
|
61
55
|
version: "0"
|
62
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
57
|
none: false
|
64
58
|
requirements:
|
65
59
|
- - ">="
|
66
60
|
- !ruby/object:Gem::Version
|
67
|
-
hash: 3
|
68
|
-
segments:
|
69
|
-
- 0
|
70
61
|
version: "0"
|
71
62
|
requirements: []
|
72
63
|
|
73
64
|
rubyforge_project:
|
74
|
-
rubygems_version: 1.8.
|
65
|
+
rubygems_version: 1.8.5
|
75
66
|
signing_key:
|
76
67
|
specification_version: 3
|
77
68
|
summary: A set of assertion matchers to test Backbone code using Konacha in Rails
|