Merge lp:~divmod-dev/divmod.org/831895-assertThrows-varargs into lp:divmod.org

Proposed by Jonathan Jacobs
Status: Merged
Merged at revision: 2703
Proposed branch: lp:~divmod-dev/divmod.org/831895-assertThrows-varargs
Merge into: lp:divmod.org
Diff against target: 67 lines (+33/-4)
2 files modified
Nevow/nevow/js/Divmod/Test/TestUnitTest.js (+27/-0)
Nevow/nevow/js/Divmod/UnitTest.js (+6/-4)
To merge this branch: bzr merge lp:~divmod-dev/divmod.org/831895-assertThrows-varargs
Reviewer Review Type Date Requested Status
Jean-Paul Calderone Approve
Review via email: mp+72547@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jean-Paul Calderone (exarkun) wrote :

This looks good to me, tests pass on my system. Please merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Nevow/nevow/js/Divmod/Test/TestUnitTest.js'
2--- Nevow/nevow/js/Divmod/Test/TestUnitTest.js 2008-02-26 07:18:22 +0000
3+++ Nevow/nevow/js/Divmod/Test/TestUnitTest.js 2011-08-23 11:04:24 +0000
4@@ -123,6 +123,33 @@
5
6
7 /**
8+ * L{assertThrows} passes additional varargs to C{callable}.
9+ */
10+ function test_assertThrowsVarargs(self) {
11+ var args = [];
12+ function foo(a, b, c) {
13+ args.push(a);
14+ args.push(b);
15+ args.push(c);
16+ throw Divmod.UnitTest.AssertionError();
17+ }
18+
19+ var expectedArgs = [1, 'two', [3, 3, 3]];
20+ try {
21+ self.assertThrows(
22+ Divmod.UnitTest.AssertionError,
23+ foo,
24+ expectedArgs[0],
25+ expectedArgs[1],
26+ expectedArgs[2]);
27+ } catch (e) {
28+ self.fail("assertThrows should have passed: " + e.message);
29+ }
30+ self.assertArraysEqual(args, expectedArgs);
31+ },
32+
33+
34+ /**
35 * Test that L{compare} does not raise an exception if its callable
36 * returns C{true}.
37 */
38
39=== modified file 'Nevow/nevow/js/Divmod/UnitTest.js'
40--- Nevow/nevow/js/Divmod/UnitTest.js 2008-12-31 18:44:01 +0000
41+++ Nevow/nevow/js/Divmod/UnitTest.js 2011-08-23 11:04:24 +0000
42@@ -406,8 +406,9 @@
43 * @param expectedError: The error type (class or prototype) which is
44 * expected to be thrown.
45 *
46- * @param callable: A no-argument callable which is expected to throw
47- * C{expectedError}.
48+ * @param callable: A callable which is expected to throw C{expectedError}.
49+ *
50+ * @param ...: Optional positional arguments passed to C{callable}.
51 *
52 * @throw AssertionError: Thrown if the callable doesn't throw
53 * C{expectedError}. This could be because it threw a different error or
54@@ -415,10 +416,11 @@
55 *
56 * @return: The exception that was raised by callable.
57 */
58- function assertThrows(self, expectedError, callable) {
59+ function assertThrows(self, expectedError, callable /*... */) {
60 var threw = null;
61+ var args = Array.prototype.slice.call(arguments, 3);
62 try {
63- callable();
64+ callable.apply(null, args);
65 } catch (e) {
66 threw = e;
67 self.assert(e instanceof expectedError,

Subscribers

People subscribed via source and target branches

to all changes: