Commit e604d78

mo k <mo@mokhan.ca>
2012-05-21 18:17:47
throw error when a matcher is not found.
1 parent c5bb8e1
Changed files (1)
spec
javascripts
spec/javascripts/FakeSpec.js
@@ -3,9 +3,8 @@ describe ("Fake", function() {
     sut = new Fake();
   });
   var sut;
-
   describe ("when stubbing out return values", function() {
-    describe ("when there is no args", function() {
+    describe ("when there are no parameters", function() {
       it ("should return the correct value", function() {
         expect(result).toEqual("hello");
       });
@@ -17,15 +16,23 @@ describe ("Fake", function() {
     });
     describe ("when there are arguments to match", function() {
       describe ("when there is a single input argument", function() {
-        it ("should return the value the corresponds to the input arguments", function() {
-          expect(sut.greet('mo')).toEqual('hello mo');
+        describe ("when invoked as expected", function() {
+          it ("should return the value the corresponds to the input arguments", function() {
+            expect(sut.greet('mo')).toEqual('hello mo');
+          });
+          it ("should return the correct value that corresponds to other args", function() {
+            expect(sut.greet('jo')).toEqual('hello jo');
+          });
+          beforeEach (function() {
+            sut.stub('greet').with('mo').andReturn('hello mo');
+            sut.stub('greet').with('jo').andReturn('hello jo');
+          });
         });
-        it ("should return the correct value that corresponds to other args", function() {
-          expect(sut.greet('jo')).toEqual('hello jo');
-        });
-        beforeEach (function() {
-          sut.stub('greet').with('mo').andReturn('hello mo');
-          sut.stub('greet').with('jo').andReturn('hello jo');
+        describe ("when invoked unexpectedly", function() {
+          it ("should throw an error", function() {
+            sut.stub('greet').with('mo').andReturn('hello mo');
+            expect(function(){sut.greet('malcolm');}).toThrow("Matcher not found.");
+          });
         });
       });
     });