views:

432

answers:

0

With my two attempts at getting a message posted to the JSpec Google Group having apparently failed, I'm posting here instead.

I'm having trouble with JSpec apparently going into an infinite recursive loop with a certain kind of test (below). Any ideas? It there something wrong with my code or is it JSpec? I'm Running JSpec 2.11.2 via Ruby Gem.

The errors are 'RangeError: Maximum call stack size exceeded.' (Safari) and 'InternalError: too much recursion' (FF/Mac). I can add an Item to a Room using the Firebug console, with no errors.

To reproduce the problem, create a template jspec project using 'jspec init test'. Then edit the following files like so:

yourlib.core.js

var Game = {};

Game.item = function () {
  var result = {
    name : 'Undefined',
    room : null
  }

  return result;
};

Game.room = function () {
  var result = {
    items : [],
    addItem : function (name) {
      var item = Game.item();
      item.name = name;
      item.room = this;
      this.items.push(item);

      return item;
    }
  };

  return result;
};

spec.core.js

describe 'Room'
  before_each
    room = Game.room()
  end

  describe 'addItem()'
    before_each
      potion = room.addItem('Potion')
      key = room.addItem('Key')
    end

    //this is fine
    it 'should return two different items'
      key.should_not.be potion
    end

    //InternalError: too much recursion
    it 'should not give recursion error'
      key.should.be potion
    end
  end
end