<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -26,7 +26,8 @@ Smoke.Mock = function(originalObj) {
 	obj._expectations = {};
 	obj.stub = function(attr){
 		return new Smoke.Stub(this, attr);
-	},
+	};
+	
 	obj.should_receive = function(attr){
 		var expectation = new Smoke.Mock.Expectation(this, attr);
 		if(this._expectations[attr]==undefined) this._expectations[attr] = [];
@@ -39,17 +40,30 @@ Smoke.Mock = function(originalObj) {
 			return previousFunction!=undefined ? previousFunction.apply(mock,arguments) : undefined;
 		};
 		return expectation;
-	},
+	};
+
 	obj.checkExpectations = function(){
 		for(var e in this._expectations) {
 			var expectations = this._expectations[e]
 			for(var i=0; i &lt; expectations.length; i++) expectations[i].check();
 		};
-	},
+	};
+	
 	Smoke.mocks.push(obj);
 	return obj;
 };
 
+Smoke.MockFunction = function(originalFunction, name) {
+  var name = name || 'anonymous_function';
+  var originalFunction = originalFunction || function() {};
+  var scope = function() { return scope.mockFunction.apply(this,arguments) };
+  scope[name] = originalFunction;
+  scope.mockFunction = function() { return scope[name].apply(this,arguments); };
+  var mock = Smoke.Mock(scope);
+  mock.should_be_invoked = function() { return mock.should_receive(name) };
+  return mock;
+};
+
 Smoke.Mock.Expectation = function(mock, attr) {
 	this._mock = mock;
 	this._attr = attr;
@@ -84,7 +98,7 @@ Smoke.Mock.Expectation.prototype = {
 		};
 	},
 	and_return: function(v){
-		this.returnValue = v
+		this.returnValue = v;
 	},
 	check: function(){
 		if(this.exactCount!=undefined) this.checkExactCount();</diff>
      <filename>lib/smoke.mock.js</filename>
    </modified>
    <modified>
      <diff>@@ -5,6 +5,10 @@ Screw.Matchers.mock = function(m) {
   return Smoke.Mock(m);
 };
 
+Screw.Matchers.mock_function = function(func,name) {
+  return Smoke.MockFunction(func,name);
+};
+
 Screw.Matchers.stub = function(obj, attr) {
   return new Smoke.Stub(obj,attr);
 };</diff>
      <filename>plugins/screw.mocking.js</filename>
    </modified>
    <modified>
      <diff>@@ -129,6 +129,50 @@ Screw.Unit(function() {
 			});
 		});
 		
+		describe(&quot;anonymous functions&quot;, function() {
+			before(function() {
+				foo = function() { return 'bar' };
+				mockObj = mock_function(foo);
+			});
+      
+      it(&quot;should leave the original intact&quot;, function() {
+        expect(foo()).to(equal,'bar');
+      });
+      
+      it(&quot;should still execute the mock like the original&quot;, function() {
+        expect(mockObj()).to(equal,'bar');
+      });
+      
+      it(&quot;should still execute the mock like the original with arguments&quot;, function() {
+        var a = function(x,y,z) { return x+y+z };
+        aMock = mock_function(a)
+        expect(aMock('a','b','c')).to(equal,'abc');
+      });
+      
+      it(&quot;should allow expectations to be set as usual&quot;, function() {
+        mockObj.should_receive('baz').exactly('once').and_return(1);
+        mockObj.baz()
+      });
+
+      it(&quot;should allow expectations to be set on invocations of itself&quot;, function() {
+        mockObj.should_be_invoked();
+        mockObj();
+      });
+      
+      it(&quot;should allow expectation rules to be set&quot;, function() {
+        mockObj.should_be_invoked().exactly('twice').with_arguments('a');
+        mockObj('a');
+        mockObj('a');
+      });
+      
+      it(&quot;should not call the original if a return value is specified&quot;, function() {
+        var func = function() { throw(&quot;I should not be called&quot;) };
+        var mockFunc = mock_function(func);
+        mockFunc.should_be_invoked().and_return('hello');
+        expect(mockFunc()).to(equal, 'hello');
+      });
+		});
+		
 		describe(&quot;when array has been monkey-patched by js library not to be named here (grrr)&quot;, function() {
       before(function() {
         Array.prototype.remove = function() {</diff>
      <filename>spec/mock_spec.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>3ce48364bb8580af8f047db005f4a8b18376e6e5</id>
    </parent>
  </parents>
  <author>
    <name>Andy Kent</name>
    <email>andrew.d.kent@gmail.com</email>
  </author>
  <url>http://github.com/andykent/smoke/commit/6cf673edcf591f2434a7110f65bd3c05c2c3d33e</url>
  <id>6cf673edcf591f2434a7110f65bd3c05c2c3d33e</id>
  <committed-date>2009-05-19T11:26:21-07:00</committed-date>
  <authored-date>2009-05-19T11:26:21-07:00</authored-date>
  <message>there is now a mock_function macro for mocking on anonymous functions</message>
  <tree>89454b5ffb7692b79ea417fa538959af31b244f7</tree>
  <committer>
    <name>Andy Kent</name>
    <email>andrew.d.kent@gmail.com</email>
  </committer>
</commit>
