Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Got all tests running properly.

  • Loading branch information...
commit f1166a905009a6108b954316a69567552ad38bd8 1 parent 8264965
Jonathan Hoyt authored March 30, 2012
32  spec/ResultsSpec.coffee
... ...
@@ -1,11 +1,13 @@
1 1
 describe 'Results', ->
2 2
   beforeEach ->
3 3
     @app = new App
  4
+    $('ul#results').remove()
  5
+    $('body').append('<ul id="results"></ul>')
  6
+    $('ul#groups').remove()
  7
+    $('body').append('<ul id="groups"><li id="match_1"><ol></ol></li></ul>')
4 8
 
5  
-  # setup test subjects
6 9
   subjects = [
7 10
     {'regex': 'a', 'test_strings': [{'string': 'a'}], 'output': '<span>a</span>'}
8  
-    {'regex': 'a(.*)c', 'test_strings': [{'string': 'abc', 'matches': ['b']}], 'output': '<span>abc</span>'}
9 11
     {'regex': 'a(.*)c', 'test_strings': [{'string': 'abcdd', 'matches': ['b']}], 'output': '<span>abc</span>dd'}
10 12
     {'regex': 'f(oo)', 'test_strings': [{'string': 'foodbar', 'matches': ['oo']}], 'output': '<span>foo</span>dbar'}
11 13
     {
@@ -14,10 +16,11 @@ describe 'Results', ->
14 16
       'output': '<span>https</span>://github.com'
15 17
     }
16 18
     {
17  
-      'regex': '^(https?)://((?:[A-Z0-9]*\.?)*)((?:\/?[A-Z0-9])*)'
  19
+      'regex': '^(https?)://((?:[A-Z0-9]*\\.?)*)((?:\\/?[A-Z0-9])*)'
  20
+      'option': 'i'
18 21
       'test_strings': [
19 22
         {'string': 'https://github.com/jonmagic/scriptular', 'matches': ['https', 'github.com', '/jonmagic/scriptular']}
20  
-        {'string': 'http://scriptular.com', 'matches': ['https', 'github.com', '/jonmagic/scriptular']}
  23
+        {'string': 'http://scriptular.com', 'matches': ['http', 'scriptular.com']}
21 24
         {'string': 'http://www.google.com'}
22 25
         {'string': 'http://www.guardian.co.uk'}
23 26
       ]
@@ -26,28 +29,27 @@ describe 'Results', ->
26 29
     {'regex': 'mono', 'option': 'g', 'test_strings': [{'string': 'monolimamonolima'}], 'output': '<span>mono</span>lima<span>mono</span>lima'}
27 30
   ]
28 31
 
29  
-  # look thru subjects
30 32
   for subject, i in subjects
31 33
     do (subject) ->
32 34
       it "subject #{i} returns correct output", ->
33 35
         @app.expression.value = @app.expression.buildRegex(subject['regex'], subject['option'])
34 36
         @app.test_strings.values = (item['string'] for item in subject['test_strings'])
35 37
 
36  
-        spyOn @app.results, 'drawResult'
37 38
         @app.results.compile()
38  
-        expect(@app.results.drawResult).toHaveBeenCalledWith(subject['output'])
  39
+        expect($('ul#results li').html()).toEqual(subject['output'])
39 40
 
40  
-  for subject, i in subjects
41  
-    for test in subject['test_strings']
42  
-      do (subject) ->
43  
-        it "subject #{i} returns correct groups", ->
  41
+  for subject in subjects
  42
+    do (subject) ->
  43
+      it "subject #{subject['regex']} returns correct groups", ->
  44
+        for test in subject['test_strings']
44 45
           return true unless test['matches']
45 46
 
46 47
           @app.expression.value = @app.expression.buildRegex(subject['regex'], subject['option'])
47  
-          @app.test_strings.values = test['string']
  48
+          @app.test_strings.values = [test['string']]
48 49
 
49  
-          spyOn @app.results, 'drawGroup'
50 50
           @app.results.compile()
51  
-          for match in test['matches']
52  
-            expect(@app.results.drawGroup).toHaveBeenCalledWith(1, match)
53 51
 
  52
+          expect($('ul#groups ol li').length).toBe(test['matches'].length)
  53
+
  54
+          for match, i in test['matches']
  55
+            expect($($('ul#groups ol li')[i]).text()).toEqual(match);
74  spec/ResultsSpec.js
... ...
@@ -1,9 +1,13 @@
1 1
 (function() {
2 2
 
3 3
   describe('Results', function() {
4  
-    var i, subject, subjects, test, _fn, _len, _len2, _results;
  4
+    var i, subject, subjects, _fn, _i, _len, _len2, _results;
5 5
     beforeEach(function() {
6  
-      return this.app = new App;
  6
+      this.app = new App;
  7
+      $('ul#results').remove();
  8
+      $('body').append('<ul id="results"></ul>');
  9
+      $('ul#groups').remove();
  10
+      return $('body').append('<ul id="groups"><li id="match_1"><ol></ol></li></ul>');
7 11
     });
8 12
     subjects = [
9 13
       {
@@ -18,15 +22,6 @@
18 22
         'regex': 'a(.*)c',
19 23
         'test_strings': [
20 24
           {
21  
-            'string': 'abc',
22  
-            'matches': ['b']
23  
-          }
24  
-        ],
25  
-        'output': '<span>abc</span>'
26  
-      }, {
27  
-        'regex': 'a(.*)c',
28  
-        'test_strings': [
29  
-          {
30 25
             'string': 'abcdd',
31 26
             'matches': ['b']
32 27
           }
@@ -51,14 +46,15 @@
51 46
         ],
52 47
         'output': '<span>https</span>://github.com'
53 48
       }, {
54  
-        'regex': '^(https?)://((?:[A-Z0-9]*\.?)*)((?:\/?[A-Z0-9])*)',
  49
+        'regex': '^(https?)://((?:[A-Z0-9]*\\.?)*)((?:\\/?[A-Z0-9])*)',
  50
+        'option': 'i',
55 51
         'test_strings': [
56 52
           {
57 53
             'string': 'https://github.com/jonmagic/scriptular',
58 54
             'matches': ['https', 'github.com', '/jonmagic/scriptular']
59 55
           }, {
60 56
             'string': 'http://scriptular.com',
61  
-            'matches': ['https', 'github.com', '/jonmagic/scriptular']
  57
+            'matches': ['http', 'scriptular.com']
62 58
           }, {
63 59
             'string': 'http://www.google.com'
64 60
           }, {
@@ -91,9 +87,8 @@
91 87
           }
92 88
           return _results;
93 89
         })();
94  
-        spyOn(this.app.results, 'drawResult');
95 90
         this.app.results.compile();
96  
-        return expect(this.app.results.drawResult).toHaveBeenCalledWith(subject['output']);
  91
+        return expect($('ul#results li').html()).toEqual(subject['output']);
97 92
       });
98 93
     };
99 94
     for (i = 0, _len = subjects.length; i < _len; i++) {
@@ -101,34 +96,27 @@
101 96
       _fn(subject);
102 97
     }
103 98
     _results = [];
104  
-    for (i = 0, _len2 = subjects.length; i < _len2; i++) {
105  
-      subject = subjects[i];
106  
-      _results.push((function() {
107  
-        var _i, _len3, _ref, _results2;
108  
-        _ref = subject['test_strings'];
109  
-        _results2 = [];
110  
-        for (_i = 0, _len3 = _ref.length; _i < _len3; _i++) {
111  
-          test = _ref[_i];
112  
-          _results2.push((function(subject) {
113  
-            return it("subject " + i + " returns correct groups", function() {
114  
-              var match, _j, _len4, _ref2, _results3;
115  
-              if (!test['matches']) return true;
116  
-              this.app.expression.value = this.app.expression.buildRegex(subject['regex'], subject['option']);
117  
-              this.app.test_strings.values = test['string'];
118  
-              spyOn(this.app.results, 'drawGroup');
119  
-              this.app.results.compile();
120  
-              _ref2 = test['matches'];
121  
-              _results3 = [];
122  
-              for (_j = 0, _len4 = _ref2.length; _j < _len4; _j++) {
123  
-                match = _ref2[_j];
124  
-                _results3.push(expect(this.app.results.drawGroup).toHaveBeenCalledWith(1, match));
125  
-              }
126  
-              return _results3;
127  
-            });
128  
-          })(subject));
129  
-        }
130  
-        return _results2;
131  
-      })());
  99
+    for (_i = 0, _len2 = subjects.length; _i < _len2; _i++) {
  100
+      subject = subjects[_i];
  101
+      _results.push((function(subject) {
  102
+        return it("subject " + subject['regex'] + " returns correct groups", function() {
  103
+          var i, match, test, _j, _len3, _len4, _ref, _ref2;
  104
+          _ref = subject['test_strings'];
  105
+          for (_j = 0, _len3 = _ref.length; _j < _len3; _j++) {
  106
+            test = _ref[_j];
  107
+            if (!test['matches']) return true;
  108
+            this.app.expression.value = this.app.expression.buildRegex(subject['regex'], subject['option']);
  109
+            this.app.test_strings.values = [test['string']];
  110
+            this.app.results.compile();
  111
+            expect($('ul#groups ol li').length).toBe(test['matches'].length);
  112
+            _ref2 = test['matches'];
  113
+            for (i = 0, _len4 = _ref2.length; i < _len4; i++) {
  114
+              match = _ref2[i];
  115
+              expect($($('ul#groups ol li')[i]).text()).toEqual(match);
  116
+            }
  117
+          }
  118
+        });
  119
+      })(subject));
132 120
     }
133 121
     return _results;
134 122
   });

0 notes on commit f1166a9

Please sign in to comment.
Something went wrong with that request. Please try again.