Last active
August 29, 2015 14:07
-
-
Save mirisuzanne/4300b78c14f118105348 to your computer and use it in GitHub Desktop.
Sass BDD syntax proposal
This file contains 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
// ---- | |
// Sass (v3.4.5) | |
// Compass (v1.0.1) | |
// ---- | |
// Sass BDD syntax proposal | |
// ======================== | |
// - based on [Jasmine](http://jasmine.github.io/2.0/introduction.html) | |
// - comparitor may be easier to parse with dashes e.g. "not-to-be" | |
// - simplest parsing would use commas as well e.g. "expect($foo, to equal, 1)" | |
// - describe/it/expect seems parallel to TDD module/test/assert | |
// - if so, True could impliment both syntaxes over the same logic | |
// Pseudo Code! | |
// ------------ | |
@mixin describe($desc){ | |
/* | |
/* #{$desc} */ | |
@content | |
} | |
@mixin it($desc){ | |
/* - #{$desc} */ | |
@content | |
} | |
@mixin expect($test){ | |
/* -- EXPECT: #{$test} */ | |
@content | |
} | |
// USAGE | |
// ----- | |
@include describe("A suite") { | |
@include it("contains spec with an expectation") { | |
@include expect(true to be true); | |
} | |
} | |
@include describe("The 'toBe' matcher compares with ===") { | |
@include it("and has a positive case") { | |
@include expect(true to be true); | |
} | |
@include it("and can have a negative case") { | |
@include expect(false not to be true); | |
} | |
} | |
@include describe("A spec") { | |
@include it("is just a function, so it can contain any code") { | |
$foo: 0; | |
$foo: $foo + 1; | |
@include expect($foo to equal 1); | |
} | |
@include it("can have more than one expectation") { | |
$foo: 0; | |
$foo: $foo + 1; | |
@include expect($foo to equal 1); | |
@include expect(true to equal true); | |
} | |
} |
This file contains 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
/* | |
/* A suite */ | |
/* - contains spec with an expectation */ | |
/* -- EXPECT: true to be true */ | |
/* | |
/* The 'toBe' matcher compares with === */ | |
/* - and has a positive case */ | |
/* -- EXPECT: true to be true */ | |
/* - and can have a negative case */ | |
/* -- EXPECT: false false be true */ | |
/* | |
/* A spec */ | |
/* - is just a function, so it can contain any code */ | |
/* -- EXPECT: 1 to equal 1 */ | |
/* - can have more than one expectation */ | |
/* -- EXPECT: 1 to equal 1 */ | |
/* -- EXPECT: true to equal true */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment