2009-11-21 03:33:06 +01:00
|
|
|
|
2009-11-21 03:33:26 +01:00
|
|
|
describe 'Failing specs'
|
2009-11-21 03:33:06 +01:00
|
|
|
|
|
|
|
it 'should fail'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function(){
|
|
|
|
'test'.should.not.eql 'test'
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message("expected 'test' to not eql 'test'")
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail with one faulty assertion'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
'test'.should.equal 'test'
|
|
|
|
'test'.should.equal 'foo'
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message("expected 'test' to be 'foo'")
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail and print array with square braces'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
[1,2].should.equal [1,3]
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message("expected [ 1, 2 ] to be [ 1, 3 ]")
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail and print nested array'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
[1, ['foo']].should.equal [1, ['bar', ['whatever', 1.0, { foo : 'bar', bar : { 1 : 2 } }]]]
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message(/^expected \[\s*1,\s*\[\s*'foo'/)
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail with selector for jQuery objects'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
elem = { jquery : '1.3.1', selector : '.foobar' }
|
|
|
|
elem.should.eql 'foo'
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message("expected selector '.foobar' to eql 'foo'")
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
2009-11-21 03:33:26 +01:00
|
|
|
it 'should fail with negated message'
|
|
|
|
spec = mock_it(function(){
|
|
|
|
'1'.should.not.be_true
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message(/expected '1' to not be true/)
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail with positive message'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
false.should.be_true
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message(/expected false to be true/)
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail saying which error has been thrown'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
-{ throw 'foo' }.should.throw_error 'bar'
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message("expected exception of 'bar' to be thrown, but got 'foo'")
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail saying no error was thrown'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
-{ }.should.throw_error 'foo'
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message("expected exception of 'foo' to be thrown, but nothing was")
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail saying no error matching was thrown'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
-{ throw 'bar' }.should.throw_error(/foo/)
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message("expected exception matching /foo/ to be thrown, but got 'bar'")
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail saying constructors'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
-{ throw new TypeError('oh no') }.should.throw_error(Error)
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message("expected Error to be thrown, but got TypeError: oh no")
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail saying multiple arg messages'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
-{ throw new TypeError('oh no') }.should.throw_error(TypeError, /foo/)
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message("expected TypeError and exception matching /foo/ to be thrown, but got TypeError: oh no")
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail with constructor name'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
function Foo(){}
|
|
|
|
function Bar(){}
|
|
|
|
Bar.prototype.toString = function(){ return 'Bar: oh no' }
|
|
|
|
-{ throw new Bar }.should.throw_error Foo
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message("expected Foo to be thrown, but got Bar: oh no")
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail with constructor name'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
function Foo(){ this.toString = function(){ return '<Foo>' }}
|
|
|
|
foo = new Foo
|
|
|
|
foo.should.not.be_an_instance_of Foo
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message("expected <Foo> to not be an instance of Foo")
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail with message of first failure'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
true.should.be_true
|
|
|
|
'bar'.should.match(/foo/gm)
|
|
|
|
'bar'.should.include 'foo'
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message("expected 'bar' to match /foo/gm")
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should fail with list'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
['foo', 'bar'].should.include 'foo', 'car'
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message("expected [ 'foo', 'bar' ] to include 'foo', 'car'")
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should catch exceptions throw within specs'
|
2009-11-21 03:33:26 +01:00
|
|
|
spec = mock_it(function() {
|
|
|
|
throw new Error('Oh noes!')
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message(/Error: Oh noes!/)
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
2009-11-21 03:33:26 +01:00
|
|
|
it 'should catch exceptions without constructors'
|
|
|
|
spec = mock_it(function() {
|
|
|
|
throw 'oh noes'
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message(/oh noes/)
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
2009-11-21 03:33:26 +01:00
|
|
|
it 'should catch indirect exceptions'
|
|
|
|
spec = mock_it(function() {
|
|
|
|
iDoNotExist.neitherDoI()
|
|
|
|
})
|
|
|
|
spec.should.have_failure_message(/iDoNotExist/)
|
2009-11-21 03:33:06 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Contexts'
|
|
|
|
before
|
|
|
|
JSpec.context = { iLike : 'cookies' }
|
|
|
|
end
|
|
|
|
|
|
|
|
after
|
|
|
|
JSpec.context = null
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should be replaceable'
|
|
|
|
iLike.should.equal 'cookies'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Misc'
|
|
|
|
it 'requires implementation'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|