Nickolay - Test.Run-0.06
Name
Test.Run.Test.More - A role with additional assertion check, which can be used in tests.
SYNOPSIS
t.plan(3)
t.diag('Starting..')
t.like('this', /this/, 'Probably similar things')
t.unlike('this', 'that', 'Unlikely..')
t.throws_ok(function(){
throw "Ups"
}, /ups/i, 'Ups was thrown correctly :)')
DESCRIPTION
Test.Run.Test.More is a role, consumed by the Test.Run.Test and providing some general-purpose (platform independed) assertions checks.
DOES
None
USAGE
Below is the list of methods, intended for usage in the individual tests.
like
void like(String str, String|RegExp regex, text)This method add the passed or failed assertion into results queue. The type of assertion to add is determined from testing the passed string (1st argument) against a regular expression (2nd argument)
str - The string to test
regex - The regex against which to test the string, can be also a plain string
text - The text of the assertion
unlike
void unlike(String str, String|RegExp regex, text)This method is the opposite of 'like', it adds failed assertion, when the string matches the passed regex.
str - The string to test
regex - The regex against which to test the string, can be also a plain string
text - The text of the assertion
throws_ok
void throws_ok(Function func, String|RegExp expected, text)This method add the passed or failed assertion into results queue. The type of assertion to add is determined from the following: The passed 'func' function is executing, and its expected to throw an exception. Then the exception object is stringified and passed to 'like' method along with 'expected' parameter.
func - The function which supposed to throw an exception
expected - The regex against which to test the stringified exception, can be also a plain string
text - The text of the assertion
SEE ALSO
General documentation for Joose: http://openjsan.org/go/?l=Joose
BUGS
All complex software has bugs lurking in it, and this module is no exception.
Please report any bugs through the web interface at http://github.com/SamuraiJack/Module-Stub/issues
AUTHORS
Nickolay Platonov nplatonov@cpan.org
COPYRIGHT AND LICENSE
Copyright (c) 2009, Nickolay Platonov
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of Nickolay Platonov nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Role('Test.Run.Test.More', {
methods : {
like : function (string, regex, desc) {
if (regex instanceof RegExp)
this.ok(string.match(regex), desc)
else
this.ok(string.indexOf(regex) != -1, desc)
},
unlike : function(string, regex, desc) {
if (regex instanceof RegExp)
this.ok(!string.match(regex), desc)
else
this.ok(string.indexOf(regex) == -1, desc)
},
throws_ok : function(func, expected, desc) {
if (typeof func != 'function') throw 'throws_ok accepts a function as 1st argument'
var e = this.topScope.__EXCEPTION_CATCHER__(func)
if (e instanceof this.topScope.Error)
//IE uses non-standard 'description' property for error msg
e = e.message || e.description
this.like('' + e, expected, desc + ' (got [' + e + '], expected [' + expected + '])')
}
}
})
//eof Test.Run.Test.More
Test.Run.Test.meta.extend({
does : [ Test.Run.Test.More ]
})
/**
Name
====
Test.Run.Test.More - A role with additional assertion check, which can be used in tests.
SYNOPSIS
========
t.plan(3)
t.diag('Starting..')
t.like('this', /this/, 'Probably similar things')
t.unlike('this', 'that', 'Unlikely..')
t.throws_ok(function(){
throw "Ups"
}, /ups/i, 'Ups was thrown correctly :)')
DESCRIPTION
===========
`Test.Run.Test.More` is a role, consumed by the [Test.Run.Test] and providing some general-purpose (platform independed) assertions checks.
DOES
====
None
USAGE
=====
Below is the list of methods, intended for usage in the individual tests.
### like
> `void like(String str, String|RegExp regex, text)`
> This method add the passed or failed assertion into results queue. The type of assertion to add is determined from testing the passed string (1st argument)
against a regular expression (2nd argument)
> **str** - The string to test
> **regex** - The regex against which to test the string, can be also a plain string
> **text** - The text of the assertion
### unlike
> `void unlike(String str, String|RegExp regex, text)`
> This method is the opposite of 'like', it adds failed assertion, when the string matches the passed regex.
> **str** - The string to test
> **regex** - The regex against which to test the string, can be also a plain string
> **text** - The text of the assertion
### throws_ok
> `void throws_ok(Function func, String|RegExp expected, text)`
> This method add the passed or failed assertion into results queue. The type of assertion to add is determined from the following:
The passed 'func' function is executing, and its expected to throw an exception. Then the exception object is stringified and passed to 'like' method along with 'expected' parameter.
> **func** - The function which supposed to throw an exception
> **expected** - The regex against which to test the *stringified* exception, can be also a plain string
> **text** - The text of the assertion
SEE ALSO
========
General documentation for Joose: [http://openjsan.org/go/?l=Joose](http://openjsan.org/go/?l=Joose)
BUGS
====
All complex software has bugs lurking in it, and this module is no exception.
Please report any bugs through the web interface at [http://github.com/SamuraiJack/Module-Stub/issues](http://github.com/SamuraiJack/Module-Stub/issues)
AUTHORS
=======
Nickolay Platonov [nplatonov@cpan.org](mailto:nplatonov@cpan.org)
COPYRIGHT AND LICENSE
=====================
Copyright (c) 2009, Nickolay Platonov
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Nickolay Platonov nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
[Test.Run.Test]: ../Test.html
*/