Skip to content

Instantly share code, notes, and snippets.

@cpsubrian
Created August 1, 2011 01:58
Show Gist options
  • Select an option

  • Save cpsubrian/1117455 to your computer and use it in GitHub Desktop.

Select an option

Save cpsubrian/1117455 to your computer and use it in GitHub Desktop.
Using tobi with vows.
var vows = require('vows')
, tobi = require('tobi')
, port = 80
, host = 'www.google.com';
/**
* Topic macro to GET a url.
*/
var getUrl = function(url) {
return function() {
var browser = tobi.createBrowser(port, host);
browser.get(url, this.callback.bind(this, null));
}
}
/**
* Sample test.
*/
vows.describe('Tobi Test').addBatch({
'A request to the frontpage of google': {
topic: getUrl('/'),
'should have a status of 200': function(_, res, $){
res.should.have.status(200);
},
'should have an image with alt="Google"': function(_, res, $) {
$('img[alt="Google"]').should.exist;
}
}
}).export(module);
@cmeiklejohn

Copy link
Copy Markdown
   ✗ should have a status of 200
      » expected { external: undefined,
  history: [ '/' ],
  cookieJar: { cookies: [] },
  followRedirects: true,
  port: 80,
  host: 'www.google.com',
  https: false } to have a property 'statusCode' // should.js:474

@cpsubrian

Copy link
Copy Markdown
Author

Just tried it with tobi 0.3.1 and vows 0.5.8 and it worked fine. I haven't had a ton of time to play with node lately so those might be out of date.

@cmeiklejohn

Copy link
Copy Markdown

Found my problem; working in coffeescript and topic implicit return was burning me.

@mikemaccana

Copy link
Copy Markdown

FYI I can run the example above changing host to be any site and the following vow:

$('img[alt="Google"]').should.exist;

Is still true from this gist, though there's no such image on the page and the selector returns nothing when run from the inspector.

@cpsubrian

Copy link
Copy Markdown
Author

Probably should be $('img[alt="Google"]').length.should.be.equal(1); or something. I haven't been using vows or tobi lately, but I'm glad people are still finding this example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment