Browse files

Refactor jasmine spec: extract common setup

  • Loading branch information...
1 parent 8c3009a commit 1f6ef498dc7f29a7d5a4c667ed21ffe1acb08449 @jasonm committed Oct 10, 2011
Showing with 4 additions and 14 deletions.
  1. +4 −14 spec/javascripts/views/room_list_spec.js
View
18 spec/javascripts/views/room_list_spec.js
@@ -1,14 +1,13 @@
describe("Views.RoomList", function() {
- var rooms;
+ var rooms, el, view;
beforeEach(function() {
rooms = new ChatApp.Collections.Rooms([{ name: "Red" }, { name: "Blue" }]);
+ el = $("<div></div>");
+ view = new ChatApp.Views.RoomList({ el: el, collection: rooms });
});
it("renders a new room form", function() {
- var el = $("<div></div>");
- var view = new ChatApp.Views.RoomList({ el: el, collection: rooms });
-
view.render();
expect(el).toContain("form");
@@ -17,33 +16,24 @@ describe("Views.RoomList", function() {
});
it("creates a new room when the form is submitted", function() {
- var el = $("<div></div>");
sinon.stub(rooms, "create");
-
- var view = new ChatApp.Views.RoomList({ el: el, collection: rooms });
-
view.render();
+
$("input[name=name]", el).val("Watercooler");
$("form", el).submit();
expect(rooms.create).toHaveBeenCalled();
});
it("renders the list of rooms", function() {
- var el = $("<div></div>");
- var view = new ChatApp.Views.RoomList({ el: el, collection: rooms });
-
view.render();
expect(el).toContain("ul#chat-rooms li a:contains('Red')")
expect(el).toContain("ul#chat-rooms li a:contains('Blue')")
});
it("re-renders when a model is added to the collection", function() {
- var el = $("<div></div>");
- var view = new ChatApp.Views.RoomList({ el: el, collection: rooms });
view.render();
-
rooms.add({ name: "Green" });
expect(el).toContain("ul#chat-rooms li a:contains('Green')")

0 comments on commit 1f6ef49

Please sign in to comment.