main
 1describe ("Fake", function() {
 2  beforeEach (function() {
 3    sut = new Fake();
 4  });
 5  var sut;
 6  describe ("when stubbing out return values", function() {
 7    describe ("when there are no parameters", function() {
 8      it ("should return the correct value", function() {
 9        expect(result).toEqual("hello");
10      });
11      beforeEach (function() {
12        sut.stub('greet').andReturn('hello');
13        result = sut.greet();
14      });
15      var result;
16    });
17    describe ("when there are arguments to match", function() {
18      describe ("when there is a single input argument", function() {
19        describe ("when invoked as expected", function() {
20          it ("should return the value the corresponds to the input arguments", function() {
21            expect(sut.greet('mo')).toEqual('hello mo');
22          });
23          it ("should return the correct value that corresponds to other args", function() {
24            expect(sut.greet('jo')).toEqual('hello jo');
25          });
26          beforeEach (function() {
27            sut.stub('greet').with('mo').andReturn('hello mo');
28            sut.stub('greet').with('jo').andReturn('hello jo');
29          });
30        });
31        describe ("when invoked unexpectedly", function() {
32          it ("should throw an error", function() {
33            sut.stub('greet').with('mo').andReturn('hello mo');
34            expect(function(){sut.greet('malcolm');}).toThrow("Matcher not found.");
35          });
36        });
37      });
38    });
39  });
40});