jasmine / jasmine-gem

Jasmine ruby gem
682 stars 274 forks source link

Test failure with `rake jasmine:ci` but passes fine with `rake jasmine` #242

Closed cannikin closed 8 years ago

cannikin commented 9 years ago

Any hints as to what could be happening here? I've got a spec that runs fine in Chrome with rake jasmine but fails in the terminal with rake jasmine:ci. It's testing a Backbone.js comparator. It looks like it blows the stack trying to run the test:

Entry = Backbone.Model.extend({});

Entries = Entries = Backbone.Collection.extend({
  model: CalCounter.Models.Entry,
  comparator: function(entry) {
    return -Date.parse(entry.get('ate_at'));
  }
});

// test
describe("CalCounter.Collections.Entries", function() {
  it("sorts entries by ate_at, newest first", function() {
    var first = new CalCounter.Models.Entry({ate_at: '2015-04-03 12:00'});
    var second = new CalCounter.Models.Entry({ate_at: '2015-04-01 09:00'});
    var third = new CalCounter.Models.Entry({ate_at: '2015-04-02 12:00'});
    var entries = new CalCounter.Collections.Entries([first, second, third]);

    expect(entries.at(0)).toEqual(first);
    expect(entries.at(1)).toEqual(third);
    expect(entries.at(2)).toEqual(second);
  });
});

Here's the stack trace: https://gist.github.com/cannikin/ac26ad79879b10926d68

I see a bunch of <circular reference: Object> in the output which is why I'm guessing the stack is overflowing. But why is it only a problem when PhantomJS is running things and not Chrome?

slackersoft commented 9 years ago

What version of jasmine are you using?

The problem is basically that once the models are put into a collection they become cyclic. One of the models properties is the collection, the collection has an array of models, etc. One way to work around this would be to write a custom equality tester that knows to compare two Backbone.Model objects by looking at their attributes (I think that's what it's called).

cannikin commented 9 years ago

I'm on 2.2.0 of Jasmine.

How come that cyclical nature doesn't cause a problem when running the tests in the browser, only through the CI?

I updated my test to check that the ID attribute matched instead of the whole object. Works like a charm, thanks!

slackersoft commented 8 years ago

The cyclical nature usually causes problems specifically when trying to serialize the data from the browser out to either phantomjs or selenium (depending on which browsers you're using).

Or it could just be a difference between running the specs in Chrome vs running them in PhantomJS and what the maximum stack depth is.

Closing, since it sounds like you've got a fix that works for you.