diff --git a/lib/rss.js b/lib/rss.js
index 96f0e67..f103c6a 100644
--- a/lib/rss.js
+++ b/lib/rss.js
@@ -11,7 +11,7 @@ function RSS (options, items) {
this.title = options.title || 'Untitled RSS Feed';
this.description = options.description || '';
- this.generator = options.generator || 'NodeJS RSS Module';
+ this.generator = options.generator || 'RSS for Node';
this.feed_url = options.feed_url;
this.site_url = options.site_url;
this.image_url = options.image_url;
@@ -85,8 +85,7 @@ function generateXML (data){
ifTruePush(category, channel, { category: { _cdata: category } });
});
}
- // { updated: new Date().toGMTString() }
-
+
data.items.forEach(function(item) {
var item_values = [
{ title: { _cdata: item.title } }
@@ -141,6 +140,4 @@ function generateXML (data){
] };
}
-
-
-module.exports = RSS;
+module.exports = RSS;
\ No newline at end of file
diff --git a/package.json b/package.json
index ba9190b..b5ca975 100644
--- a/package.json
+++ b/package.json
@@ -27,7 +27,14 @@
"xml": ">= 0.0.4",
"mime": ">= 1.2.9"
},
+ "devDependencies": {
+ "chai": "~1.7.2",
+ "mocha": "~1.12.0"
+ },
"main": "lib/rss.js",
+ "scripts": {
+ "test": "./node_modules/.bin/mocha --reporter spec"
+ },
"engines": { "node": ">=0.4.0" },
"licenses" :
[
diff --git a/readme.md b/readme.md
index f808c3e..9464aca 100644
--- a/readme.md
+++ b/readme.md
@@ -6,13 +6,6 @@
$ npm install rss
-## Tests
-
- Use [nodeunit](https://github.com/caolan/nodeunit) to run the tests.
-
- $ npm install nodeunit
- $ nodeunit test
-
## Usage
var RSS = require('rss');
@@ -94,6 +87,12 @@ an have any number of items. Ten to tenty is usually good.
* _xml([indent])_ - return the xml. If you pass in true it will use four spaces for indenting. If you prefer
tabs use \t instead of true.
+## Tests
+
+ Mocha tests are included. Use `npm test` to run the tests.
+
+ $ npm test
+
## Notes
* You do not need to escape anything. This module will escape characters when necessary.
* This module is very fast but you might as well cache the output of xml() and serve
diff --git a/test/test.js b/test/rss.test.js
similarity index 87%
rename from test/test.js
rename to test/rss.test.js
index 8aac3ab..c186020 100644
--- a/test/test.js
+++ b/test/rss.test.js
@@ -1,21 +1,21 @@
/*
- use nodeunit to run tests.
+ use `npm test` to run tests using mocha
*/
var RSS = require('../lib/rss');
+var expect = require('chai').expect;
+describe('rss module', function(done) {
-module.exports = {
-
- 'empty feed': function(test) {
+ it('should work with an empty feed', function(done) {
var feed = new RSS();
- test.equal(feed.xml(), '\nhttp://github.com/dylan/node-rssNodeJS RSS Module' + new Date().toUTCString() +'');
+ expect(feed.xml()).to.equal('\nhttp://github.com/dylan/node-rssNodeJS RSS Module' + new Date().toUTCString() +'');
feed.item();
- test.equal(feed.xml(), '\nhttp://github.com/dylan/node-rssNodeJS RSS Module' + new Date().toUTCString() +'- No title
');
- test.done();
- },
+ expect(feed.xml()).to.equal('\nhttp://github.com/dylan/node-rssNodeJS RSS Module' + new Date().toUTCString() +'- No title
');
+ done();
+ });
- 'easy test': function(test) {
+ it('should work with an easy test', function(done) {
var feed = new RSS({
title: 'title',
description: 'description',
@@ -72,12 +72,12 @@ module.exports = {
var expectedResult = '\nhttp://example.comhttp://example.com/icon.pngtitlehttp://example.comExample Generator' + new Date().toUTCString() +'Sun, 20 May 2012 04:00:00 GMThttp://example.com/rss/docs.html60- http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT
- http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT
- http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT
- ]]>html]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT
- http://example.com/article5http://example.com/article5Mon, 28 May 2012 04:00:00 GMT
';
var result = feed.xml();
- test.equal(result.length, expectedResult.length);
- test.equal(result, expectedResult);
- test.done();
- },
+ expect(result).to.have.length(expectedResult.length);
+ expect(result).to.equal(expectedResult);
+ done();
+ });
- 'easy test without image_url': function(test) {
+ it('should work without image_url', function(done) {
var feed = new RSS({
title: 'title',
description: 'description',
@@ -132,12 +132,12 @@ module.exports = {
var expectedResult = '\nhttp://example.comNodeJS RSS Module' + new Date().toUTCString() +'Sun, 20 May 2012 04:00:00 GMThttp://example.com/rss/docs.html60- http://example.com/article1http://example.com/article1Thu, 24 May 2012 04:00:00 GMT
- http://example.com/article2http://example.com/article2Fri, 25 May 2012 04:00:00 GMT
- http://example.com/article3item3Sat, 26 May 2012 04:00:00 GMT
- ]]>html]]>http://example.com/article4?this&thathttp://example.com/article4?this&thatSun, 27 May 2012 04:00:00 GMT
- http://example.com/article5http://example.com/article5Mon, 28 May 2012 04:00:00 GMT
';
var result = feed.xml();
- test.equal(result.length, expectedResult.length);
- test.equal(result, expectedResult);
- test.done();
- },
+ expect(result).to.have.length(expectedResult.length);
+ expect(result).to.equal(expectedResult);
+ done();
+ });
- 'test with enclosure' : function(test) {
+ it('should work with an enclosure', function(done) {
var feed = new RSS({
title: 'title',
description: 'description',
@@ -178,9 +178,9 @@ module.exports = {
'';
var result = feed.xml();
- test.equal(result.length, expectedResult.length);
- test.equal(result, expectedResult);
- test.done();
- }
-};
+ expect(result).to.have.length(expectedResult.length);
+ expect(result).to.equal(expectedResult);
+ done();
+ });
+});