define(function() {
    describe('Minionette.CollectionView', function() {
        describe("instances", function() {
            beforeEach(function() {
                this.collection = new Backbone.Collection();
                this.view = new Minionette.CollectionView({collection: this.collection});
            });
            afterEach(function() {
                this.view.remove();
                delete this.collection;
                delete this.view;
            });

            it("sets ModelView to Backbone.View", function() {
                expect(this.view.ModelView).to.equal(Backbone.View);
            });

            describe("Collection Events", function() {
                it("#render() on collection's 'reset' event", function() {
                    expect(this.view.collectionEvents.reset).to.equal('render');
                });

                it("#render() on collection's 'sort' event", function() {
                    expect(this.view.collectionEvents.sort).to.equal('render');
                });

                it("#removeOne() on collection's 'remove' event", function() {
                    expect(this.view.collectionEvents.remove).to.equal('removeOne');
                });

                it("#addOne() on collection's 'add' event", function() {
                    expect(this.view.collectionEvents.add).to.equal('addOne');
                });
            });

            describe("#render()", function() {
                it("triggers 'render:before' event", function() {
                    var spy = this.sinon.spy();
                    this.view.on('render:before', spy);

                    this.view.render();

                    expect(spy).to.have.been.called;
                });

                it("triggers 'render' event", function() {
                    var spy = this.sinon.spy();
                    this.view.on('render', spy);

                    this.view.render();

                    expect(spy).to.have.been.called;
                });

                it("returns the view", function() {
                    var ret = this.view.render();

                    expect(ret).to.equal(this.view);
                });

                it("appends a modelView for each model in the collection", function() {
                    var models = [
                        new Backbone.Model({id: _.uniqueId()}),
                        new Backbone.Model({id: _.uniqueId()}),
                        new Backbone.Model({id: _.uniqueId()})
                    ];
                    var view = new (Minionette.CollectionView.extend({
                        ModelView: Minionette.ModelView.extend({
                            template: function(model) {return '<p>' + model.id + '</p>';}
                        })
                    }))({collection: this.collection});
                    this.collection.add(models);
                    view.$el.empty();

                    view.render();

                    expect(view.$el.text()).to.equal(_.pluck(models, 'id').join(''));
                });
            });

            describe("#addOne()", function() {
                beforeEach(function() {
                    this.model = new Backbone.Model();
                });
                afterEach(function() {
                    this.model.destroy();
                    delete this.model;
                });

                it("triggers 'addOne:before' event", function() {
                    var spy = this.sinon.spy();
                    this.view.on('addOne:before', spy);

                    this.view.addOne(this.model);

                    expect(spy).to.have.been.called;
                });

                it("triggers 'addOne' event", function() {
                    var spy = this.sinon.spy();
                    this.view.on('addOne', spy);

                    this.view.addOne(this.model);

                    expect(spy).to.have.been.called;
                });

                it("creates a view from ModelView", function() {
                    var spy = this.sinon.spy(Backbone, 'View'),
                        view = new Minionette.CollectionView({collection: this.collection});

                    view.addOne(this.model);

                    expect(spy).to.have.been.called;
                });

                it("returns the new modelView", function() {
                    var view = this.view.addOne(this.model);

                    expect(view).to.be.instanceOf(Backbone.View);
                });

                it("sets the new modelView's _parent to this", function() {
                    var view = this.view.addOne(this.model);

                    expect(view._parent).to.equal(this.view);
                });

                it("appends the new modelView's el to this.$el", function() {
                    var view = this.view.addOne(this.model);

                    expect(this.view.$el).to.have(view.$el);
                });
            });

            describe("#removeOne()", function() {
                beforeEach(function() {
                    this.model = new Backbone.Model();
                    this.modelView = this.view.addOne(this.model);
                });
                afterEach(function() {
                    this.modelView.remove();
                    this.model.destroy();
                    delete this.model;
                    delete this.modelView;
                });

                it("triggers 'removeOne:before' event", function() {
                    var spy = this.sinon.spy();
                    this.view.on('removeOne:before', spy);

                    this.view.removeOne(this.model);

                    expect(spy).to.have.been.called;
                });

                it("triggers 'removeOne' event", function() {
                    var spy = this.sinon.spy();
                    this.view.on('removeOne', spy);

                    this.view.removeOne(this.model);

                    expect(spy).to.have.been.called;
                });

                it("returns the removed view", function() {
                    var ret = this.view.removeOne(this.model);

                    expect(ret).to.equal(this.modelView);
                });

                it("calls #remove() on the view", function() {
                    var stub = this.sinon.stub(this.modelView, 'remove');

                    this.view.removeOne(this.model);

                    expect(stub).to.have.been.called;
                });
            });

            describe("#_getModelView()", function() {
                var View = Minionette.CollectionView.extend({
                    ModelView: 'DefaultModelView'
                });

                it("returns this#ModelView", function() {
                    var view = new View();
                    expect(view._getModelView()).to.equal('DefaultModelView');
                });

                it("returns ModelView passed in at instantiation", function() {
                    var view = new View({ModelView: 'instantiation'});
                    expect(view._getModelView()).to.equal('instantiation');
                });
            });
        });
    });
});

@@ -2525,16 +2525,65 @@
      %5D;%0A
+                    this.collection.add(models);%0A
         
@@ -2637,32 +2637,70 @@
 onView.extend(%7B%0A
+                        tagName: 'p',%0A
                 
@@ -2790,59 +2790,31 @@
 te: 
-function(model) %7Breturn '%3Cp%3E' + model.id + '%3C/p%3E';%7D
+_.template('%3C%25= id %25%3E')
 %0A   
@@ -2896,95 +2896,8 @@
 n%7D);
-%0A                    this.collection.add(models);%0A                    view.$el.empty();
 %0A%0A  
@@ -6491,660 +6491,8 @@
  %7D);
-%0A%0A            describe(%22#_getModelView()%22, function() %7B%0A                var View = Minionette.CollectionView.extend(%7B%0A                    ModelView: 'DefaultModelView'%0A                %7D);%0A%0A                it(%22returns this#ModelView%22, function() %7B%0A                    var view = new View();%0A                    expect(view._getModelView()).to.equal('DefaultModelView');%0A                %7D);%0A%0A                it(%22returns ModelView passed in at instantiation%22, function() %7B%0A                    var view = new View(%7BModelView: 'instantiation'%7D);%0A                    expect(view._getModelView()).to.equal('instantiation');%0A                %7D);%0A            %7D);
 %0A   

Refactor CollectionView spec