Permalink
Browse files

I've removed withThis and made the 'DSL' style more strict by using a…

… function to pass the DSL methods
  • Loading branch information...
1 parent 9c7be59 commit 269c19c9196e2146d7a82958d435c1ab2933abb6 Alex Young committed Oct 21, 2009
Showing with 12 additions and 6 deletions.
  1. +11 −5 riot.js
  2. +1 −1 test.js
View
16 riot.js
@@ -34,7 +34,7 @@ var Riot = {
runAllContexts: function(tests) {
if (typeof tests !== 'undefined') {
- this.withThis(Riot, tests)();
+ this.withDSL(tests)();
}
for (var i = 0; i < this.contexts.length; i++) {
@@ -46,8 +46,15 @@ var Riot = {
return fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
},
- withThis: function(that, fn) {
- return function() { eval('with (that) {\n' + Riot.functionBody(fn) + '\n}\n'); };
+ withDSL: function(fn, context) {
+ var body = this.functionBody(fn);
+ body = "(function(context, given, asserts, should, setup, teardown) { " + body + " })";
+ return function() { eval(body)(Riot.context,
+ Riot.given,
+ function() { return context.asserts.apply(context, arguments); },
+ function() { return context.should.apply(context, arguments); },
+ function() { return context.setup.apply(context, arguments); },
+ function() { return context.teardown.apply(context, arguments); }) };
},
context: function(title, callback) {
@@ -197,7 +204,6 @@ Riot.Context = function(name, callback) {
this.callback = callback;
this.assertions = [];
this.should = this.asserts;
- this.given = Riot.given;
};
Riot.Context.prototype = {
@@ -229,7 +235,7 @@ Riot.Context.prototype = {
run: function() {
Riot.formatter.context(this.name);
- Riot.withThis(this, this.callback)();
+ Riot.withDSL(this.callback, this)();
this.runSetup();
for (var i = 0; i < this.assertions.length; i++) {
var pass = false,
View
@@ -42,7 +42,7 @@ Riot.run(function() {
});
});
- given('1.2 yet another context', function() {
+ context('1.2 yet another context', function() {
asserts('equals should compare strings as expected', 'test string').equals('test string');
});

0 comments on commit 269c19c

Please sign in to comment.