magic_lamp 0.9.9 → 1.0.0

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.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +286 -59
  3. data/app/assets/javascripts/magic_lamp/genie.js +32 -7
  4. data/app/assets/javascripts/magic_lamp/magic_lamp.js +4 -0
  5. data/app/controllers/magic_lamp/fixtures_controller.rb +2 -2
  6. data/lib/magic_lamp.rb +59 -14
  7. data/lib/magic_lamp/callbacks.rb +24 -0
  8. data/lib/magic_lamp/configuration.rb +26 -0
  9. data/lib/magic_lamp/fixture_creator.rb +6 -5
  10. data/lib/magic_lamp/render_catcher.rb +17 -10
  11. data/lib/magic_lamp/version.rb +1 -1
  12. data/lib/tasks/fixture_names_task.rb +7 -0
  13. data/lib/tasks/lint_task.rb +8 -0
  14. data/spec/controllers/magic_lamp/fixtures_controller_spec.rb +2 -2
  15. data/spec/dummy/log/development.log +74880 -0
  16. data/spec/dummy/log/test.log +223258 -0
  17. data/spec/dummy/persisted_specs/magic_lamp.rb +5 -0
  18. data/spec/dummy/persisted_specs/magic_lamp_config.rb +14 -0
  19. data/spec/dummy/spec/magical/a_lamp_file_with_a_different_name_lamp.rb +7 -0
  20. data/spec/dummy/spec/magical/magic_lamp.rb +1 -1
  21. data/spec/dummy/spec/magical/magic_lamp_config.rb +1 -0
  22. data/spec/dummy/tmp/cache/assets/development/sprockets/020414588350dc7f6c910d23b47b2eac +0 -0
  23. data/spec/dummy/tmp/cache/assets/development/sprockets/04a1e26a9e3fde1f448cb2a9d382fbbc +0 -0
  24. data/spec/dummy/tmp/cache/assets/development/sprockets/09bc89d8ac4ccacfcf2f4db466e7735f +0 -0
  25. data/spec/dummy/tmp/cache/assets/development/sprockets/0b3144442052dbb8af7f57ca27cd7a15 +0 -0
  26. data/spec/dummy/tmp/cache/assets/development/sprockets/18650d8ff9b0a83b32e55b58917ec791 +0 -0
  27. data/spec/dummy/tmp/cache/assets/development/sprockets/1b2519cef64d534f944996a2326823f6 +0 -0
  28. data/spec/dummy/tmp/cache/assets/development/sprockets/1e42928536d86174d2365d82a034082b +0 -0
  29. data/spec/dummy/tmp/cache/assets/development/sprockets/292405ba7ff52dbb279572aee49ba174 +0 -0
  30. data/spec/dummy/tmp/cache/assets/development/sprockets/2c66f0d7ef22d32ab110fc31a55fe828 +0 -0
  31. data/spec/dummy/tmp/cache/assets/development/sprockets/2ccef21649a61deac2c84f622753b77b +0 -0
  32. data/spec/dummy/tmp/cache/assets/development/sprockets/32b0c6aea545968d6da4939bcbab9b5e +0 -0
  33. data/spec/dummy/tmp/cache/assets/development/sprockets/32d3add1308f63f1ce5eacde1eba7752 +0 -0
  34. data/spec/dummy/tmp/cache/assets/development/sprockets/3823434d99b44359ee75dffba2817055 +0 -0
  35. data/spec/dummy/tmp/cache/assets/development/sprockets/3a2dd1069a3d0cd57769e33920561e09 +0 -0
  36. data/spec/dummy/tmp/cache/assets/development/sprockets/3c8cdd0e5d5eee39df490048c656a2c5 +0 -0
  37. data/spec/dummy/tmp/cache/assets/development/sprockets/40f78fd7fa893a3ba0bb52949d4d6e21 +0 -0
  38. data/spec/dummy/tmp/cache/assets/development/sprockets/4878804f69b49fa9eb8a9c0af84ba31a +0 -0
  39. data/spec/dummy/tmp/cache/assets/development/sprockets/4af6cefe350f9be6f923a3d72edf1813 +0 -0
  40. data/spec/dummy/tmp/cache/assets/development/sprockets/51333e0ed6511483c511470803d3803a +0 -0
  41. data/spec/dummy/tmp/cache/assets/development/sprockets/5723ed075d2604a5ae91531445b2a613 +0 -0
  42. data/spec/dummy/tmp/cache/assets/development/sprockets/58367e9b5bd6d94235a07214faacf926 +0 -0
  43. data/spec/dummy/tmp/cache/assets/development/sprockets/5b03eeac2e4ecbaaf227c5aa35808fee +0 -0
  44. data/spec/dummy/tmp/cache/assets/development/sprockets/5bbf09297502a156801e9c65f4bd3db7 +0 -0
  45. data/spec/dummy/tmp/cache/assets/development/sprockets/5c9e5cf4ec642fa40af2267ef88f3095 +0 -0
  46. data/spec/dummy/tmp/cache/assets/development/sprockets/5ce07b63a8c04b5207f4ce3e753f5cee +0 -0
  47. data/spec/dummy/tmp/cache/assets/development/sprockets/62b7a364ac8780cbc8d56c1c6434a0a4 +0 -0
  48. data/spec/dummy/tmp/cache/assets/development/sprockets/6f968441247482ba7e1ac7ce9f34dfdb +0 -0
  49. data/spec/dummy/tmp/cache/assets/development/sprockets/759e97d6d411bc4cef7055a778e1bef3 +0 -0
  50. data/spec/dummy/tmp/cache/assets/development/sprockets/7f5b2f45d9f12db1fb26a605759b360a +0 -0
  51. data/spec/dummy/tmp/cache/assets/development/sprockets/7f7dcf7837dbb7f150b7364ad7920712 +0 -0
  52. data/spec/dummy/tmp/cache/assets/development/sprockets/80a68d71946643e61d91cc216f7aa32f +0 -0
  53. data/spec/dummy/tmp/cache/assets/development/sprockets/86023efec2465a88617e5a47a38f1f55 +0 -0
  54. data/spec/dummy/tmp/cache/assets/development/sprockets/87c6d9a5c985ccb321255862fd8c2f48 +0 -0
  55. data/spec/dummy/tmp/cache/assets/development/sprockets/88fe64427f1fff8e41ca8ad0170da88a +0 -0
  56. data/spec/dummy/tmp/cache/assets/development/sprockets/8a0862dca044d19cadb655c53acb20ab +0 -0
  57. data/spec/dummy/tmp/cache/assets/development/sprockets/8c4d5b82ba38d47cebae9c56db8fc883 +0 -0
  58. data/spec/dummy/tmp/cache/assets/development/sprockets/8dc2cb33d4af3c73661b4b84b4a95947 +0 -0
  59. data/spec/dummy/tmp/cache/assets/development/sprockets/8e2a04fd6b5a2e086e5d604cb8224809 +0 -0
  60. data/spec/dummy/tmp/cache/assets/development/sprockets/8ed4b4f20fb65446181984e6df7d7c9b +0 -0
  61. data/spec/dummy/tmp/cache/assets/development/sprockets/8f4a370f455559b7a209ecd758a3bb3d +0 -0
  62. data/spec/dummy/tmp/cache/assets/development/sprockets/96210dc070e479fcee862294afe5efc1 +0 -0
  63. data/spec/dummy/tmp/cache/assets/development/sprockets/972b6b0bb1fc0b1123077b4b2f4394bd +0 -0
  64. data/spec/dummy/tmp/cache/assets/development/sprockets/9825272284630c2926f661645205382a +0 -0
  65. data/spec/dummy/tmp/cache/assets/development/sprockets/9d676cb2f7cb26509cfcd0bce3f08fee +0 -0
  66. data/spec/dummy/tmp/cache/assets/development/sprockets/acbd4771ecb2a173a35382fbff9317cf +0 -0
  67. data/spec/dummy/tmp/cache/assets/development/sprockets/b226a96bfa85a5a853dd6566d1706231 +0 -0
  68. data/spec/dummy/tmp/cache/assets/development/sprockets/b29390c73fea05dd0073f043c17a9986 +0 -0
  69. data/spec/dummy/tmp/cache/assets/development/sprockets/b2a142b210c2cbfe4a58040684b3c33c +0 -0
  70. data/spec/dummy/tmp/cache/assets/development/sprockets/bb57f340ac9df9041014540af079a7f3 +0 -0
  71. data/spec/dummy/tmp/cache/assets/development/sprockets/bfa154e8a12acdbc85028ad8130d9043 +0 -0
  72. data/spec/dummy/tmp/cache/assets/development/sprockets/c84af5f8f55b15818667b16b15416431 +0 -0
  73. data/spec/dummy/tmp/cache/assets/development/sprockets/cf573b52d944e8aea7f1dc03f9be9b2c +0 -0
  74. data/spec/dummy/tmp/cache/assets/development/sprockets/d53d8d895a44b860d5e1399e1a9a7b69 +0 -0
  75. data/spec/dummy/tmp/cache/assets/development/sprockets/d5b28f340e57aab871a83d30b1294b62 +0 -0
  76. data/spec/dummy/tmp/cache/assets/development/sprockets/d98de652252dc6ae11b5b6db5588705b +0 -0
  77. data/spec/dummy/tmp/cache/assets/development/sprockets/e52d001ef73b04129baa586e2822018e +0 -0
  78. data/spec/dummy/tmp/cache/assets/development/sprockets/f0aa53eb377a5d7cc83657ef33b02d25 +0 -0
  79. data/spec/dummy/tmp/cache/assets/development/sprockets/f12e838fbbcc1647156ec47ebbeaac9a +0 -0
  80. data/spec/dummy/tmp/cache/assets/development/sprockets/f3018c23e25ab4b02fc51d6302f79a0a +0 -0
  81. data/spec/dummy/tmp/cache/assets/development/sprockets/f30abc368796858ff89a5ff6daf33e6a +0 -0
  82. data/spec/dummy/tmp/cache/assets/development/sprockets/f5d1b7d2ec1c89dc32cc982b43502dc8 +0 -0
  83. data/spec/dummy/tmp/cache/assets/development/sprockets/f5e8036e8de24870e4db21ccb209e272 +0 -0
  84. data/spec/dummy/tmp/cache/assets/development/sprockets/f6256b2e4e609981d9eb420aae5bef46 +0 -0
  85. data/spec/dummy/tmp/cache/assets/development/sprockets/f62fb3331d14ad448ad997f1fbdb7e23 +0 -0
  86. data/spec/dummy/tmp/cache/assets/development/sprockets/fd203e335fb22b3109d0354b99f45c6e +0 -0
  87. data/spec/dummy/tmp/cache/assets/development/sprockets/fdc3718e0a84d340a897f87179d95c84 +0 -0
  88. data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  89. data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  90. data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  91. data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  92. data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  93. data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  94. data/spec/javascripts/genie_spec.js +97 -28
  95. data/spec/javascripts/magic_lamp_spec.js +50 -17
  96. data/spec/javascripts/spec_helper.js +5 -4
  97. data/spec/javascripts/support/chai-fuzzy.js +110 -0
  98. data/spec/lib/callbacks_spec.rb +58 -0
  99. data/spec/lib/configuration_spec.rb +48 -0
  100. data/spec/lib/fixture_creator_spec.rb +17 -14
  101. data/spec/lib/magic_lamp_spec.rb +97 -26
  102. data/spec/lib/render_catcher_spec.rb +18 -4
  103. data/spec/rails_helper.rb +2 -0
  104. data/spec/spec_helper.rb +5 -0
  105. data/spec/tasks/fixture_names_task_spec.rb +23 -0
  106. data/spec/tasks/lint_task_spec.rb +17 -0
  107. data/spec/teaspoon_env.rb +33 -34
  108. metadata +146 -9
  109. data/lib/tasks/magic_lamp_tasks.rake +0 -4
  110. data/spec/dummy/tmp/pids/server.pid +0 -1
