Completed
Push — GildedRose/js ( a01e2a )
by
unknown
05:41 queued 03:38
created

lib/jasmine-1.1.0/jasmine-html.js   B

Complexity

Total Complexity 43
Complexity/F 3.58

Size

Lines of Code 190
Function Count 12

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 384
dl 0
loc 190
rs 8.3157
wmc 43
mnd 4
bc 40
fnc 12
bpm 3.3333
cpm 3.5833
noi 15

9 Functions

Rating   Name   Duplication   Size   Complexity  
B jasmine.TrivialReporter.reportRunnerResults 0 19 6
A jasmine.TrivialReporter.reportRunnerStarting 0 58 3
D jasmine.TrivialReporter.reportSpecResults 0 37 10
A jasmine.TrivialReporter.log 0 10 4
A jasmine.TrivialReporter.reportSpecStarting 0 5 2
A jasmine.TrivialReporter.getLocation 0 3 1
B jasmine.TrivialReporter.createDom 0 23 6
A jasmine.TrivialReporter.specFilter 0 13 3
A jasmine.TrivialReporter.reportSuiteResults 0 8 3

How to fix   Complexity   

Complexity

Complex classes like lib/jasmine-1.1.0/jasmine-html.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
jasmine.TrivialReporter = function(doc) {
0 ignored issues
show
Bug introduced by
The variable jasmine seems to be never declared. If this is a global, consider adding a /** global: jasmine */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2
  this.document = doc || document;
3
  this.suiteDivs = {};
4
  this.logRunningSpecs = false;
5
};
6
7
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
0 ignored issues
show
Bug introduced by
The variable jasmine seems to be never declared. If this is a global, consider adding a /** global: jasmine */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Unused Code introduced by
The parameter childrenVarArgs is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
8
  var el = document.createElement(type);
9
10
  for (var i = 2; i < arguments.length; i++) {
11
    var child = arguments[i];
12
13
    if (typeof child === 'string') {
14
      el.appendChild(document.createTextNode(child));
15
    } else {
16
      if (child) { el.appendChild(child); }
17
    }
18
  }
19
20
  for (var attr in attrs) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
21
    if (attr == "className") {
22
      el[attr] = attrs[attr];
23
    } else {
24
      el.setAttribute(attr, attrs[attr]);
25
    }
26
  }
27
28
  return el;
29
};
30
31
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
0 ignored issues
show
Bug introduced by
The variable jasmine seems to be never declared. If this is a global, consider adding a /** global: jasmine */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
32
  var showPassed, showSkipped;
33
34
  this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
35
      this.createDom('div', { className: 'banner' },
36
        this.createDom('div', { className: 'logo' },
37
            this.createDom('span', { className: 'title' }, "Jasmine"),
38
            this.createDom('span', { className: 'version' }, runner.env.versionString())),
39
        this.createDom('div', { className: 'options' },
40
            "Show ",
41
            showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
42
            this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
43
            showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
44
            this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
45
            )
46
          ),
47
48
      this.runnerDiv = this.createDom('div', { className: 'runner running' },
49
          this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
50
          this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
51
          this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
52
      );
53
54
  this.document.body.appendChild(this.outerDiv);
55
56
  var suites = runner.suites();
57
  for (var i = 0; i < suites.length; i++) {
58
    var suite = suites[i];
59
    var suiteDiv = this.createDom('div', { className: 'suite' },
60
        this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
61
        this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
62
    this.suiteDivs[suite.id] = suiteDiv;
63
    var parentDiv = this.outerDiv;
64
    if (suite.parentSuite) {
65
      parentDiv = this.suiteDivs[suite.parentSuite.id];
66
    }
67
    parentDiv.appendChild(suiteDiv);
68
  }
69
70
  this.startedAt = new Date();
71
72
  var self = this;
73
  showPassed.onclick = function(evt) {
0 ignored issues
show
Unused Code introduced by
The parameter evt is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
74
    if (showPassed.checked) {
75
      self.outerDiv.className += ' show-passed';
76
    } else {
77
      self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
78
    }
79
  };
80
81
  showSkipped.onclick = function(evt) {
0 ignored issues
show
Unused Code introduced by
The parameter evt is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
82
    if (showSkipped.checked) {
83
      self.outerDiv.className += ' show-skipped';
84
    } else {
85
      self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
86
    }
87
  };
88
};
89
90
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
0 ignored issues
show
Bug introduced by
The variable jasmine seems to be never declared. If this is a global, consider adding a /** global: jasmine */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
91
  var results = runner.results();
