Permalink
Browse files

Adds syntax highlighting to all examples.

  • Loading branch information...
1 parent a20cfd8 commit f11916add84d0f6b4d80391617eb103e5192a335 Seth Purcell committed Dec 28, 2012
Showing with 27 additions and 23 deletions.
  1. +27 −23 README.md
View
@@ -52,41 +52,45 @@ Promises make Node programming far less painful and error-prone, but there are a
## Example: a more useful app
- var capsela = require('capsela');
+```js
+var capsela = require('capsela');
- new capsela.Server()
- .addStage(new capsela.stages.PreferredHost('www.capsela.org'))
- .addStage(new capsela.stages.ViewRenderer(__dirname + '/views', capsela.views.JsonTemplate))
- .addStage(new capsela.stages.ErrorHandler(errorTemplate))
- .addStage(new capsela.stages.FileServer('/', __dirname + '/public'))
- .addStage(new capsela.stages.SessionManager())
- .addStage(new capsela.stages.Dispatcher(__dirname + '/controllers'))
- .start();
+new capsela.Server()
+ .addStage(new capsela.stages.PreferredHost('www.capsela.org'))
+ .addStage(new capsela.stages.ViewRenderer(__dirname + '/views', capsela.views.JsonTemplate))
+ .addStage(new capsela.stages.ErrorHandler(errorTemplate))
+ .addStage(new capsela.stages.FileServer('/', __dirname + '/public'))
+ .addStage(new capsela.stages.SessionManager())
+ .addStage(new capsela.stages.Dispatcher(__dirname + '/controllers'))
+ .start();
+```
As you'd expect, Capsela comes out of the box with several stages that provide solutions to common problems such as error handling, serving static files, managing sessions, and dispatching to MVC-style controllers.
A core requirement of Capsela is testability: unit and functional tests need to be easy to write and have the greatest possible veracity. This has driven both the architecture of the framework itself as well as a major investment in developing test infrastructure, including accurate mocks of Node objects such as ServerRequest and ServerResponse, and powerful testing tools such as the Browser class.
## Example: an end-to-end app test
- var browser = new Browser();
+```js
+var browser = new Browser();
- browser.get(appBaseUrl + '/login').then(
- function() {
- browser.fill('email', 'test@example.com');
- browser.fill('password', 'password1');
+browser.get(appBaseUrl + '/login').then(
+ function() {
+ browser.fill('email', 'test@example.com');
+ browser.fill('password', 'password1');
- return browser.pressButton('Sign in');
- }
- ).then(
- function(response) {
+ return browser.pressButton('Sign in');
+ }
+).then(
+ function(response) {
- var $ = browser.window.$;
+ var $ = browser.window.$;
- test.equal(response.statusCode, 200);
- test.ok($('.error').text().indexOf("Sorry, that password is incorrect.") >= 0);
- }
- ).end();
+ test.equal(response.statusCode, 200);
+ test.ok($('.error').text().indexOf("Sorry, that password is incorrect.") >= 0);
+ }
+).end();
+```
You might have noticed that we're using jQuery in the assertions, which is a beautiful way of analyzing HTML responses; the browser window contains a full DOM implementation (courtesy of JSDOM). As you can see, the promise-based Browser class provides a powerful and natural testing style that lets you develop high-quality code with minimal effort. It can also be used for making assertions against JSON and binary responses, for loading and making assertions against HTML emails, or as a powerful page-scraper in your application proper.

0 comments on commit f11916a

Please sign in to comment.