Permalink
Browse files

Add a couple of simple Jasmine specs

  • Loading branch information...
1 parent 69f6a3d commit fd3f741a5fff21a2bbf690858343b707c68cde39 @rf- committed Dec 31, 2012
Showing with 65 additions and 8 deletions.
  1. +4 −1 lib/pry-notebook/files/main.js
  2. +13 −4 lib/pry-notebook/files/notebook.js
  3. +48 −3 lib/pry-notebook/files/test.js
@@ -1,5 +1,8 @@
$(function () {
- var nb = new Notebook({ input: ".input input", output: ".output" });
+ var nb = new Notebook({
+ input: $(".footer input"),
+ output: $(".output")
+ });
Notebook.openSocket(function (msg) {
nb.handleMessage(JSON.parse(msg.data));
@@ -1,4 +1,6 @@
function Notebook(options) {
+ this.output = options.output;
+ this.input = options.input;
this.bindKeyup();
};
@@ -10,14 +12,21 @@ Notebook.openSocket = function(callback) {
};
Notebook.prototype.handleMessage = function(data) {
- var div = $('<div/>').addClass("pry-" + data.type).text(data.value);
- $('.output').append(div);
+ var html = $('<div/>').text(data.value).html();
+ div = $('<div/>').addClass("pry-" + data.type).html(html);
+ this.output.append(div);
+};
+
+Notebook.prototype.sendLine = function(line) {
+ $.post('/', line);
};
Notebook.prototype.bindKeyup = function () {
- $('input').on('keyup', function (e) {
+ var self = this;
+
+ this.input.on('keyup', function (e) {
if (e.keyCode == 13) {
- $.post('/', $(this).val());
+ self.sendLine($(this).val());
$(this).val('');
}
});
@@ -1,5 +1,50 @@
-describe("This shit", function() {
- it("is bananas", function() {
- expect(true).toBe(true);
+describe("Pry Notebook", function() {
+ beforeEach(function () {
+ this.output = { append: jasmine.createSpy("append") };
+ this.input = { on: jasmine.createSpy("on") };
+ this.notebook = new Notebook({
+ output: this.output,
+ input: this.input
+ });
+ });
+
+ describe("handling return values", function () {
+ beforeEach(function () {
+ this.notebook.handleMessage({
+ type: "value",
+ value: "100"
+ });
+
+ var call = this.output.append.mostRecentCall;
+ this.el = call && call.args && call.args[0];
+ });
+
+ it("appends them to the output div", function() {
+ expect(this.output.append).toHaveBeenCalled();
+ });
+
+ it("uses the class 'pry-value'", function() {
+ expect(this.el.hasClass("pry-value")).toBe(true);
+ });
+ });
+
+ describe("handling errors", function () {
+ beforeEach(function () {
+ this.notebook.handleMessage({
+ type: "error",
+ value: "An Error Message"
+ });
+
+ var call = this.output.append.mostRecentCall;
+ this.el = call && call.args && call.args[0];
+ });
+
+ it("appends them to the output div", function() {
+ expect(this.output.append).toHaveBeenCalled();
+ });
+
+ it("uses the class 'pry-error'", function() {
+ expect(this.el.hasClass("pry-error")).toBe(true);
+ });
});
});

0 comments on commit fd3f741

Please sign in to comment.