Permalink
Browse files

Got all tests running properly.

  • Loading branch information...
jonmagic committed Mar 30, 2012
1 parent 8264965 commit f1166a905009a6108b954316a69567552ad38bd8
Showing with 48 additions and 58 deletions.
  1. +17 −15 spec/ResultsSpec.coffee
  2. +31 −43 spec/ResultsSpec.js
View
@@ -1,11 +1,13 @@
describe 'Results', ->
beforeEach ->
@app = new App
+ $('ul#results').remove()
+ $('body').append('<ul id="results"></ul>')
+ $('ul#groups').remove()
+ $('body').append('<ul id="groups"><li id="match_1"><ol></ol></li></ul>')
- # setup test subjects
subjects = [
{'regex': 'a', 'test_strings': [{'string': 'a'}], 'output': '<span>a</span>'}
- {'regex': 'a(.*)c', 'test_strings': [{'string': 'abc', 'matches': ['b']}], 'output': '<span>abc</span>'}
{'regex': 'a(.*)c', 'test_strings': [{'string': 'abcdd', 'matches': ['b']}], 'output': '<span>abc</span>dd'}
{'regex': 'f(oo)', 'test_strings': [{'string': 'foodbar', 'matches': ['oo']}], 'output': '<span>foo</span>dbar'}
{
@@ -14,10 +16,11 @@ describe 'Results', ->
'output': '<span>https</span>://github.com'
}
{
- 'regex': '^(https?)://((?:[A-Z0-9]*\.?)*)((?:\/?[A-Z0-9])*)'
+ 'regex': '^(https?)://((?:[A-Z0-9]*\\.?)*)((?:\\/?[A-Z0-9])*)'
+ 'option': 'i'
'test_strings': [
{'string': 'https://github.com/jonmagic/scriptular', 'matches': ['https', 'github.com', '/jonmagic/scriptular']}
- {'string': 'http://scriptular.com', 'matches': ['https', 'github.com', '/jonmagic/scriptular']}
+ {'string': 'http://scriptular.com', 'matches': ['http', 'scriptular.com']}
{'string': 'http://www.google.com'}
{'string': 'http://www.guardian.co.uk'}
]
@@ -26,28 +29,27 @@ describe 'Results', ->
{'regex': 'mono', 'option': 'g', 'test_strings': [{'string': 'monolimamonolima'}], 'output': '<span>mono</span>lima<span>mono</span>lima'}
]
- # look thru subjects
for subject, i in subjects
do (subject) ->
it "subject #{i} returns correct output", ->
@app.expression.value = @app.expression.buildRegex(subject['regex'], subject['option'])
@app.test_strings.values = (item['string'] for item in subject['test_strings'])
- spyOn @app.results, 'drawResult'
@app.results.compile()
- expect(@app.results.drawResult).toHaveBeenCalledWith(subject['output'])
+ expect($('ul#results li').html()).toEqual(subject['output'])
- for subject, i in subjects
- for test in subject['test_strings']
- do (subject) ->
- it "subject #{i} returns correct groups", ->
+ for subject in subjects
+ do (subject) ->
+ it "subject #{subject['regex']} returns correct groups", ->
+ for test in subject['test_strings']
return true unless test['matches']
@app.expression.value = @app.expression.buildRegex(subject['regex'], subject['option'])
- @app.test_strings.values = test['string']
+ @app.test_strings.values = [test['string']]
- spyOn @app.results, 'drawGroup'
@app.results.compile()
- for match in test['matches']
- expect(@app.results.drawGroup).toHaveBeenCalledWith(1, match)
+ expect($('ul#groups ol li').length).toBe(test['matches'].length)
+
+ for match, i in test['matches']
+ expect($($('ul#groups ol li')[i]).text()).toEqual(match);
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit f1166a9

Please sign in to comment.