@@ -0,0 +1,5 @@
1
+ # Don't pass name argument here for the sake of the db cleaner spec
2
+ MagicLamp.register_fixture do
3
+ @order = Order.create!
4
+ render partial: "orders/form"
5
+ end
@@ -0,0 +1,14 @@
1
+ require "database_cleaner"
2
+
3
+ MagicLamp.configure do |config|
4
+
5
+ DatabaseCleaner.strategy = :transaction
6
+
7
+ config.before_each do
8
+ DatabaseCleaner.start
9
+ end
10
+
11
+ config.after_each do
12
+ DatabaseCleaner.clean
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ MagicLamp.register_fixture(name: "custom_name") do
2
+ render "orders/foo"
3
+ end
4
+
5
+ MagicLamp.register_fixture(controller: OrdersController, name: "super_specified") do
6
+ render :foo
7
+ end
@@ -2,7 +2,7 @@ MagicLamp.register_fixture do
2
2
  render "orders/foo"
3
3
  end
4
4
 
5
- MagicLamp.register_fixture do
5
+ MagicLamp.register_fixture(controller: OrdersController) do
6
6
  render "orders/bar"
7
7
  end
8
8
 
@@ -0,0 +1 @@
1
+ MagicLamp.registered_fixtures
@@ -28,6 +28,26 @@ describe('Genie', function() {
28
28
  });
