<commit_before>var rewire = require('rewire');
var ProjectVelocityView = rewire('views/project_velocity_view');

describe('ProjectVelocityView', function() {

  beforeEach(function() {
    this.model = {on: sinon.stub()};
    var overrideView = this.overrideView = {};
    function ProjectVelocityOverrideView() {
      return overrideView;
    }

    ProjectVelocityOverrideView.prototype.template = sinon.stub();

    this.revertRewire = ProjectVelocityView.__set__({
      ProjectVelocityOverrideView: ProjectVelocityOverrideView
    });

    this.subject = new ProjectVelocityView({model: this.model});
  });

  afterEach(function() {
    this.revertRewire();
  });

  it("should have a top level element", function() {
    expect(this.subject.el.nodeName).toEqual('DIV');
  });

  describe("initialize", function() {

    it("creates the override view", function() {
      expect(this.subject.override_view).toEqual(this.overrideView);
    });

    it("binds setFakeClass to change:userVelocity on the model", function() {
      expect(this.model.on).toHaveBeenCalledWith(
        "change:userVelocity", this.subject.setFakeClass
      );
    });

    it("binds render to rebuilt-iterations on the model", function() {
      expect(this.model.on).toHaveBeenCalledWith(
        "rebuilt-iterations", this.subject.render
      );
    });

  });

  describe("render", function() {

    beforeEach(function() {
      this.subject.$el.html = sinon.stub();
      this.subject.setFakeClass = sinon.stub();
      this.template = {};
      this.subject.template = sinon.stub().withArgs({project: this.model}).returns(this.template);
    });

    it("renders the template", function() {
      this.subject.render();
      expect(this.subject.$el.html).toHaveBeenCalledWith(this.template);
    });

    it("calls setFakeClass()", function() {
      this.subject.render();
      expect(this.subject.setFakeClass).toHaveBeenCalledWith(this.model);
    });

    it("returns itself", function() {
      expect(this.subject.render()).toBe(this.subject);
    });

  });

  describe("editVelocityOverride", function() {

    beforeEach(function() {
      this.el = {};
      this.subject.override_view.render = sinon.stub();
      this.subject.override_view.render.returns({el: this.el});
      this.subject.$el.append = sinon.stub();
    });

    it("appends the override view to its $el", function() {
      this.subject.editVelocityOverride();
      expect(this.subject.$el.append).toHaveBeenCalled(this.el);
    });

  });

  describe("setFakeClass", function() {

    beforeEach(function() {
      this.model.velocityIsFake = sinon.stub();
    });

    describe("when velocity is fake", function() {

      beforeEach(function() {
        this.model.velocityIsFake.returns(true);
      });

      it("adds the fake class to $el", function() {
        this.subject.setFakeClass(this.model);
        expect(this.subject.$el).toHaveClass('fake');
      });

    });

    describe("when velocity is not fake", function() {

      beforeEach(function() {
        this.model.velocityIsFake.returns(false);
      });

      it("adds the fake class to $el", function() {
        this.subject.setFakeClass(this.model);
        expect(this.subject.$el).not.toHaveClass('fake');
      });

    });
  });
});
<commit_msg>Fix failed specs<commit_after>var rewire = require('rewire');
var ProjectVelocityView = rewire('views/project_velocity_view');

describe('ProjectVelocityView', function() {

  beforeEach(function() {
    this.model = {};
    var overrideView = this.overrideView = {};
    function ProjectVelocityOverrideView() {
      return overrideView;
    }

    ProjectVelocityOverrideView.prototype.template = sinon.stub();

    this.revertRewire = ProjectVelocityView.__set__({
      ProjectVelocityOverrideView: ProjectVelocityOverrideView
    });

    this.subject = new ProjectVelocityView({model: this.model});
    this.subject.listenTo = sinon.stub();
  });

  afterEach(function() {
    this.revertRewire();
  });

  it("should have a top level element", function() {
    expect(this.subject.el.nodeName).toEqual('DIV');
  });

  describe("initialize", function() {

    it("creates the override view", function() {
      expect(this.subject.override_view).toEqual(this.overrideView);
    });

    it("binds setFakeClass to change:userVelocity on the model", function() {
      expect(this.subject.listenTo).toHaveBeenCalledWith(
        this.subject.model, "change:userVelocity", this.subject.setFakeClass
      );
    });

    it("binds render to rebuilt-iterations on the model", function() {
      expect(this.subject.listenTo).toHaveBeenCalledWith(
        this.subject.model, "rebuilt-iterations", this.subject.render
      );
    });

  });

  describe("render", function() {

    beforeEach(function() {
      this.subject.$el.html = sinon.stub();
      this.subject.setFakeClass = sinon.stub();
      this.template = {};
      this.subject.template = sinon.stub().withArgs({project: this.model}).returns(this.template);
    });

    it("renders the template", function() {
      this.subject.render();
      expect(this.subject.$el.html).toHaveBeenCalledWith(this.template);
    });

    it("calls setFakeClass()", function() {
      this.subject.render();
      expect(this.subject.setFakeClass).toHaveBeenCalledWith(this.model);
    });

    it("returns itself", function() {
      expect(this.subject.render()).toBe(this.subject);
    });

  });

  describe("editVelocityOverride", function() {

    beforeEach(function() {
      this.el = {};
      this.subject.override_view.render = sinon.stub();
      this.subject.override_view.render.returns({el: this.el});
      this.subject.$el.append = sinon.stub();
    });

    it("appends the override view to its $el", function() {
      this.subject.editVelocityOverride();
      expect(this.subject.$el.append).toHaveBeenCalled(this.el);
    });

  });

  describe("setFakeClass", function() {

    beforeEach(function() {
      this.model.velocityIsFake = sinon.stub();
    });

    describe("when velocity is fake", function() {

      beforeEach(function() {
        this.model.velocityIsFake.returns(true);
      });

      it("adds the fake class to $el", function() {
        this.subject.setFakeClass(this.model);
        expect(this.subject.$el).toHaveClass('fake');
      });

    });

    describe("when velocity is not fake", function() {

      beforeEach(function() {
        this.model.velocityIsFake.returns(false);
      });

      it("adds the fake class to $el", function() {
        this.subject.setFakeClass(this.model);
        expect(this.subject.$el).not.toHaveClass('fake');
      });

    });
  });
});

{'fraction_non_alphanumeric': 0.15746971736204576, 'fraction_numerical': 0.0, 'mean_word_length': 3.2517482517482517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5995521', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1968, 'n_words': 310}