Skip to content
jejacks0n edited this page Dec 29, 2012 · 9 revisions

To get setup for QUnit you'll need to configure your suites. Since QUnit tests aren't considered specs, we need to adjust the path to point to test/javascripts. You should make a test/javascripts path and then change your suite(s).

config/initializers/teabag.rb

Teabag.setup do |config|

  config.suite do |suite|
    suite.matcher = "test/javascripts/**/*_test.{js,js.coffee,coffee}"
    suite.javascripts = ["teabag/qunit"]
    suite.helper = "test_helper"
  end

end

You'll have to do this for all the suites where you want to use QUnit.

Example Test

//= require jquery
module("My great feature");

test("will change the world", 2, function() {
  ok(true, "Passing is true");
  ok(typeof(jQuery) !== "undefined");
});

Example Fixture Usage

fixture.preload("fixture.html", "fixture.json") # make the actual requests for the files
module "Using fixtures",
  setup: ->
    fixture.set("<h2>Another Title</h2>") # create some markup manually
    @fixtures = fixture.load("fixture.html", "fixture.json", true) # append these fixtures

test "loads fixtures", ->
  ok(document.getElementById("fixture_view").tagName == "DIV", "is in the dom")
  ok(@fixtures[0] == fixture.el, "has return values for the el") # the element is available as a return value and through fixture.el
  ok(@fixtures[1].title == fixture.json[0].title, "has return values for json") # the json for json fixtures is returned, and available in fixture.json