Example Test Suite

James Kyle edited this page Nov 16, 2013 · 5 revisions

Example Test Suite

The following is a valid Bootcamp Test Suite for a power function. It should serve as an example of a typical test suite.

functions/math

@function power($base, $exponent) {
  $result: 1;

  @if $exponent >= 0 {
    @for $i from 1 through $exponent {
      $result: $result * $base;
    }
  } @else {
    @for $i from $exponent to 0 {
      $result: $result / $base;
    }
  }

  @return $result;
}

specs/math.scss

@include describe("Math Power") {
  @include it("should expect positive values to be calculated correctly") {
    @include should( expect( power( 10, 2) ), to( equal(  100 )));
    @include should( expect( power(  2, 2) ), to( equal(    4 )));
    @include should( expect( power(0.5, 2) ), to( equal( 0.25 )));
  }

  @include it("should expect negative values to be calculated correctly") {
    @include should( expect( power( 10, -2) ), to( equal( 0.01 )));
    @include should( expect( power(  2, -2) ), to( equal( 0.25 )));
    @include should( expect( power(0.5, -2) ), to( equal(    4 )));
  }
}

specs.scss

@import "functions/math";

@import "bootcamp";
$bc-setting-verbose:  false;
$bc-setting-warnings: false;

@include runner-start;
@import "specs/math";
@include runner-end;

Expected Results

✔ ✔
2 Tests, 6 assertions, 0 failures, 0 skipped