Skip to content

Instantly share code, notes, and snippets.

@kozo002
Created January 11, 2012 15:20
Show Gist options
  • Select an option

  • Save kozo002/1595151 to your computer and use it in GitHub Desktop.

Select an option

Save kozo002/1595151 to your computer and use it in GitHub Desktop.
Qunit using with Sinatra
require "rubygems"
require "sinatra/base"
require "erb"
class MyApp < Sinatra::Base
helpers do
def qunit(test_js, fixtures = nil)
result = '<link rel="stylesheet" href="/qunit/qunit.css" type="text/css" media="screen" /><script type="text/javascript" src="/qunit/qunit.js"></script>'
case test_js.class.name
when 'Array'
test_js.each do |path|
result += "<script type=\"text/javascript\" src=\"#{path}\"></script>"
end
when 'String'
result += "<script type=\"text/javascript\" src=\"#{test_js}\"></script>"
end
result += '<h1 id="qunit-header">QUnit Test Suite</h1><h2 id="qunit-banner"></h2><div id="qunit-testrunner-toolbar"></div><h2 id="qunit-userAgent"></h2><ol id="qunit-tests"></ol><div id="qunit-fixture">' + fixtures + '</div>'
result
end
end
get '/' do
erb :index
end
end
MyApp.run! :port => 9000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment