ASpellTests.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. (function() {
  2. var chai, should, sinon;
  3. sinon = require('sinon');
  4. chai = require('chai');
  5. should = chai.should();
  6. describe("ASpell", function() {
  7. beforeEach(function() {
  8. return this.ASpell = require("../../../app/js/ASpell");
  9. });
  10. describe("a correctly spelled word", function() {
  11. beforeEach(function(done) {
  12. return this.ASpell.checkWords("en", ["word"], (function(_this) {
  13. return function(error, result) {
  14. _this.result = result;
  15. return done();
  16. };
  17. })(this));
  18. });
  19. return it("should not correct the word", function() {
  20. return this.result.length.should.equal(0);
  21. });
  22. });
  23. describe("a misspelled word", function() {
  24. beforeEach(function(done) {
  25. return this.ASpell.checkWords("en", ["bussines"], (function(_this) {
  26. return function(error, result) {
  27. _this.result = result;
  28. return done();
  29. };
  30. })(this));
  31. });
  32. return it("should correct the word", function() {
  33. this.result.length.should.equal(1);
  34. return this.result[0].suggestions.indexOf("business").should.not.equal(-1);
  35. });
  36. });
  37. describe("multiple words", function() {
  38. beforeEach(function(done) {
  39. return this.ASpell.checkWords("en", ["bussines", "word", "neccesary"], (function(_this) {
  40. return function(error, result) {
  41. _this.result = result;
  42. return done();
  43. };
  44. })(this));
  45. });
  46. return it("should correct the incorrect words", function() {
  47. this.result[0].index.should.equal(0);
  48. this.result[0].suggestions.indexOf("business").should.not.equal(-1);
  49. this.result[1].index.should.equal(2);
  50. return this.result[1].suggestions.indexOf("necessary").should.not.equal(-1);
  51. });
  52. });
  53. describe("without a valid language", function() {
  54. beforeEach(function(done) {
  55. return this.ASpell.checkWords("notALang", ["banana"], (function(_this) {
  56. return function(error, result) {
  57. _this.error = error;
  58. _this.result = result;
  59. return done();
  60. };
  61. })(this));
  62. });
  63. return it("should return an error", function() {
  64. return should.exist(this.error);
  65. });
  66. });
  67. describe("when there are no suggestions", function() {
  68. beforeEach(function(done) {
  69. return this.ASpell.checkWords("en", ["asdkfjalkdjfadhfkajsdhfashdfjhadflkjadhflajsd"], (function(_this) {
  70. return function(error, result) {
  71. _this.error = error;
  72. _this.result = result;
  73. return done();
  74. };
  75. })(this));
  76. });
  77. return it("should return a blank array", function() {
  78. this.result.length.should.equal(1);
  79. return this.result[0].suggestions.should.deep.equal([]);
  80. });
  81. });
  82. return describe("when the request times out", function() {
  83. beforeEach(function(done) {
  84. var i, words;
  85. words = (function() {
  86. var _i, _results;
  87. _results = [];
  88. for (i = _i = 0; _i <= 1000000; i = ++_i) {
  89. _results.push("abcdefg");
  90. }
  91. return _results;
  92. })();
  93. this.ASpell.ASPELL_TIMEOUT = 100;
  94. this.start = new Date();
  95. return this.ASpell.checkWords("en", words, (function(_this) {
  96. return function(error, result) {
  97. _this.result = result;
  98. return done();
  99. };
  100. })(this));
  101. });
  102. return it("should return in reasonable time", function(done) {
  103. return done();
  104. });
  105. });
  106. });
  107. }).call(this);