92
  var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
93
  this.runnerDiv.setAttribute("class", className);
94
  //do it twice for IE
95
  this.runnerDiv.setAttribute("className", className);
96
  var specs = runner.specs();
97
  var specCount = 0;
98
  for (var i = 0; i < specs.length; i++) {
99
    if (this.specFilter(specs[i])) {
100
      specCount++;
101
    }
102
  }
103
  var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
104
  message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
105
  this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
106
107
  this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
108
};
109
110
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
0 ignored issues
show
Bug introduced by
The variable jasmine seems to be never declared. If this is a global, consider adding a /** global: jasmine */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
111
  var results = suite.results();
112
  var status = results.passed() ? 'passed' : 'failed';
113
  if (results.totalCount === 0) { // todo: change this to check results.skipped
114
    status = 'skipped';
115
  }
116
  this.suiteDivs[suite.id].className += " " + status;
117
};
118
119
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
0 ignored issues
show
Bug introduced by
The variable jasmine seems to be never declared. If this is a global, consider adding a /** global: jasmine */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
120
  if (this.logRunningSpecs) {
121
    this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
122
  }
123
};
124
125
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
0 ignored issues
show
Bug introduced by
The variable jasmine seems to be never declared. If this is a global, consider adding a /** global: jasmine */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
126
  var results = spec.results();
127
  var status = results.passed() ? 'passed' : 'failed';
128
  if (results.skipped) {
129
    status = 'skipped';
130
  }
131
  var specDiv = this.createDom('div', { className: 'spec '  + status },
132
      this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
133
      this.createDom('a', {
134
        className: 'description',
135
        href: '?spec=' + encodeURIComponent(spec.getFullName()),
136
        title: spec.getFullName()
137
      }, spec.description));
138
139
140
  var resultItems = results.getItems();
141
  var messagesDiv = this.createDom('div', { className: 'messages' });
142
  for (var i = 0; i < resultItems.length; i++) {
143
    var result = resultItems[i];
144
145
    if (result.type == 'log') {
146
      messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
147
    } else if (result.type == 'expect' && result.passed && !result.passed()) {
148
      messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
149
150
      if (result.trace.stack) {
151
        messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
152
      }
153
    }
154
  }
155
156
  if (messagesDiv.childNodes.length > 0) {
157
    specDiv.appendChild(messagesDiv);
158
  }
159
160
  this.suiteDivs[spec.suite.id].appendChild(specDiv);
161
};
162
163
jasmine.TrivialReporter.prototype.log = function() {
0 ignored issues
show
Bug introduced by
The variable jasmine seems to be never declared. If this is a global, consider adding a /** global: jasmine */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
164
  var console = jasmine.getGlobal().console;
0 ignored issues
show
Bug introduced by
The variable jasmine seems to be never declared. If this is a global, consider adding a /** global: jasmine */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
165
  if (console && console.log) {
166
    if (console.log.apply) {
167
      console.log.apply(console, arguments);
168
    } else {
169
      console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
170
    }
171
  }
172
};
173
174
jasmine.TrivialReporter.prototype.getLocation = function() {
175
  return this.document.location;
176
};
177
178
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
0 ignored issues
show
Bug introduced by
The variable jasmine seems to be never declared. If this is a global, consider adding a /** global: jasmine */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
179
  var paramMap = {};
180
  var params = this.getLocation().search.substring(1).split('&');
181
  for (var i = 0; i < params.length; i++) {
182
    var p = params[i].split('=');
183
    paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
184
  }
185
186
  if (!paramMap.spec) {
187
    return true;
188
  }
189
  return spec.getFullName().indexOf(paramMap.spec) === 0;
190
};
191