Skip to content

Commit

Permalink
run specs with buster instead of the dead project 'jasmine-runner'
Browse files Browse the repository at this point in the history
  • Loading branch information
flosse committed Aug 28, 2012
1 parent 2b1ab53 commit c8223b7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 51 deletions.
13 changes: 9 additions & 4 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,16 @@ connection.rpc.addJidToWhiteList("*@*");

## Tests & specs

I use the node module `jasmine-runner` for the tests. Install it and use it as follow :
I use the node module `buster` for the tests. Install it and use it as follow :

```bash
$ npm install jasmine-runner
$ jasmine mon
$ npm install buster
$ buster server
```

The tests run in the browser at the address `localhost:8124`.
Open a browser and navigate to `http://localhost:1111` and capture the browser.
Then you can run the tests:

```
$ buster test --browser
```
11 changes: 11 additions & 0 deletions rpc/buster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var config = module.exports;

config["rpc"] = {
environment: "browser",
specs: ["spec/*.spec.js"],
sources: ["strophe.rpc.js"],
libs: [
"lib/strophe.js",
"spec/strophe.rpc.spec.helper.js"
]
};
10 changes: 0 additions & 10 deletions rpc/jasmine.json

This file was deleted.

67 changes: 33 additions & 34 deletions rpc/spec/strophe.rpc.spec.helper.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
var helper = (function() {
function receive(c,req) {
c._dataRecv(createRequest(req));
}
function receive(c,req) {
c._dataRecv(createRequest(req));
}

function spyon (obj, method, cb) {
spyOn(obj,method).andCallFake(function(res) {
res = res;
cb.call(this,res);
});
}
function spyon (obj, method, cb) {
sinon.stub(obj,method, function(res) {
cb.call(this,res);
});
}

function mockConnection() {
var c = new Strophe.Connection();
c.authenticated = true;
c.jid = 'n@d/r2';
c._processRequest = function() {};
c._changeConnectStatus(Strophe.Status.CONNECTED);
return c;
}
function mockConnection() {
var c = new Strophe.Connection();
c.authenticated = true;
c.jid = 'n@d/r2';
c._processRequest = function() {};
c._changeConnectStatus(Strophe.Status.CONNECTED);
return c;
}

function createRequest(iq) {
iq = typeof iq.tree == "function" ? iq.tree() : iq;
var req = new Strophe.Request(iq, function() {});
req.getResponse = function() {
var env = new Strophe.Builder('env', {type: 'mock'}).tree();
env.appendChild(iq);
return env;
};
return req;
}
function createRequest(iq) {
iq = typeof iq.tree == "function" ? iq.tree() : iq;
var req = new Strophe.Request(iq, function() {});
req.getResponse = function() {
var env = new Strophe.Builder('env', {type: 'mock'}).tree();
env.appendChild(iq);
return env;
};
return req;
}

return {
createRequest: createRequest,
mockConnection: mockConnection,
receive: receive,
spyon: spyon
};
})();
return {
createRequest: createRequest,
mockConnection: mockConnection,
receive: receive,
spyon: spyon
};
})();
8 changes: 5 additions & 3 deletions rpc/spec/strophe.rpc.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
buster.spec.expose()

var mockConnection = helper.mockConnection,
spyon = helper.spyon, receive = helper.receive;

Expand Down Expand Up @@ -161,7 +163,7 @@ describe("Strophe Jabber-RPC plugin", function() {
var handler;

beforeEach(function() {
handler = jasmine.createSpy();
handler = sinon.spy();
});

it("should be possible to add a request handler", function() {
Expand Down Expand Up @@ -246,7 +248,7 @@ describe("Strophe Jabber-RPC plugin", function() {
});

it("should NOT send forbidden access to the right nodes", function() {
spyOn(connection, "send");
spyon(connection, "send");
var iq = $iq({type: "set", id: "123", from: "[email protected]", to: connection.jid})
.c("query", {xmlns: Strophe.NS.RPC});
receive(connection, iq);
Expand All @@ -257,4 +259,4 @@ describe("Strophe Jabber-RPC plugin", function() {

});

});
});

0 comments on commit c8223b7

Please sign in to comment.