       throw new Error 'expected the test to fail with "' + failureText + '" in the failures, but it passed'
     done()
 
+sampleHtml = '<!doctype html>
+  <html>
+    <head>
+      <title>mocha-casperjs tests</title>
+    </head>
+  <body>
+    <h1>Hello World!</h1>
+    <article></article>
+  </body>
+  </html>'
+
 describe 'Mocha Runnable shim', ->
   server = null
-  port = 10473
   before ->
     server = require('http').createServer (req, res) ->
       echoStatus = req.url?.match(/echo\/(\d+)/)
       if echoStatus?[1]
         res.statusCode = echoStatus[1]
         res.end()
-    server.listen port
+      if req.url is '/sample'
+        res.writeHead '200', 
+          'Content-Type': 'text/html'
+        res.end sampleHtml
+    server.listen 10473
   
   it 'should flush all the steps at the end of a test', (done) ->
     thisShouldPass


  it 'should fail when waitFor times out', (done) ->
    thisShouldFailWith
      before: ->
        casper.start 'http://bing.com'
      test: ->
        casper.waitForSelector 'h1.nonexistant', ->
          throw new Error 'we found it?!?'
        casper.then -> throw new Error 'this shouldnt get here'
    , 'timeout', done

  after -> server.close()


      encoding: 'utf8'
    , (err, template) ->
      throw err if err
      testContents = util.format template, test.reporter or 'spec', test.before or (-> casper.start('http://localhost:10473/sample')), test.test, test.after or (->)
      fs.writeFile testfile, testContents, (err) -> throw err if err

  process = spawn('casperjs', [testfile])
