Screw.Unit and Smoke Example

Tagged with ScrewUnit Javascript Smoke Testing

Language: JavaScript

View as text

function Cat(){

}

Cat.meow = function() {
  return "meow";
};

Cat.lol = function() {
  return "I can haz";
}

Screw.Unit(function() {
  describe("The stubbing process",function(){
    it("--- well, 0 equals 0",function(){
      expect(0).to(equal,0);
    });
  });
  describe("Cats",function(){
    describe("lol method",function(){
      it("should return 'I can haz'",function(){
        expect(Cat.lol()).to(equal,"I can haz");
      });
    });
    describe("meow method",function(){
      it("should return 'meow'",function(){
        expect(Cat.meow()).to(equal,"meow");
      });
      describe("when stubbed",function(){
        before(function(){
          stubbedCat = Smoke.Mock(Cat);
          stubbedCat.should_receive('meow').and_return("woof");
        });
        it("should return 'woof'",function(){
          expect(stubbedCat.meow()).to(equal,"woof");
          Smoke.checkExpectations();
        });
        it("should not affect lol method",function(){
          expect(Cat.lol()).to(equal,"I can haz");
        });
      });
    });
  });
});
Original snippet written by Kevin Gisi
Last updated at 01:30 AM on Jun 06, 2009

SnippetStash costs money to host and develop. The service is free for everyone to use
but if you found it useful please consider making a small donation.