PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/javascripts/helpers/jasmine_additions.js

https://github.com/heimidal/midas
JavaScript | 117 lines | 71 code | 18 blank | 28 comment | 16 complexity | 3103d00fa21e85e6145d10222aa7efc9 MD5 | raw file
  1. /**
  2. * Logs the given string to the current logger.
  3. *
  4. * @param {String} string to log
  5. * @static
  6. */
  7. jasmine.log = function(string) {
  8. var env = jasmine.getEnv();
  9. env.reporter.log(string);
  10. };
  11. /**
  12. * Loads a given fixture file into the jasmine_content div.
  13. *
  14. * @param {String} filename of the fixture you want to load (minus the .html)
  15. * @static
  16. */
  17. jasmine.loadFixture = function(filename) {
  18. if (!jasmine.fixtures[filename]) throw('Unable to load that fixture.');
  19. document.getElementById('jasmine_content').innerHTML = jasmine.fixtures[filename];
  20. // might want to eval the string here as well
  21. };
  22. /**
  23. * Loads a given css fixture file into the document.
  24. *
  25. * @param {String} filename of the css you want to load (minus the .css)
  26. * @static
  27. */
  28. jasmine.loadCSS = function(filename) {
  29. if (!jasmine.css[filename]) throw('Unable to load that css.');
  30. if (document.getElementById('css_' + filename)) return;
  31. var style_node = document.createElement('div');
  32. style_node.setAttribute('id', 'css_' + filename);
  33. style_node.innerHTML = '<style>' + jasmine.css[filename] + '</style>';
  34. document.body.appendChild(style_node);
  35. };
  36. /**
  37. * Unloads a given css fixture file from the document.
  38. *
  39. * @param {String} filename of the css you want to load (minus the .css)
  40. * @static
  41. */
  42. jasmine.unloadCSS = function(filename) {
  43. var element = document.getElementById('css_' + filename);
  44. if (!element) throw('That css cannot be unloaded -- not yet loaded');
  45. document.body.removeChild(element);
  46. };
  47. /**
  48. * Pending functionality
  49. *------------------------------------------------------------------------------*/
  50. jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
  51. var results = spec.results();
  52. var status = results.passed() ? 'passed' : 'failed';
  53. var style = '';
  54. if (results.skipped) {
  55. status = 'skipped';
  56. }
  57. if (results.failedCount == 0 && results.passedCount == 0 && !results.skipped) {
  58. status = 'pending';
  59. style = "background-color: #FFA200; border: 1px solid #000000";
  60. }
  61. var specDiv = this.createDom('div', { className: 'spec ' + status, style: style },
  62. this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
  63. this.createDom('a', {
  64. className: 'description',
  65. href: '?spec=' + encodeURIComponent(spec.getFullName()),
  66. title: spec.getFullName()
  67. }, spec.description));
  68. var resultItems = results.getItems();
  69. var messagesDiv = this.createDom('div', { className: 'messages' });
  70. for (var i = 0; i < resultItems.length; i++) {
  71. var result = resultItems[i];
  72. if (result.passed && !result.passed()) {
  73. messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
  74. if (result.trace.stack) {
  75. messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
  76. }
  77. }
  78. }
  79. if (messagesDiv.childNodes.length > 0) {
  80. specDiv.appendChild(messagesDiv);
  81. }
  82. this.suiteDivs[spec.suite.getFullName()].appendChild(specDiv);
  83. };
  84. var pending = function(desc, func) {
  85. return jasmine.getEnv().pending(desc, func);
  86. };
  87. jasmine.Env.prototype.pending = function(description, func) {
  88. var spec = new jasmine.Spec(this, this.currentSuite, description);
  89. this.currentSuite.add(spec);
  90. this.currentSpec = spec;
  91. if (func) {
  92. spec.pending(func);
  93. }
  94. return spec;
  95. };
  96. jasmine.Spec.prototype.pending = function (e) {
  97. var expectationResult = new jasmine.MessageResult('pending');
  98. this.results_.addResult(expectationResult);
  99. };