Skip to content
Browse files

Adding Smoke#argumentToArray. Turns an arguments object into an actua…

…l array.
  • Loading branch information...
1 parent 3583eba commit 13349ca1e5a4e7e3a44561398840b78d0e4f4760 @kristopher kristopher committed Jun 8, 2009
Showing with 31 additions and 3 deletions.
  1. +14 −1 lib/smoke.core.js
  2. +17 −2 spec/core_spec.js
View
15 lib/smoke.core.js
@@ -20,5 +20,18 @@ Smoke = {
}
}
return '(' + a.join(', ') + ')';
- }
+ },
+
+ argumentsToArray: function(args) {
+ if (args.callee) {
+ var array = []
+ for(var i = 0; i < args.length; i++) {
+ array.push(args[i]);
+ }
+ return array;
+ } else {
+ return args;
+ }
+ }
+
};
View
19 spec/core_spec.js
@@ -1,7 +1,7 @@
Screw.Unit(function() {
describe("core", function() {
+ var anonymous_function = function() { return arguments };
describe("printArguments", function() {
- var anonymous_function = function() { return arguments };
it("should return '()' is the arguments are empty", function() {
expect(Smoke.printArguments(arguments)).to(equal, '()');
});
@@ -18,6 +18,21 @@ Screw.Unit(function() {
it("should handle being passed something other than an array or arguments object", function() {
expect(Smoke.printArguments(false)).to(equal, '(false)');
});
- });
+ });
+
+ describe("argumentsToArray", function() {
+ it("should return an array", function() {
+ expect(Smoke.argumentsToArray(anonymous_function(1,2)) instanceof Array).to(equal, true);
+ });
+
+ it("should return the arguments in an array", function() {
+ expect(Smoke.argumentsToArray(anonymous_function(1,2))).to(equal, [1,2]);
+ });
+
+ it("should return the array if passed an array", function() {
+ var array = [];
+ expect(Smoke.argumentsToArray(array) === array).to(equal, true)
+ })
+ });
});
});

0 comments on commit 13349ca

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