@@ -9,8 +9,8 @@ import { module, test } from 'qunit';
99
1010let sandbox , adapters ;
1111
12- module ( 'Unit | Mixin | adaptable' , {
13- beforeEach ( ) {
12+ module ( 'Unit | Mixin | adaptable' , function ( hooks ) {
13+ hooks . beforeEach ( function ( ) {
1414 sandbox = Sinon . sandbox . create ( ) ;
1515 adapters = {
1616 starships : [
@@ -28,157 +28,157 @@ module('Unit | Mixin | adaptable', {
2828 }
2929 ]
3030 } ;
31- } ,
31+ } ) ;
3232
33- afterEach ( ) {
33+ hooks . afterEach ( function ( ) {
3434 sandbox . restore ( ) ;
35- }
36- } ) ;
37-
38- test ( 'it initialises the adapters object' , function ( assert ) {
39- let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
40- let subject = AdaptableObject . create ( ) ;
41-
42- assert . deepEqual ( get ( subject , '_adapters' ) , { } ) ;
43- } ) ;
35+ } ) ;
4436
45- test ( 'it initialises the context object' , function ( assert ) {
46- let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
47- let subject = AdaptableObject . create ( ) ;
37+ test ( 'it initialises the adapters object' , function ( assert ) {
38+ let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
39+ let subject = AdaptableObject . create ( ) ;
4840
49- assert . deepEqual ( get ( subject , 'context ' ) , { } ) ;
50- } ) ;
41+ assert . deepEqual ( get ( subject , '_adapters ' ) , { } ) ;
42+ } ) ;
5143
52- test ( 'it registers configured adapters ' , function ( assert ) {
53- let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
54- let subject = AdaptableObject . create ( ) ;
44+ test ( 'it initialises the context object ' , function ( assert ) {
45+ let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
46+ let subject = AdaptableObject . create ( ) ;
5547
56- sandbox . stub ( subject , '_lookupAdapter' ) . callsFake ( function ( ) {
57- return Starship ; // Return a non-instantiated adapter.
58- } )
48+ assert . deepEqual ( get ( subject , 'context' ) , { } ) ;
49+ } ) ;
5950
60- subject . activateAdapters ( adapters . starships ) ;
61- assert . ok ( subject ) ;
62- } ) ;
51+ test ( 'it registers configured adapters' , function ( assert ) {
52+ let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
53+ let subject = AdaptableObject . create ( ) ;
6354
64- test ( 'it passes config options to the configured adapters' , function ( assert ) {
65- let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
66- let subject = AdaptableObject . create ( ) ;
55+ sandbox . stub ( subject , '_lookupAdapter' ) . callsFake ( function ( ) {
56+ return Starship ; // Return a non-instantiated adapter.
57+ } )
6758
68- sandbox . stub ( subject , '_lookupAdapter' ) . callsFake ( function ( ) {
69- return Starship ; // Return a non-instantiated adapter.
59+ subject . activateAdapters ( adapters . starships ) ;
60+ assert . ok ( subject ) ;
7061 } ) ;
7162
72- subject . activateAdapters ( adapters . starships ) ;
73- assert . equal ( get ( subject , '_adapters.Enterprise.config.captain' ) , 'Jean-Luc Picard' ) ;
74- } ) ;
75-
76- test ( '#invoke invokes the named method on activated adapters' , function ( assert ) {
77- assert . expect ( 6 ) ;
63+ test ( 'it passes config options to the configured adapters' , function ( assert ) {
64+ let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
65+ let subject = AdaptableObject . create ( ) ;
7866
79- let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
80- let subject = AdaptableObject . create ( ) ;
67+ sandbox . stub ( subject , '_lookupAdapter' ) . callsFake ( function ( ) {
68+ return Starship ; // Return a non-instantiated adapter.
69+ } ) ;
8170
82- sandbox . stub ( subject , '_lookupAdapter' ) . callsFake ( function ( ) {
83- return Starship ; // Return a non-instantiated adapter.
71+ subject . activateAdapters ( adapters . starships ) ;
72+ assert . equal ( get ( subject , '_adapters.Enterprise.config.captain' ) , 'Jean-Luc Picard' ) ;
8473 } ) ;
8574
86- subject . activateAdapters ( adapters . starships ) ;
75+ test ( '#invoke invokes the named method on activated adapters' , function ( assert ) {
76+ assert . expect ( 6 ) ;
8777
88- const EnterpriseStub = sandbox . stub ( get ( subject , '_adapters.Enterprise' ) , '_makeItSo' ) ;
89- const VoyagerStub = sandbox . stub ( get ( subject , '_adapters.Voyager' ) , '_makeItSo' ) ;
78+ let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
79+ let subject = AdaptableObject . create ( ) ;
9080
91- const EnterpriseSpy = sandbox . spy ( get ( subject , '_adapters.Enterprise' ) , 'warp' ) ;
92- const VoyagerSpy = sandbox . spy ( get ( subject , '_adapters.Voyager' ) , 'warp' ) ;
81+ sandbox . stub ( subject , '_lookupAdapter' ) . callsFake ( function ( ) {
82+ return Starship ; // Return a non-instantiated adapter.
83+ } ) ;
9384
94- const warpFactor = {
95- factor : 8
96- } ;
85+ subject . activateAdapters ( adapters . starships ) ;
9786
98- subject . invoke ( 'warp' , warpFactor ) ;
87+ const EnterpriseStub = sandbox . stub ( get ( subject , '_adapters.Enterprise' ) , '_makeItSo' ) ;
88+ const VoyagerStub = sandbox . stub ( get ( subject , '_adapters.Voyager' ) , '_makeItSo' ) ;
9989
100- assert . ok ( EnterpriseSpy . calledOnce ) ;
101- assert . ok ( EnterpriseSpy . calledWith ( warpFactor ) ) ;
102- assert . ok ( EnterpriseStub . calledOnce ) ;
90+ const EnterpriseSpy = sandbox . spy ( get ( subject , '_adapters.Enterprise' ) , 'warp' ) ;
91+ const VoyagerSpy = sandbox . spy ( get ( subject , '_adapters.Voyager' ) , 'warp' ) ;
10392
104- assert . ok ( VoyagerSpy . calledOnce ) ;
105- assert . ok ( VoyagerSpy . calledWith ( warpFactor ) ) ;
106- assert . ok ( VoyagerStub . calledOnce ) ;
107- } ) ;
93+ const warpFactor = {
94+ factor : 8
95+ } ;
10896
109- test ( '#invoke invokes the named method on a single activated adapter' , function ( assert ) {
110- assert . expect ( 3 ) ;
97+ subject . invoke ( 'warp' , warpFactor ) ;
11198
112- let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
113- let subject = AdaptableObject . create ( ) ;
99+ assert . ok ( EnterpriseSpy . calledOnce ) ;
100+ assert . ok ( EnterpriseSpy . calledWith ( warpFactor ) ) ;
101+ assert . ok ( EnterpriseStub . calledOnce ) ;
114102
115- sandbox . stub ( subject , '_lookupAdapter' ) . callsFake ( function ( ) {
116- return Starship ; // Return a non-instantiated adapter.
103+ assert . ok ( VoyagerSpy . calledOnce ) ;
104+ assert . ok ( VoyagerSpy . calledWith ( warpFactor ) ) ;
105+ assert . ok ( VoyagerStub . calledOnce ) ;
117106 } ) ;
118107
119- subject . activateAdapters ( adapters . starships ) ;
108+ test ( '#invoke invokes the named method on a single activated adapter' , function ( assert ) {
109+ assert . expect ( 3 ) ;
120110
121- const stub = sandbox . stub ( get ( subject , '_adapters.Enterprise' ) , '_makeItSo' ) ;
122- const spy = sandbox . spy ( get ( subject , '_adapters.Enterprise' ) , 'warp' ) ;
111+ let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
112+ let subject = AdaptableObject . create ( ) ;
123113
124- const warpFactor = {
125- factor : 8
126- } ;
114+ sandbox . stub ( subject , '_lookupAdapter' ) . callsFake ( function ( ) {
115+ return Starship ; // Return a non-instantiated adapter.
116+ } ) ;
127117
128- subject . invoke ( 'warp' , 'Enterprise' , warpFactor ) ;
118+ subject . activateAdapters ( adapters . starships ) ;
129119
130- assert . ok ( spy . calledOnce ) ;
131- assert . ok ( spy . calledWith ( warpFactor ) ) ;
132- assert . ok ( stub . calledOnce ) ;
133- } ) ;
120+ const stub = sandbox . stub ( get ( subject , '_adapters.Enterprise' ) , '_makeItSo' ) ;
121+ const spy = sandbox . spy ( get ( subject , '_adapters.Enterprise' ) , 'warp' ) ;
134122
135- test ( '#invoke includes `context` properties' , function ( assert ) {
136- assert . expect ( 3 ) ;
123+ const warpFactor = {
124+ factor : 8
125+ } ;
137126
138- let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
139- let subject = AdaptableObject . create ( ) ;
127+ subject . invoke ( 'warp' , 'Enterprise' , warpFactor ) ;
140128
141- sandbox . stub ( subject , '_lookupAdapter' ) . callsFake ( function ( ) {
142- return Starship ; // Return a non-instantiated adapter.
129+ assert . ok ( spy . calledOnce ) ;
130+ assert . ok ( spy . calledWith ( warpFactor ) ) ;
131+ assert . ok ( stub . calledOnce ) ;
143132 } ) ;
144133
145- subject . activateAdapters ( adapters . starships ) ;
134+ test ( '#invoke includes `context` properties' , function ( assert ) {
135+ assert . expect ( 3 ) ;
146136
147- const stub = sandbox . stub ( get ( subject , '_adapters.Enterprise' ) , '_makeItSo' ) ;
148- const spy = sandbox . spy ( get ( subject , '_adapters.Enterprise' ) , 'warp' ) ;
137+ let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
138+ let subject = AdaptableObject . create ( ) ;
149139
150- const warpFactor = {
151- factor : 8
152- } ;
140+ sandbox . stub ( subject , '_lookupAdapter' ) . callsFake ( function ( ) {
141+ return Starship ; // Return a non-instantiated adapter.
142+ } ) ;
153143
154- set ( subject , 'context.warpCapabilities' , true ) ;
155- subject . invoke ( 'warp' , 'Enterprise' , warpFactor ) ;
144+ subject . activateAdapters ( adapters . starships ) ;
156145
157- assert . ok ( spy . calledOnce ) ;
158- assert . ok ( spy . calledWith ( { warpCapabilities : true , factor : 8 } ) ) ;
159- assert . ok ( stub . calledOnce ) ;
160- } ) ;
146+ const stub = sandbox . stub ( get ( subject , '_adapters.Enterprise' ) , '_makeItSo' ) ;
147+ const spy = sandbox . spy ( get ( subject , '_adapters.Enterprise' ) , 'warp' ) ;
161148
162- test ( '#invoke does not leak options between calls' , function ( assert ) {
163- assert . expect ( 3 ) ;
149+ const warpFactor = {
150+ factor : 8
151+ } ;
164152
165- let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
166- let subject = AdaptableObject . create ( ) ;
153+ set ( subject , 'context.warpCapabilities' , true ) ;
154+ subject . invoke ( 'warp' , 'Enterprise' , warpFactor ) ;
167155
168- sandbox . stub ( subject , '_lookupAdapter' ) . callsFake ( function ( ) {
169- return Starship ; // Return a non-instantiated adapter.
156+ assert . ok ( spy . calledOnce ) ;
157+ assert . ok ( spy . calledWith ( { warpCapabilities : true , factor : 8 } ) ) ;
158+ assert . ok ( stub . calledOnce ) ;
170159 } ) ;
171160
172- subject . activateAdapters ( adapters . starships ) ;
161+ test ( '#invoke does not leak options between calls' , function ( assert ) {
162+ assert . expect ( 3 ) ;
163+
164+ let AdaptableObject = EmberObject . extend ( AdaptableMixin ) ;
165+ let subject = AdaptableObject . create ( ) ;
166+
167+ sandbox . stub ( subject , '_lookupAdapter' ) . callsFake ( function ( ) {
168+ return Starship ; // Return a non-instantiated adapter.
169+ } ) ;
173170
174- const stub = sandbox . stub ( get ( subject , '_adapters.Enterprise' ) , '_makeItSo' ) ;
175- const spy = sandbox . spy ( get ( subject , '_adapters.Enterprise' ) , 'warp' ) ;
171+ subject . activateAdapters ( adapters . starships ) ;
176172
177- set ( subject , 'context.warpCapabilities' , true ) ;
178- subject . invoke ( 'warp' , 'Enterprise' , { factor : 8 , callOne : true } ) ;
179- subject . invoke ( 'warp' , 'Enterprise' , { factor : 8 , callTwo : true } ) ;
173+ const stub = sandbox . stub ( get ( subject , '_adapters.Enterprise' ) , '_makeItSo' ) ;
174+ const spy = sandbox . spy ( get ( subject , '_adapters.Enterprise' ) , 'warp' ) ;
180175
181- assert . ok ( spy . called ) ;
182- assert . ok ( spy . calledWith ( { warpCapabilities : true , factor : 8 , callTwo : true } ) ) ;
183- assert . ok ( stub . called ) ;
176+ set ( subject , 'context.warpCapabilities' , true ) ;
177+ subject . invoke ( 'warp' , 'Enterprise' , { factor : 8 , callOne : true } ) ;
178+ subject . invoke ( 'warp' , 'Enterprise' , { factor : 8 , callTwo : true } ) ;
179+
180+ assert . ok ( spy . called ) ;
181+ assert . ok ( spy . calledWith ( { warpCapabilities : true , factor : 8 , callTwo : true } ) ) ;
182+ assert . ok ( stub . called ) ;
183+ } ) ;
184184} ) ;
0 commit comments