Permalink
Browse files

Fix tests.

They actually run, and I added a script to make that more convenient.
  • Loading branch information...
1 parent 11f08e5 commit 9b841caca1331e60f84d3670ee5c69646448adaa @dhasenan committed Mar 19, 2012
Showing with 82 additions and 62 deletions.
  1. +2 −0 test.sh
  2. +80 −62 test/maryjanetests.coffee
View
2 test.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+NODE_PATH=$(readlink -f lib) coffee test/maryjanetests.coffee
View
142 test/maryjanetests.coffee
@@ -13,123 +13,125 @@ class HasFields
@foo = 17
@bar = 'drinky winky!'
-exports['regurgitate an expected answer'] = ->
+tests = {}
+
+tests['regurgitate an expected answer'] = ->
mock = mj.mock(new UnderTest())
mj.when(mock).frob(1, 7).thenReturn 15
- assert.eql mock.frob(1, 7), 15
+ assert.equal mock.frob(1, 7), 15
-exports['leave the original type alone'] = ->
+tests['leave the original type alone'] = ->
a = mj.mock(new UnderTest())
mj.when(a).frob(1, 7).thenReturn 15
b = new UnderTest()
assert.throws((-> b.frob(1, 7)), 'DIVIDE BY CUCUMBER ERROR')
-exports['return null by default'] = ->
+tests['return null by default'] = ->
b = mj.mock(new UnderTest())
- assert.isNull b.frob(1, 7)
+ assert.equal null, b.frob(1, 7)
-exports['wrong arguments ignored'] = ->
+tests['wrong arguments ignored'] = ->
mock = mj.mock(new UnderTest())
mj.when(mock).frob(1, 7).thenReturn 15
- assert.isNull mock.frob(1, 8)
+ assert.equal null, mock.frob(1, 8)
-exports['not strict and i didn\'t specify one argument'] = ->
+tests['not strict and i didn\'t specify one argument'] = ->
mock = mj.mock(new UnderTest())
mj.when(mock).frob(1).lax().thenReturn 15
- assert.eql mock.frob(1, 8), 15
+ assert.equal mock.frob(1, 8), 15
-exports['strict and i didn\'t specify one argument'] = ->
+tests['strict and i didn\'t specify one argument'] = ->
mock = mj.mock(new UnderTest())
mj.when(mock).frob(1).thenReturn 15
- assert.eql mock.frob(1, 8), null
+ assert.equal mock.frob(1, 8), null
-exports['throw an exception'] = ->
+tests['throw an exception'] = ->
mock = mj.mock(new UnderTest())
ex = "who's the what now?"
mj.when(mock).frob(1, 8).thenThrow ex
assert.throws((-> mock.frob(1, 8)), ex)
-exports['user callback'] = ->
+tests['user callback'] = ->
mock = mj.mock(new UnderTest())
count = 0
mj.when(mock).frob(1, 8).thenDo (a, b) ->
- assert.eql a, 1
- assert.eql b, 8
+ assert.equal a, 1
+ assert.equal b, 8
count++
mock.frob 1, 8
- assert.eql count, 1
+ assert.equal count, 1
-exports['verify call'] = ->
+tests['verify call'] = ->
mock = mj.mock(new UnderTest())
mock.frob 1, 8
mj.verify(mock).frob 1, 8
-exports['verify call that was not called'] = ->
+tests['verify call that was not called'] = ->
mock = mj.mock(new UnderTest())
cb = -> mj.verify(mock).frob 1, 8
assert.throws cb, (ex) -> ex.message == 'Expected UnderTest.frob(1, 8) to be called at least 1 times, but it was called 0 times'
-exports['mock from base function prototype'] = ->
+tests['mock from base function prototype'] = ->
mock = mj.mock(UnderTest.prototype)
mock.frob 1, 8
mj.verify(mock).frob 1, 8
-exports['mock from base function'] = ->
+tests['mock from base function'] = ->
mock = mj.mock(UnderTest)
mock.frob 1, 8
mj.verify(mock).frob 1, 8
-exports['mock copies fields'] = ->
+tests['mock copies fields'] = ->
h = new HasFields()
mock = mj.mock(h)
- assert.eql mock.foo, h.foo
- assert.eql mock.bar, h.bar
+ assert.equal mock.foo, h.foo
+ assert.equal mock.bar, h.bar
-exports['chained expectations'] = ->
+tests['chained expectations'] = ->
mock = mj.mock(new UnderTest())
mj.when(mock).frob(1, 7).thenReturn(8).thenReturn(18).thenReturn('no thanks')
- assert.eql mock.frob(1, 7), 8
- assert.eql mock.frob(1, 7), 18
- assert.eql mock.frob(1, 7), 'no thanks'
+ assert.equal mock.frob(1, 7), 8
+ assert.equal mock.frob(1, 7), 18
+ assert.equal mock.frob(1, 7), 'no thanks'
-exports['number of times called'] = ->
+tests['number of times called'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
mock.frob(1, 7)
mj.verify(mock, mj.times(3)).frob(1, 7)
-exports['number of times called: never'] = ->
+tests['number of times called: never'] = ->
mock = mj.mock(new UnderTest())
mj.verify(mock, mj.never).frob(1, 7)
-exports['number of times called: once'] = ->
+tests['number of times called: once'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mj.verify(mock, mj.once).frob(1, 7)
-exports['number of times called: twice'] = ->
+tests['number of times called: twice'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
mj.verify(mock, mj.twice).frob(1, 7)
-exports['number of times called: thrice'] = ->
+tests['number of times called: thrice'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
mock.frob(1, 7)
mj.verify(mock, mj.thrice).frob(1, 7)
-exports['number of times called, failure, too few'] = ->
+tests['number of times called, failure, too few'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
cb = -> mj.verify(mock, mj.times(3, 3)).frob(1, 7)
assert.throws cb, (ex) ->
ex.message == 'Expected UnderTest.frob(1, 7) to be called exactly 3 times, but it was called 2 times'
-exports['number of times called, failure, too many'] = ->
+tests['number of times called, failure, too many'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
@@ -139,43 +141,43 @@ exports['number of times called, failure, too many'] = ->
assert.throws cb, (ex) ->
ex.message == 'Expected UnderTest.frob(1, 7) to be called exactly 3 times, but it was called 4 times'
-exports['number of times called: once, failure - too few'] = ->
+tests['number of times called: once, failure - too few'] = ->
mock = mj.mock(new UnderTest())
cb = -> mj.verify(mock, mj.once).frob(1, 7)
assert.throws cb, (ex) ->
ex.message == 'Expected UnderTest.frob(1, 7) to be called exactly 1 times, but it was called 0 times'
-exports['number of times called: twice, failure - too few'] = ->
+tests['number of times called: twice, failure - too few'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
cb = -> mj.verify(mock, mj.twice).frob(1, 7)
assert.throws cb, (ex) ->
ex.message == 'Expected UnderTest.frob(1, 7) to be called exactly 2 times, but it was called 1 times'
-exports['number of times called: thrice, failure - too few'] = ->
+tests['number of times called: thrice, failure - too few'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
cb = -> mj.verify(mock, mj.thrice).frob(1, 7)
assert.throws cb, (ex) ->
ex.message == 'Expected UnderTest.frob(1, 7) to be called exactly 3 times, but it was called 2 times'
-exports['number of times called: never, but actually was called'] = ->
+tests['number of times called: never, but actually was called'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
cb = -> mj.verify(mock, mj.never).frob(1, 7)
assert.throws cb, (ex) ->
ex.message == 'Expected UnderTest.frob(1, 7) to be called exactly 0 times, but it was called 1 times'
-exports['number of times called: once, failure - too many'] = ->
+tests['number of times called: once, failure - too many'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
cb = -> mj.verify(mock, mj.once).frob(1, 7)
assert.throws cb, (ex) ->
ex.message == 'Expected UnderTest.frob(1, 7) to be called exactly 1 times, but it was called 2 times'
-exports['number of times called: twice, failure - too many'] = ->
+tests['number of times called: twice, failure - too many'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
@@ -184,7 +186,7 @@ exports['number of times called: twice, failure - too many'] = ->
assert.throws cb, (ex) ->
ex.message == 'Expected UnderTest.frob(1, 7) to be called exactly 2 times, but it was called 3 times'
-exports['number of times called: thrice, failure - too many'] = ->
+tests['number of times called: thrice, failure - too many'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
@@ -194,15 +196,15 @@ exports['number of times called: thrice, failure - too many'] = ->
assert.throws cb, (ex) ->
ex.message == 'Expected UnderTest.frob(1, 7) to be called exactly 3 times, but it was called 4 times'
-exports['number of times called, at most'] = ->
+tests['number of times called, at most'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
mock.frob(1, 7)
mock.frob(1, 7)
mj.verify(mock, mj.atMost(6)).frob(1, 7)
-exports['number of times called, at most, failure'] = ->
+tests['number of times called, at most, failure'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
@@ -212,15 +214,15 @@ exports['number of times called, at most, failure'] = ->
assert.throws cb, (ex) ->
ex.message == 'Expected UnderTest.frob(1, 7) to be called at most 3 times, but it was called 4 times'
-exports['number of times called, at least'] = ->
+tests['number of times called, at least'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
mock.frob(1, 7)
mock.frob(1, 7)
mj.verify(mock, mj.atLeast(3)).frob(1, 7)
-exports['number of times called, at least, failure'] = ->
+tests['number of times called, at least, failure'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
@@ -230,15 +232,15 @@ exports['number of times called, at least, failure'] = ->
assert.throws cb, (ex) ->
ex.message == 'Expected UnderTest.frob(1, 7) to be called at least 6 times, but it was called 4 times'
-exports['number of times called, range'] = ->
+tests['number of times called, range'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
mock.frob(1, 7)
mock.frob(1, 7)
mj.verify(mock, mj.range(3, 5)).frob(1, 7)
-exports['number of times called, range, too high'] = ->
+tests['number of times called, range, too high'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
@@ -248,7 +250,7 @@ exports['number of times called, range, too high'] = ->
assert.throws cb, (ex) ->
ex.message == 'Expected UnderTest.frob(1, 7) to be called between 6 and 19 times, but it was called 4 times'
-exports['number of times called, range, too low'] = ->
+tests['number of times called, range, too low'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
@@ -258,11 +260,11 @@ exports['number of times called, range, too low'] = ->
assert.throws cb, (ex) ->
ex.message == 'Expected UnderTest.frob(1, 7) to be called between 1 and 3 times, but it was called 4 times'
-exports['verifyNoMoreInteractions'] = ->
+tests['verifyNoMoreInteractions'] = ->
mock = mj.mock(new UnderTest())
mj.verifyNoMoreInteractions(mock)
-exports['verifyNoMoreInteractions failure'] = ->
+tests['verifyNoMoreInteractions failure'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
@@ -272,16 +274,16 @@ exports['verifyNoMoreInteractions failure'] = ->
assert.throws cb, (ex) ->
ex.message == 'Expected:\n\tUnderTest.frob(1, 7) should not be called\nActual:\n\tUnderTest.frob(1, 7) was called 4 times'
-exports['verifyZeroInteractions'] = ->
+tests['verifyZeroInteractions'] = ->
mock = mj.mock(new UnderTest())
mj.verifyZeroInteractions(mock)
-exports['verifyZeroInteractions with setup'] = ->
+tests['verifyZeroInteractions with setup'] = ->
mock = mj.mock(new UnderTest())
mj.when(mock).frob(1, 7).thenReturn 4
mj.verifyZeroInteractions(mock)
-exports['verifyZeroInteractions failure'] = ->
+tests['verifyZeroInteractions failure'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mock.frob(1, 7)
@@ -291,32 +293,48 @@ exports['verifyZeroInteractions failure'] = ->
assert.throws cb, (ex) ->
ex.message == 'Expected no interactions with UnderTest, but UnderTest.frob(1, 7) was called 4 times'
-exports['matchers by position and failed non-matcher arg match'] = ->
+tests['matchers by position and failed non-matcher arg match'] = ->
mock = mj.mock(new UnderTest())
mj.when(mock).frob(1, mj.match((x) -> x % 6 == 1)).thenReturn(187)
- assert.eql mock.frob(2, 7), null
+ assert.equal mock.frob(2, 7), null
-exports['matchers by position and failed matcher match'] = ->
+tests['matchers by position and failed matcher match'] = ->
mock = mj.mock(new UnderTest())
mj.when(mock).frob(1, mj.match((x) -> x % 6 == 1)).thenReturn(187)
- assert.eql mock.frob(1, 8), null
+ assert.equal mock.frob(1, 8), null
-exports['matchers by position'] = ->
+tests['matchers by position'] = ->
mock = mj.mock(new UnderTest())
mj.when(mock).frob(mj.match((x) -> x == 1), mj.match((x) -> x % 6 == 1)).thenReturn(187)
- assert.eql mock.frob(1, 7), 187
+ assert.equal mock.frob(1, 7), 187
-exports['verify by matcher'] = ->
+tests['verify by matcher'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 7)
mj.verify(mock).frob((mj.match((x) -> x == 1)), 7)
-exports['verify by matcher but does not match'] = ->
+tests['verify by matcher but does not match'] = ->
mock = mj.mock(new UnderTest())
mock.frob(2, 7)
assert.throws -> mj.verify(mock).frob((mj.match((x) -> x == 1)), 7)
-exports['verify by matcher but non-matcher arg does not match'] = ->
+tests['verify by matcher but non-matcher arg does not match'] = ->
mock = mj.mock(new UnderTest())
mock.frob(1, 8)
assert.throws -> mj.verify(mock).frob((mj.match((x) -> x == 1)), 7)
+
+count = 0
+pass = 0
+for k, v of tests
+ count++
+ try
+ v()
+ pass++
+ catch ex
+ console.error "#{k} failed: #{ex}"
+
+console.log "#{pass}/#{count} tests pass"
+if pass == count
+ console.log "SUCCESS"
+else
+ console.log "FAILURE"

0 comments on commit 9b841ca

Please sign in to comment.