Created
January 11, 2012 15:20
-
-
Save kozo002/1595151 to your computer and use it in GitHub Desktop.
Qunit using with Sinatra
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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