Skip to content
Browse files

Adding specs for Smoke#printArguments. Making Smoke#printArguments mo…

…re robust
  • Loading branch information...
1 parent e6755f5 commit 3583eba018854d06b0bd85fd0e392be8fbb1ca64 @kristopher kristopher committed Jun 8, 2009
Showing with 38 additions and 5 deletions.
  1. +15 −5 lib/smoke.core.js
  2. +23 −0 spec/core_spec.js
View
20 lib/smoke.core.js
@@ -5,10 +5,20 @@ Smoke = {
},
printArguments: function(args) {
- var args = (args || []), a = [];
- for(var i = 0; i < args.length; i++) {
- a.push(Smoke.print(args[i]));
- }
- return '(' + a.join(', ') + ')';
+ var a = [];
+ if (args === undefined) args = '';
+ if ((args && args.callee) || (args instanceof Array)) {
+ for(var i = 0; i < args.length; i++) {
+ a.push(Smoke.print(args[i]));
+ }
+ } else {
+ // Workaround for jQuery.print returning "null" when called with an empty string.
+ if (!args && (typeof args == 'string')) {
+ a.push('');
+ } else {
+ a.push(Smoke.print(args));
+ }
+ }
+ return '(' + a.join(', ') + ')';
}
};
View
23 spec/core_spec.js
@@ -0,0 +1,23 @@
+Screw.Unit(function() {
+ describe("core", function() {
+ describe("printArguments", function() {
+ var anonymous_function = function() { return arguments };
+ it("should return '()' is the arguments are empty", function() {
+ expect(Smoke.printArguments(arguments)).to(equal, '()');
+ });
+
+ it("should return '()' is the arguments are undefined", function() {
+ expect(Smoke.printArguments()).to(equal, '()');
+ });
+
+ it("should return the arguments comma seperated wrapped in parenthesis", function() {
+ var args = anonymous_function(1,2);
+ expect(Smoke.printArguments(args)).to(equal, '(1, 2)');
+ });
+
+ it("should handle being passed something other than an array or arguments object", function() {
+ expect(Smoke.printArguments(false)).to(equal, '(false)');
+ });
+ });
+ });
+});

0 comments on commit 3583eba

Please sign in to comment.
Something went wrong with that request. Please try again.