jasminerice 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jasminerice (0.0.9)
4
+ jasminerice (0.0.10)
5
5
  coffee-rails
6
6
  haml
7
7
 
data/README.md CHANGED
@@ -25,7 +25,16 @@ end
25
25
 
26
26
  The engine is automatically mounted into your application in the development
27
27
  and test environments. If you'd like to change that behavior, you can
28
- override the array `Jasminerice.environments` in an initializer.
28
+ change which groups the gem is included in via the gemfile.
29
+
30
+ Optionally, you can run the installer
31
+
32
+ ```bash
33
+ rails g jasminerice::install
34
+ ```
35
+
36
+ This will add the required `spec.js.coffee` together with a sample spec and
37
+ fixture to help get you started.
29
38
 
30
39
  Usage
31
40
  -----
@@ -36,6 +45,11 @@ Create a file `spec/javascripts/spec.js.coffee` with the following content:
36
45
 
37
46
  #=require_tree ./
38
47
 
48
+ In the case where you need access to all your application javascript assets then create the file `spec/javascripts/spec.js.coffee` with the following contents:
49
+
50
+ #=require_tree ./
51
+ #=require_tree ../../app/assets/javascripts
52
+
39
53
  This pulls in all your specs from the `javascripts` directory into Jasmine:
40
54
 