29
29
  });
30
30
 
31
+ describe('#fixtureNames', function() {
32
+ beforeEach(function() {
33
+ stub(console, 'log', true);
34
+ subject.cache = { foo: 'template', bar: 'other template' };
35
+ });
36
+
37
+ it('returns all of the fixtures named in the cache', function() {
38
+ expect(subject.fixtureNames()).to.be.like(['bar', 'foo']);
39
+ console.log.restore();
40
+ });
41
+
42
+ it('logs all of the fixture names in the cache', function() {
43
+ subject.fixtureNames();
44
+ expect(console.log).to.have.been.calledWith('bar');
45
+ expect(console.log).to.have.been.calledWith('foo');
46
+ expect(console.log.args).to.be.like([['bar'], ['foo']]);
47
+ console.log.restore();
48
+ });
49
+ });
50
+
31
51
  describe('#load', function() {
32
52
  var path;
33
53
  beforeEach(function() {
@@ -38,6 +58,13 @@ describe('Genie', function() {
38
58
  removeNode(subject.fixtureContainer);
39
59
  });
40
60
 
61
+ it('does not double append fixture containers', function() {
62
+ subject.cache[path] = 'some template';
63
+ subject.cacheOnly = true;
64
+ _(2).times(function() { subject.load(path); });
65
+ expect(document.getElementsByClassName('magic-lamp').length).to.equal(1);
66
+ });
67
+
41
68
  describe('cacheOnly false', function() {
42
69
  it('requests the fixture and adds it to the cache', function() {
43
70
  spyOn(subject, 'xhrRequest');
@@ -47,12 +74,11 @@ describe('Genie', function() {
47
74
  });
48
75
 
49
76
  it('appends the fixture container with the fixture to the dom', function() {
50
- expect(testFixtureContainer()).to.equal(null);
77
+ expect(testFixtureContainer()).to.be.undefined;
51
78
  subject.load(path);
52
79
  expect(testFixtureContainer().innerHTML).to.equal('foo\n');
53
80
  });
54
81
 
55
-
56
82
  describe('cached', function() {
57
83
  beforeEach(function() {
58
84
  subject.cache[path] = 'howdy';
@@ -65,7 +91,7 @@ describe('Genie', function() {
65
91
  });
66
92
 
67
93
  it('appends the fixture container to the dom with the cached fixture', function() {
68
- expect(testFixtureContainer()).to.equal(null);
94
+ expect(testFixtureContainer()).to.be.undefined;
69
95
  subject.load(path);
70
96
  expect(testFixtureContainer().innerHTML).to.equal('howdy');
71
97
  });
@@ -87,7 +113,7 @@ describe('Genie', function() {
87
113
  it('throws an error if the fixture is not in the cache', function() {
88
114
  expect(function() {
89
115
  subject.load(path);
90
- }).to.throw(/The fixture "orders\/foo" was not preloaded. Is the fixture registered\? Such a bummer./);
116
+ }).to.throw(/The fixture "orders\/foo" was not preloaded. Is the fixture registered\? Call `MagicLamp.fixtureNames\(\)` to see what is registered./);
91
117
  });
92
118
  });
93
119
  });
@@ -95,7 +121,7 @@ describe('Genie', function() {
95
121
  describe('#preload', function() {
96
122
  it('requests all of the fixtures and puts them in the cache', function() {
97
123
  subject.preload();
98
- expect(subject.cache).to.have.keys(['orders/foo', 'orders/bar', 'orders/form']);
124
+ expect(subject.cache).to.have.keys(['orders/foo', 'orders/bar', 'orders/form', 'custom_name', 'super_specified']);
99
125
  });
100
126
 
101
127
  it('sets cacheOnly to true', function() {
@@ -103,6 +129,12 @@ describe('Genie', function() {
103
129
  expect(subject.cacheOnly).to.equal(true);
104
130
  });
105
131
 
132
+ it('does not set cacheOnly to true if the request fails', function() {
133
+ subject.xhrRequest = function() { throw new Error(); }
134
+ expect(function() { subject.preload(); }).to.throw();
135
+ expect(subject.cacheOnly).to.equal(false);
136
+ });
137
+
106
138
  it('makes a request to the specified path if defined', function() {
107
139
  var path = MagicLamp.path = '/normal_lamp';
108
140
  stub(subject, 'xhrRequest', { responseText: '{}' });
@@ -115,17 +147,17 @@ describe('Genie', function() {
115
147
  });
116
148
 
117
149
  describe('#createFixtureContainer', function() {
118
- it('creates a div with an id of "magic-lamp" and caches it', function() {
150
+ it('creates a div with a class of "magic-lamp" and caches it', function() {
119
151
  subject.createFixtureContainer();
120
152
  expect(subject.fixtureContainer.tagName).to.equal('DIV');
121
- expect(subject.fixtureContainer.id).to.equal('magic-lamp');
153
+ expect(subject.fixtureContainer.className).to.equal('magic-lamp');
122
154
  });
123
155
 
124
- it('creates a div with an id of MagicLamp.id if present', function() {
125
- var id = MagicLamp.id = 'footastic';
156
+ it('creates a div with a class of MagicLamp.class if present', function() {
157
+ var specifiedClass = MagicLamp.class = 'footastic';
126
158
  subject.createFixtureContainer();
127
- delete MagicLamp.id;
128
- expect(subject.fixtureContainer.id).to.equal(id);
159
+ delete MagicLamp.class;
160
+ expect(subject.fixtureContainer.className).to.equal(specifiedClass);
129
161
  });
130
162
  });
131
163
 
@@ -139,34 +171,57 @@ describe('Genie', function() {
139
171
  });
140
172
 
141
173
  it('appends the fixtureContainer to the body', function() {
142
- expect(testFixtureContainer()).to.equal(null);
174
+ expect(testFixtureContainer()).to.be.undefined;
143
175
  subject.appendFixtureContainer();
144
176
  expect(testFixtureContainer()).to.equal(subject.fixtureContainer);
145
177
  });
146
178
  });
147
179
 
148
180
  describe('#removeFixtureContainer', function() {
149
- beforeEach(function() {
150
- subject.createFixtureContainer();
151
- subject.appendFixtureContainer();
152
- });
153
-
154
181
  afterEach(function() {
155
182
  removeNode(subject.fixtureContainer);
156
183
  });
157
184
 
158
- it('removes the fixture container from the dom', function() {
159
- expect(testFixtureContainer()).to.equal(subject.fixtureContainer);
160
- subject.removeFixtureContainer();
161
- expect(testFixtureContainer()).to.equal(null);
162
- expect(subject.fixtureContainer).to.be.undefined;
185
+ describe('without the fixture container', function() {
186
+ it('logs a message saying that this is a weird thing to do', function() {
187
+ expect(function() {
188
+ _(3).times(function() { subject.removeFixtureContainer(); });
189
+ }).to.not.throw()
190
+ });
163
191
  });
164
192
 
165
- it('removes the fixture container from the genie instance', function() {
166
- expect(testFixtureContainer()).to.equal(subject.fixtureContainer);
167
- subject.removeFixtureContainer();
168
- expect(subject.fixtureContainer).to.be.undefined;
193
+ describe('with the fixture container created', function() {
194
+ beforeEach(function() {
195
+ subject.createFixtureContainer();
196
+ });
197
+
198
+ it('removes the fixture container from the genie instance', function() {
199
+ expect(subject.fixtureContainer).to.be.defined;
200
+ subject.removeFixtureContainer();
201
+ expect(subject.fixtureContainer).to.be.undefined;
202
+ });
203
+ });
204
+
205
+ describe('with the fixture there', function() {
206
+ beforeEach(function() {
207
+ subject.createFixtureContainer();
208
+ subject.appendFixtureContainer();
209
+ });
210
+
211
+ it('removes the fixture container from the dom', function() {
212
+ expect(testFixtureContainer()).to.equal(subject.fixtureContainer);
213
+ subject.removeFixtureContainer();
214
+ expect(testFixtureContainer()).to.be.undefined;
215
+ expect(subject.fixtureContainer).to.be.undefined;
216
+ });
217
+
218
+ it('removes the fixture container from the genie instance', function() {
219
+ expect(testFixtureContainer()).to.equal(subject.fixtureContainer);
220
+ subject.removeFixtureContainer();
221
+ expect(subject.fixtureContainer).to.be.undefined;
222
+ });
169
223
  });
224
+
170
225
  });
171
226
 
172
227
  describe('#handleError', function() {
@@ -190,7 +245,6 @@ describe('Genie', function() {
190
245
 
191
246
  expect(xhrProto.open).to.have.been.calledWith('GET', path, false);
192
247
  expect(xhrProto.send).to.have.been.calledOnce;
193
-
194
248
  });
195
249
 
196
250
  it('returns the xhr object', function() {
@@ -200,11 +254,26 @@ describe('Genie', function() {
200
254
  expect(result.constructor).to.equal(XMLHttpRequest);
201
255
  });
202
256
 
203
- it('calls handleError if the status is not 200', function() {
257
+ it('calls handleError with the response text if the status was 400', function() {
204
258
  stub(subject, 'handleError', true);
205
259
  var path = '/magic_lamp/foo/bar';
206
260
  var xhr = subject.xhrRequest(path);
207
261
  expect(subject.handleError).to.have.been.calledWith(xhr.responseText);
208
262
  });
263
+
264
+ it('calls handleError with the default error message if the status was 500', function() {
265
+ stub(subject, 'handleError', true);
266
+ stub(subject, 'xhrStatus', 500);
267
+ var path = '/magic_lamp/foo/bar';
268
+ var xhr = subject.xhrRequest(path);
269
+ expect(subject.handleError).to.have.been.calledWith('Something went wrong while generating the fixture, please check the server log or run `rake magic_lamp:lint` for more information');
270
+ });
271
+ });
272
+
273
+ describe('#xhrStatus', function() {
274
+ it('returns the status of the xhr', function() {
275
+ var status = 200;
276
+ expect(subject.xhrStatus({ status: status })).to.equal(status);
277
+ });
209
278
  });
210
279
  });
@@ -22,6 +22,26 @@ describe('MagicLamp', function() {
22
22
  });
23
23
  });
24
24
 
25
+ describe('#fixtureNames', function() {
26
+ beforeEach(function() {
27
+ subject.initialize();
28
+ stub(subject.genie, 'fixtureNames', true);
29
+ subject.fixtureNames();
30
+ });
31
+
32
+ afterEach(function() {
33
+ delete subject.genie;
34
+ });
35
+
36
+ it('passes through to its genie instance', function() {
37
+ expect(subject.genie.fixtureNames).to.have.been.calledOnce;
38
+ });
39
+
40
+ it('returns the genie instance\'s return value', function() {
41
+ expect(subject.fixtureNames()).to.equal(true);
42
+ });
43
+ });
44
+
25
45
  describe('#globalize', function() {
26
46
  beforeEach(function() {
27
47
  subject.globalize();
@@ -130,47 +150,50 @@ describe('MagicLamp', function() {
130
150
  });
131
151
 
132
152
  afterEach(function() {
153
+ subject.clean();
133
154
  delete subject.genie;
134
155
  });
135
156
 
136
157
  it('can load the foo template and clean up', function() {
137
- expect(testFixtureContainer()).to.equal(null);
158
+ expect(testFixtureContainer()).to.be.undefined;
138
159
  subject.load('orders/foo');
139
160
  expect(testFixtureContainer().innerHTML).to.equal('foo\n');
140
161
  subject.clean();
141
- expect(testFixtureContainer()).to.equal(null);
162
+ expect(testFixtureContainer()).to.be.undefined;
142
163
  });
143
164
 
144
165
  it('can preload the templates and clean up', function() {
145
166
  subject.preload();
146
- expect(testFixtureContainer()).to.equal(null);
147
- subject.load('orders/foo');
167
+ expect(testFixtureContainer()).to.be.undefined;
168
+ _(2).times(function() { subject.load('orders/foo'); });
169
+ expect(document.getElementsByClassName('magic-lamp').length).to.equal(1);
148
170
  expect(testFixtureContainer().innerHTML).to.equal('foo\n');
149
171
  subject.clean();
150
- expect(testFixtureContainer()).to.equal(null);
172
+ expect(testFixtureContainer()).to.be.undefined;
151
173
  subject.load('orders/bar');
152
174
  expect(testFixtureContainer().innerHTML).to.equal('bar\n');
153
- subject.clean();
154
- expect(testFixtureContainer()).to.equal(null);
175
+ _(3).times(function() { subject.clean(); });
176
+ expect(testFixtureContainer()).to.be.undefined;
155
177
  });
156
178
 
157
- it('can specify the id used for the fixture container', function() {
158
- var newId = subject.id = 'the-eye';
179
+ it('can specify the class used for the fixture container', function() {
180
+ var newClass = subject.class = 'the-eye';
159
181
  subject.load('orders/foo');
160
- expect(testFixtureContainer()).to.equal(null);
161
- expect(document.getElementById(newId)).to.exist;
162
- expect(document.getElementById(newId).innerHTML).to.equal('foo\n');
182
+ expect(testFixtureContainer()).to.be.undefined;
183
+ expect(findByClassName(newClass)).to.exist;
184
+ expect(findByClassName(newClass).innerHTML).to.equal('foo\n');
163
185
  subject.clean();
164
- expect(document.getElementById(newId)).to.not.exist;
165
- delete subject.id;
186
+ expect(findByClassName(newClass)).to.not.exist;
187
+ delete subject.class;
166
188
  });
167
189
 
168
190
  it('throws an error when it cannot find the template', function() {
169
191
  expect(function() {
170
192
  subject.load('not/gonna/happen');
171
193
  }).to.throw(/'not\/gonna\/happen' is not a registered fixture$/);
172
-
173
- expect(testFixtureContainer()).to.equal(null);
194
+ _(3).times(function() { subject.clean(); });
195
+ subject.clean();
196
+ expect(testFixtureContainer()).to.be.undefined;
174
197
  });
175
198
 
176
199
  it('throws an error when it cannot find the preloaded template', function() {
@@ -178,8 +201,18 @@ describe('MagicLamp', function() {
178
201
  expect(function() {
179
202
  subject.load('still/not/gonna/happen');
180
203
  }).to.throw();
204
+ _(3).times(function() { subject.clean(); });
205
+ expect(testFixtureContainer()).to.be.undefined;
206
+ });
207
+
208
+ it('can load fixtures with specified names', function() {
209
+ subject.load('custom_name');
210
+ expect(testFixtureContainer().innerHTML).to.equal('foo\n');
211
+ });
181
212
 
182
- expect(testFixtureContainer()).to.equal(null);
213
+ it('can load fixtures with specified names and controllers', function() {
214
+ subject.load('super_specified')
215
+ expect(testFixtureContainer().innerHTML).to.equal('foo\n');
183
216
  });
184
217
  });
185
218
  });