Skip to content

Instantly share code, notes, and snippets.

@chrisjpowers
Created November 3, 2011 18:43

Revisions

  1. chrisjpowers created this gist Nov 3, 2011.
    4 changes: 4 additions & 0 deletions conundrum.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    var Conundrum = {
    doIt: function() {return "did it"; },
    doItCopy: function() {return this.doIt(); }
    };
    23 changes: 23 additions & 0 deletions conundrum_spec.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    describe('conundrum',function(){
    describe("faking actual method", function() {
    beforeEach(function() {
    spyOn(Conundrum, "doIt").andReturn("fake");
    });

    it("fakes both calls", function() {
    expect(Conundrum.doIt()).toEqual("fake");
    expect(Conundrum.doItCopy()).toEqual("fake");
    });
    });

    describe("faking the reference", function() {
    beforeEach(function() {
    spyOn(Conundrum, "doItCopy").andReturn("fake");
    });

    it("only fakes the call to the reference", function() {
    expect(Conundrum.doIt()).toEqual("did it");
    expect(Conundrum.doItCopy()).toEqual("fake");
    });
    });
    });