Skip to content

Commit

Permalink
wip.
Browse files Browse the repository at this point in the history
  • Loading branch information
sakari committed Mar 31, 2012
1 parent 7dfb8e7 commit 26f500d
Showing 1 changed file with 70 additions and 38 deletions.
108 changes: 70 additions & 38 deletions spec/javascripts/test/jasmine.js
Expand Up @@ -14,26 +14,29 @@ describe('qc.jasmine', function() {
function given_suite_with(fn) {
_suite = _env.describe('suite', function() { fn(_env); } );
}
function given_a_property(description, generator, pred) {
given_suite_with(function(env) {
if (pred)
return env.property(description, generator, pred);
return env.property(description, generator);
});
}
it('passes on holding properties', function() {
given_suite_with(function(env){
env.property('property that holds', qc.gen.integer,
function(i) {
this.expect(_.isNumber(i)).toEqual(true);
});
});
given_a_property('property that holds', qc.gen.integer,
function(i) {
this.expect(_.isNumber(i)).toEqual(true);
});
when_suite_has_been_run(function(suite) {
expect(suite.results().passedCount).toEqual(1);
expect(suite.results().totalCount).toEqual(1);
});
});

it('fails when property does not hold', function(i) {
given_suite_with(function(env) {
env.property('property that fails with some value', qc.gen.integer,
function(i) {
this.expect(i).toBeLessThan(5);
});
});
given_a_property('property that fails with some value', qc.gen.integer,
function(i) {
this.expect(i).toBeLessThan(5);
});
when_suite_has_been_run(function(suite) {
expect(suite.results().failedCount).toEqual(1);
expect(suite.results().totalCount).toEqual(1);
Expand Down Expand Up @@ -94,56 +97,85 @@ describe('qc.jasmine', function() {
});
it('runs property many times', function() {
var tries = 0;
given_suite_with(function(env) {
env.property('prop', qc.gen.integer,
function(i) {
tries++;
});
given_a_property('prop', qc.gen.integer,
function(i) {
tries++;
});
when_suite_has_been_run(function() {
when_suite_has_been_run(function() {
expect(tries).toBeGreaterThan(1);
});
});

it('fails if some tests fail', function() {
given_suite_with(function(env) {
env.property('prop', qc.gen.integer,
function(i) {
this.expect(i).toBeLessThan(10);
});
given_a_property('prop', qc.gen.integer,
function(i) {
this.expect(i).toBeLessThan(10);
});
when_suite_has_been_run(function(suite) {
when_suite_has_been_run(function(suite) {
expect(suite.results().failedCount).toEqual(1);
});
});

it('shrinks to the minimal failing value', function() {
given_suite_with(function(env) {
env.property('prop', qc.gen.integer,
function(i) {
this.expect(i).toBeLessThan(10);
});
given_a_property('prop', qc.gen.integer,
function(i) {
this.expect(i).toBeLessThan(10);
});
when_suite_has_been_run(function(suite) {
when_suite_has_been_run(function(suite) {
expect(suite.results().getItems()[0].getItems()[1].values)
.toEqual(['10']);
});
});

it('logs the last failing value', function() {
var last_failing_value;
given_suite_with(function(env) {
env.property('prop', qc.gen.integer,
function(i) {
if (i >= 10)
last_failing_value = i;
this.expect(i).toBeLessThan(10);
});
given_a_property('prop', qc.gen.integer,
function(i) {
if (i >= 10)
last_failing_value = i;
this.expect(i).toBeLessThan(10);
});
when_suite_has_been_run(function(suite) {
when_suite_has_been_run(function(suite) {
expect(suite.results().getItems()[0].getItems()[1].values)
.toEqual([last_failing_value + '']);
});
});

describe('waiting for async events', function() {
it('works with jasmine async tests', function() {
var ticks = 0;
given_a_property('prop', function() {
var tick;
setTimeout(function() { tick = true; }, 1);
this.waitsFor(function() { return tick; });
this.runs(function() {
this.expect(tick).toBeTruthy();
ticks++;
});
});
when_suite_has_been_run(function() {
expect(ticks).toBeGreaterThan(1);
});
});
describe('randomized async testing', function() {
it('waits until a condition holds', function() {
var tick;
given_a_property('prop', function() {
this.qc.event(function() {
tick = true;
});
this.qc.waitsFor(function() {
return tick;
});
this.expect(tick).toBeTruthy();
});
when_suite_has_been_run(function() {
expect(tick).toBeTruthy();
});
});
});

});

describe('classify', function() {
it('logs the classification results', function() {
Expand Down

0 comments on commit 26f500d

Please sign in to comment.