Opened 13 years ago

Closed 12 years ago

#8599 closed enhancement (duplicate)

Add "faux" rspec style testing for doh

Reported by: foobarfighter Owned by: alex
Priority: high Milestone: future
Component: TestFramework Version: 1.2.3
Keywords: doh Cc:
Blocked By: Blocking:


I can take on the work for the namespace changes (fix indentation, etc.) and the full on doh impl as long as somebody commits it for me. What is the best way to integrate this as I have no writes ;) to the dojo code?

Here is my implementation for d-rails. I would love to contribute this code to dojo.

Here is the original email that spawned the impl:

I've been working on d-rails some more and I'm trying to test drive some of the new functionality to ensure that I am still compatible with rails and prototype/scriptaculous (ugh). Anyway, I started out using standard doh methods and I had a really hard time with (hated :-) ) it mostly because I've recently come from rspec land ( which has a different syntax/style and IMHO has a more elegant approach to unit testing.

Here are my main gripes with testing in doh:

  1. Registering a bunch of tests within a single context using all object literals is error prone and ugly (it's usually a bitch to track down a comma). I'm assuming that there might be some way around this, but even the mere fact that I can't use spec style syntax bothers me too (albeit that's a personal taste issue).
  2. If you want to reuse setup and teardown methods for each test within a group, then you have to do that by pointing to some user defined customSetup and customTeardown method.
  3. There's no readily apparent way to nest test groups (and if there is then it's not in the book or I just can't read).

So I've come up with something that I liked, and I wanted to know if anybody was interested in the idea. In my implementation you still can't nest specs, but with some work and some revisions to the UI for doh runner you probably could.

Here is what my new tests/specs look like:

dojo.require("doh.runner"); dojo.require("drails.tests.ext");

This adds all special spec methods to the global namespace... less typing wheeeeeeee! Otherwise you have methods like doh.spec, doh.before, doh.after, doh.pollute();

doh.register under the hood. Builds up a spec/group spec("Some context for my test group", function() {

var thinger;

before(function(t) {

console.debug("setup each it with this function"); thinger = { baz: 'boo' }; console.debug(thinger.baz);


after(function(t) {

This passes because each 'it' is run in order., "thunk"); console.debug("teardown each it");


it adds a test to the spec/group it("this test passes and sets thinger.baz to show that thinger can be accessed from inside these 'it's", function(t){, 'boo'); thinger.baz = 'thunk';


it("fails here", function(t){"foo", "bar");






Last but not least, kudos to all who have worked on doh. It's a great tool, I just think it needs a little more love :-).

Change History (4)

comment:1 Changed 13 years ago by alex

Milestone: tbd1.3
Status: newassigned
Type: defectenhancement

comment:2 Changed 13 years ago by dante

Milestone: 1.31.4

comment:3 Changed 13 years ago by dante

Milestone: 1.4future

comment:4 Changed 12 years ago by bill

Resolution: duplicate
Status: assignedclosed

Superceded by #11063.

Note: See TracTickets for help on using tickets.