41
55
  ```bash
@@ -1,6 +1,6 @@
1
1
  #=require jasmine
2
2
  #=require jasmine-html
3
- #=require jasmine-jquery-1.3.1
3
+ #=require jasmine-jquery-1.4.2
4
4
 
5
5
  (->
6
6
  execJasmine = ->
@@ -9,17 +9,19 @@
9
9
  jasmineEnv.updateInterval = 1000
10
10
 
11
11
  window.jsApiReporter = new jasmine.JsApiReporter()
12
- trivialReporter = new jasmine.TrivialReporter()
12
+ htmlReporter = new jasmine.HtmlReporter()
13
13
 
14
- jasmineEnv.addReporter trivialReporter
14
+ jasmineEnv.addReporter htmlReporter
15
15
  jasmineEnv.addReporter jsApiReporter
16
16
 
17
17
  jasmineEnv.specFilter = (spec) ->
18
- trivialReporter.specFilter spec
18
+ htmlReporter.specFilter spec
19
+
20
+ jasmine.getFixtures().fixturesPath = 'jasmine/fixtures'
19
21
 
20
22
  jasmine.rice = {}
21
23
  jasmine.rice.autoExecute = true
22
-
24
+
23
25
  currentWindowOnload = window.onload
24
26
  window.onload = ->
25
27
  currentWindowOnload() if currentWindowOnload
@@ -8,6 +8,7 @@ module Jasminerice
8
8
  layout false
9
9
 
10
10
  def index
11
+ @specenv = params[:environment].try(:concat, "_spec") || "spec"
11
12
  end
12
13
 
13
14
  def fixtures
@@ -4,6 +4,6 @@
4
4
  = stylesheet_link_tag "jasmine"
5
5
  = stylesheet_link_tag "spec"
6
6
  = javascript_include_tag "jasminerice"
7
- = javascript_include_tag "spec"
7
+ = javascript_include_tag @specenv
8
8
  = csrf_meta_tags
9
9
  %body
@@ -7,6 +7,8 @@ Jasminerice::Engine.routes.draw do
7
7
  root :to => "spec#index"
8
8
  end
9
9
 
10
- Rails.application.routes.draw do
11
- mount Jasminerice::Engine => "/jasmine"
10
+ if Jasminerice.mount
11
+ Rails.application.routes.draw do
12
+ mount Jasminerice::Engine => "/jasmine"
13
+ end
12
14
  end
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.description = "Full support for the Rails 3.1 asset pipeline when bdd'ing your coffeescript or javascript using jasmine"
7
7
  s.files = `git ls-files`.split "\n"
8
8
  s.authors = ["Brad Phelan"]
9
- s.version = "0.0.9"
9
+ s.version = "0.0.10"
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.add_dependency( 'haml' )
12
12
  s.add_dependency( 'coffee-rails' )
@@ -0,0 +1,15 @@
1
+ require 'rails'
2
+ if ::Rails.version >= "3.1"
3
+ module Jasminerice::Generators
4
+ class InstallGenerator < ::Rails::Generators::Base
5
+ source_root File.expand_path("../templates", __FILE__)
6
+
7
+ def copy_files
8
+ copy_file "spec.js.coffee", "spec/javascripts/spec.js.coffee"
9
+ copy_file 'foo_spec.js.coffee', 'spec/javascripts/foo_spec.js.coffee'
10
+ copy_file 'spec.css', 'spec/javascripts/spec.css'
11
+ copy_file 'baz.html.haml', 'spec/javascripts/fixtures/baz.html.haml'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ %h2 Test Fixture
2
+ %p Using fixtures
@@ -0,0 +1,14 @@
1
+ # use require to load any .js file available to the asset pipeline
2
+ #= require foo
3
+ #= require bar
4
+
5
+ describe "Foo", ->
6
+ loadFixtures 'baz' # located at 'spec/javascripts/fixtures/baz.html.haml'
7
+ it "it is not bar", ->
8
+ v = new Foo()
9
+ expect(v.bar()).toEqual(false)
10
+
11
+ describe "Bar", ->
12
+ it "it is not foo", ->
13
+ v = new Bar()
14
+ expect(v.foo()).toEqual(false)
@@ -0,0 +1,4 @@
1
+ /*
2
+ Use Sprockets directives to include the right css files e.g.:
3
+ *= require application
4
+ */
@@ -0,0 +1,8 @@
1
+ # This pulls in all your specs from the javascripts directory into Jasmine:
2
+ #
3
+ # spec/javascripts/*_spec.js.coffee
4
+ # spec/javascripts/*_spec.js
5
+ # spec/javascripts/*_spec.js.erb
6
+ # IT IS UNLIKELY THAT YOU WILL NEED TO CHANGE THIS FILE
7
+ #
8
+ #=require_tree ./
@@ -2,4 +2,6 @@ require "jasminerice/engine"
2
2
  require 'haml'
3
3
 
4
4
  module Jasminerice
5
+ mattr_accessor :mount
6
+ self.mount = true
5
7
  end
@@ -1,3 +1,429 @@
1
+ jasmine.HtmlReporterHelpers = {};
2
+
3
+ jasmine.HtmlReporterHelpers.createDom = function(type, attrs, childrenVarArgs) {
4
+ var el = document.createElement(type);
5
+
6
+ for (var i = 2; i < arguments.length; i++) {
7
+ var child = arguments[i];
8
+
9
+ if (typeof child === 'string') {
10
+ el.appendChild(document.createTextNode(child));
11
+ } else {
12
+ if (child) {
13
+ el.appendChild(child);
14
+ }
15
+ }
16
+ }
17
+
18
+ for (var attr in attrs) {
19
+ if (attr == "className") {
20
+ el[attr] = attrs[attr];
21
+ } else {
22
+ el.setAttribute(attr, attrs[attr]);
23
+ }
24
+ }
25
+
26
+ return el;
27
+ };
28
+
29
+ jasmine.HtmlReporterHelpers.getSpecStatus = function(child) {
30
+ var results = child.results();
31
+ var status = results.passed() ? 'passed' : 'failed';
32
+ if (results.skipped) {
33
+ status = 'skipped';
34
+ }
35
+
36
+ return status;
37
+ };
38
+
39
+ jasmine.HtmlReporterHelpers.appendToSummary = function(child, childElement) {
40
+ var parentDiv = this.dom.summary;
41
+ var parentSuite = (typeof child.parentSuite == 'undefined') ? 'suite' : 'parentSuite';
42
+ var parent = child[parentSuite];
43
+
44
+ if (parent) {
45
+ if (typeof this.views.suites[parent.id] == 'undefined') {
46
+ this.views.suites[parent.id] = new jasmine.HtmlReporter.SuiteView(parent, this.dom, this.views);
47
+ }
48
+ parentDiv = this.views.suites[parent.id].element;
49
+ }
50
+
51
+ parentDiv.appendChild(childElement);
52
+ };
53
+
54
+
55
+ jasmine.HtmlReporterHelpers.addHelpers = function(ctor) {
56
+ for(var fn in jasmine.HtmlReporterHelpers) {
57
+ ctor.prototype[fn] = jasmine.HtmlReporterHelpers[fn];
58
+ }
59
+ };
60
+
61
+ jasmine.HtmlReporter = function(_doc) {
62
+ var self = this;
63
+ var doc = _doc || window.document;
64
+
65
+ var reporterView;
66
+
67
+ var dom = {};
68
+
69
+ // Jasmine Reporter Public Interface
70
+ self.logRunningSpecs = false;
71
+
72
+ self.reportRunnerStarting = function(runner) {
73
+ var specs = runner.specs() || [];
74
+
75
+ if (specs.length == 0) {
76
+ return;
77
+ }
78
+
79
+ createReporterDom(runner.env.versionString());
80
+ doc.body.appendChild(dom.reporter);
81
+
82
+ reporterView = new jasmine.HtmlReporter.ReporterView(dom);
83
+ reporterView.addSpecs(specs, self.specFilter);
84
+ };
85
+
86
+ self.reportRunnerResults = function(runner) {
87
+ reporterView && reporterView.complete();
88
+ };
89
+
90
+ self.reportSuiteResults = function(suite) {
91
+ reporterView.suiteComplete(suite);
92
+ };
93
+
94
+ self.reportSpecStarting = function(spec) {
95
+ if (self.logRunningSpecs) {
96
+ self.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
97
+ }
98
+ };
99
+
100
+ self.reportSpecResults = function(spec) {
101
+ reporterView.specComplete(spec);
102
+ };
103
+
104
+ self.log = function() {
105
+ var console = jasmine.getGlobal().console;
106
+ if (console && console.log) {
107
+ if (console.log.apply) {
108
+ console.log.apply(console, arguments);
109
+ } else {
110
+ console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
111
+ }
112
+ }
113
+ };
114
+
115
+ self.specFilter = function(spec) {
116
+ if (!focusedSpecName()) {
117
+ return true;
118
+ }
119
+
120
+ return spec.getFullName().indexOf(focusedSpecName()) === 0;
121
+ };
122
+
123
+ return self;
124
+
125
+ function focusedSpecName() {
126
+ var specName;
127
+
128
+ (function memoizeFocusedSpec() {
129
+ if (specName) {
130
+ return;
131
+ }
132
+
133
+ var paramMap = [];
134
+ var params = doc.location.search.substring(1).split('&');
135
+
136
+ for (var i = 0; i < params.length; i++) {
137
+ var p = params[i].split('=');
138
+ paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
139
+ }
140
+
141
+ specName = paramMap.spec;
142
+ })();
143
+
144
+ return specName;
145
+ }
146
+
147
+ function createReporterDom(version) {
148
+ dom.reporter = self.createDom('div', { id: 'HTMLReporter', className: 'jasmine_reporter' },
149
+ dom.banner = self.createDom('div', { className: 'banner' },
150
+ self.createDom('span', { className: 'title' }, "Jasmine "),
151
+ self.createDom('span', { className: 'version' }, version)),
152
+
153
+ dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}),
154
+ dom.alert = self.createDom('div', {className: 'alert'}),
155
+ dom.results = self.createDom('div', {className: 'results'},
156
+ dom.summary = self.createDom('div', { className: 'summary' }),
157
+ dom.details = self.createDom('div', { id: 'details' }))
158
+ );
159
+ }
160
+ };
161
+ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);jasmine.HtmlReporter.ReporterView = function(dom) {
162
+ this.startedAt = new Date();
163
+ this.runningSpecCount = 0;
164
+ this.completeSpecCount = 0;
165
+ this.passedCount = 0;
166
+ this.failedCount = 0;
167
+ this.skippedCount = 0;
168
+
169
+ this.createResultsMenu = function() {
170
+ this.resultsMenu = this.createDom('span', {className: 'resultsMenu bar'},
171
+ this.summaryMenuItem = this.createDom('a', {className: 'summaryMenuItem', href: "#"}, '0 specs'),
172
+ ' | ',
173
+ this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing'));
174
+
175
+ this.summaryMenuItem.onclick = function() {
176
+ dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '');
177
+ };
178
+
179
+ this.detailsMenuItem.onclick = function() {
180
+ showDetails();
181
+ };
182
+ };
183
+
184
+ this.addSpecs = function(specs, specFilter) {
185
+ this.totalSpecCount = specs.length;
186
+
187
+ this.views = {
188
+ specs: {},
189
+ suites: {}
190
+ };
191
+
192
+ for (var i = 0; i < specs.length; i++) {
193
+ var spec = specs[i];
194
+ this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom, this.views);
195
+ if (specFilter(spec)) {
196
+ this.runningSpecCount++;
197
+ }
198
+ }
199
+ };
200
+
201
+ this.specComplete = function(spec) {
202
+ this.completeSpecCount++;
203
+
204
+ if (isUndefined(this.views.specs[spec.id])) {
205
+ this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom);
206
+ }
207
+
208
+ var specView = this.views.specs[spec.id];
209
+
210
+ switch (specView.status()) {
211
+ case 'passed':
212
+ this.passedCount++;
213
+ break;
214
+
215
+ case 'failed':
216
+ this.failedCount++;
217
+ break;
218
+
219
+ case 'skipped':
220
+ this.skippedCount++;
221
+ break;
222
+ }
223
+
224
+ specView.refresh();
225
+ this.refresh();
226
+ };
227
+
228
+ this.suiteComplete = function(suite) {
229
+ var suiteView = this.views.suites[suite.id];
230
+ if (isUndefined(suiteView)) {
231
+ return;
232
+ }
233
+ suiteView.refresh();
234
+ };
235
+
236
+ this.refresh = function() {
237
+
238
+ if (isUndefined(this.resultsMenu)) {
239
+ this.createResultsMenu();
240
+ }
241
+
242
+ // currently running UI
243
+ if (isUndefined(this.runningAlert)) {
244
+ this.runningAlert = this.createDom('a', {href: "?", className: "runningAlert bar"});
245
+ dom.alert.appendChild(this.runningAlert);
246
+ }
247
+ this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount);
248
+
249
+ // skipped specs UI
250
+ if (isUndefined(this.skippedAlert)) {
251
+ this.skippedAlert = this.createDom('a', {href: "?", className: "skippedAlert bar"});
252
+ }
253
+
254
+ this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
255
+
256
+ if (this.skippedCount === 1 && isDefined(dom.alert)) {
257
+ dom.alert.appendChild(this.skippedAlert);
258
+ }
259
+
260
+ // passing specs UI
261
+ if (isUndefined(this.passedAlert)) {
262
+ this.passedAlert = this.createDom('span', {href: "?", className: "passingAlert bar"});
263
+ }
264
+ this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount);
265
+
266
+ // failing specs UI
267
+ if (isUndefined(this.failedAlert)) {
268
+ this.failedAlert = this.createDom('span', {href: "?", className: "failingAlert bar"});
269
+ }
270
+ this.failedAlert.innerHTML = "Failing " + specPluralizedFor(this.failedCount);
271
+
272
+ if (this.failedCount === 1 && isDefined(dom.alert)) {
273
+ dom.alert.appendChild(this.failedAlert);
274
+ dom.alert.appendChild(this.resultsMenu);
275
+ }
276
+
277
+ // summary info
278
+ this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount);
279
+ this.detailsMenuItem.innerHTML = "" + this.failedCount + " failing";
280
+ };
281
+
282
+ this.complete = function() {
283
+ dom.alert.removeChild(this.runningAlert);
284
+
285
+ this.skippedAlert.innerHTML = "Ran " + this.runningSpecCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
286
+
287
+ if (this.failedCount === 0) {
288
+ dom.alert.appendChild(this.createDom('span', {className: 'passingAlert bar'}, "Passing " + specPluralizedFor(this.passedCount)));
289
+ } else {
290
+ showDetails();
291
+ }
292
+
293
+ dom.banner.appendChild(this.createDom('span', {className: 'duration'}, "finished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"));
294
+ };
295
+
296
+ return this;
297
+
298
+ function showDetails() {
299
+ if (dom.reporter.className.search(/showDetails/) === -1) {
300
+ dom.reporter.className += " showDetails";
301
+ }
302
+ }
303
+
304
+ function isUndefined(obj) {
305
+ return typeof obj === 'undefined';
306
+ }
307
+
308
+ function isDefined(obj) {
309
+ return !isUndefined(obj);
310
+ }
311
+
312
+ function specPluralizedFor(count) {
313
+ var str = count + " spec";
314
+ if (count > 1) {
315
+ str += "s"
316
+ }
317
+ return str;
318
+ }
319
+
320
+ };
321
+
322
+ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.ReporterView);
323
+
324
+
325
+ jasmine.HtmlReporter.SpecView = function(spec, dom, views) {
326
+ this.spec = spec;
327
+ this.dom = dom;
328
+ this.views = views;
329
+
330
+ this.symbol = this.createDom('li', { className: 'pending' });
331
+ this.dom.symbolSummary.appendChild(this.symbol);
332
+
333
+ this.summary = this.createDom('div', { className: 'specSummary' },
334
+ this.createDom('a', {
335
+ className: 'description',
336
+ href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
337
+ title: this.spec.getFullName()
338
+ }, this.spec.description)
339
+ );
340
+
341
+ this.detail = this.createDom('div', { className: 'specDetail' },
342
+ this.createDom('a', {
343
+ className: 'description',
344
+ href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
345
+ title: this.spec.getFullName()
346
+ }, this.spec.getFullName())
347
+ );
348
+ };
349
+
350
+ jasmine.HtmlReporter.SpecView.prototype.status = function() {
351
+ return this.getSpecStatus(this.spec);
352
+ };
353
+
354
+ jasmine.HtmlReporter.SpecView.prototype.refresh = function() {
355
+ this.symbol.className = this.status();
356
+
357
+ switch (this.status()) {
358
+ case 'skipped':
359
+ break;
360
+
361
+ case 'passed':
362
+ this.appendSummaryToSuiteDiv();
363
+ break;
364
+
365
+ case 'failed':
366
+ this.appendSummaryToSuiteDiv();
367
+ this.appendFailureDetail();
368
+ break;
369
+ }
370
+ };
371
+
372
+ jasmine.HtmlReporter.SpecView.prototype.appendSummaryToSuiteDiv = function() {
373
+ this.summary.className += ' ' + this.status();
374
+ this.appendToSummary(this.spec, this.summary);
375
+ };
376
+
377
+ jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() {
378
+ this.detail.className += ' ' + this.status();
379
+
380
+ var resultItems = this.spec.results().getItems();
381
+ var messagesDiv = this.createDom('div', { className: 'messages' });
382
+
383
+ for (var i = 0; i < resultItems.length; i++) {
384
+ var result = resultItems[i];
385
+
386
+ if (result.type == 'log') {
387
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
388
+ } else if (result.type == 'expect' && result.passed && !result.passed()) {
389
+ messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
390
+
391
+ if (result.trace.stack) {
392
+ messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
393
+ }
394
+ }
395
+ }
396
+
397
+ if (messagesDiv.childNodes.length > 0) {
398
+ this.detail.appendChild(messagesDiv);
399
+ this.dom.details.appendChild(this.detail);
400
+ }
401
+ };
402
+
403
+ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.HtmlReporter.SuiteView = function(suite, dom, views) {
404
+ this.suite = suite;
405
+ this.dom = dom;
406
+ this.views = views;
407
+
408
+ this.element = this.createDom('div', { className: 'suite' },
409
+ this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(this.suite.getFullName()) }, this.suite.description)
410
+ );
411
+
412
+ this.appendToSummary(this.suite, this.element);
413
+ };
414
+
415
+ jasmine.HtmlReporter.SuiteView.prototype.status = function() {
416
+ return this.getSpecStatus(this.suite);
417
+ };
418
+
419
+ jasmine.HtmlReporter.SuiteView.prototype.refresh = function() {
420
+ this.element.className += " " + this.status();
421
+ };
422
+
423
+ jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SuiteView);
424
+
425
+ /* @deprecated Use jasmine.HtmlReporter instead
426
+ */
1
427
  jasmine.TrivialReporter = function(doc) {
2
428
  this.document = doc || document;
3
429
  this.suiteDivs = {};
@@ -31,7 +457,7 @@ jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarA
31
457
  jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
32
458
  var showPassed, showSkipped;
33
459
 
34
- this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
460
+ this.outerDiv = this.createDom('div', { id: 'TrivialReporter', className: 'jasmine_reporter' },
35
461
  this.createDom('div', { className: 'banner' },
36
462
  this.createDom('div', { className: 'logo' },
37
463
  this.createDom('span', { className: 'title' }, "Jasmine"),
@@ -188,3 +614,4 @@ jasmine.TrivialReporter.prototype.specFilter = function(spec) {
188
614
  }
189
615
  return spec.getFullName().indexOf(paramMap.spec) === 0;
190
616
  };
617
+