true 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,9 +1,14 @@
1
1
  True Changelog
2
2
  ==============
3
3
 
4
+ 0.1.3 (6/7/13)
5
+ --------------
6
+ - Nest assertions within `test() {}` named tests.
7
+ - Cleaner css output.
8
+
4
9
  0.1.2 (6/7/13)
5
10
  --------------
6
- - Use nesting for modules with `test-module()`
11
+ - Use nesting for modules with `test-module() {}`
7
12
  - Added failure message argument to all assertions.
8
13
 
9
14
  0.1.1 (6/6/13)
data/README.md CHANGED
@@ -3,6 +3,11 @@ True
3
3
 
4
4
  A testing framework for compass/sass libraries.
5
5
 
6
+ At this point,
7
+ True is better at testing functions than mixins -
8
+ because it is easier to test a value
9
+ than the actual property-value css output.
10
+
6
11
  Install
7
12
  -------
8
13
 
@@ -25,8 +30,8 @@ in your scss:
25
30
  // Track and report results in a test module
26
31
  @include test-module('My Tests') {
27
32
 
28
- // silent classes can help you organize tests and scope variables.
29
- %test__feature-1 {
33
+ // Add tests
34
+ @include test('Feature A does The Things') {
30
35
  $test-1: 3*5;
31
36
  $test-2: if(something, true, false);
32
37
 
@@ -35,6 +40,7 @@ in your scss:
35
40
  'Simple multiplication failed.');
36
41
 
37
42
  // You can assert-equal, assert-unequal, assert-true, or assert-false.
43
+ // A test can include as many assertions as you need.
38
44
  @include assert-true($test-2,
39
45
  'Something returned false.');
40
46
  }
@@ -42,6 +48,5 @@ in your scss:
42
48
  }
43
49
  ```
44
50
 
45
- **true** will report test results
46
- both in the command line
47
- and in the output css file.
51
+ **True** will report detailed results in the terminal,
52
+ and a summary of results in the output css.
data/sass/_true.scss CHANGED
@@ -1,6 +1,8 @@
1
1
  // Susy partials
2
2
  // =============
3
3
 
4
- @import "true/modules";
5
4
  @import "true/messages";
5
+ @import "true/results";
6
+ @import "true/modules";
7
+ @import "true/tests";
6
8
  @import "true/assert";
@@ -1,19 +1,15 @@
1
- // Pass / Fail Messages
2
- // ====================
1
+ // Messages
2
+ // ========
3
3
 
4
- $test-pass-message : '.' !default;
5
- $test-fail-message : 'F' !default;
6
-
7
- @mixin pass(
8
- $pass: $test-pass-message
9
- ) {
10
- $test-results: append($test-results, 'p');
11
- @debug $pass;
12
- }
13
-
14
- @mixin fail(
15
- $fail: $test-fail-message
4
+ @mixin result-message(
5
+ $message,
6
+ $output
16
7
  ) {
17
- $test-results: append($test-results, 'f');
18
- @warn $fail;
8
+ @if index($output, css) {
9
+ /* #{$message} */
10
+ } @else if index($output, debug) or index($output, terminal) {
11
+ @debug $message;
12
+ } @else if index($output, warn) {
13
+ @warn $message;
14
+ }
19
15
  }
@@ -1,47 +1,40 @@
1
1
  // Test Modules
2
2
  // ============
3
3
 
4
- $test-output: terminal css !default;
5
-
6
- $module-name: null;
7
- $test-results: null;
8
-
9
- // Collate test results
10
- @function collate-results(
11
- $results
12
- ) {
13
- $total: length($results);
14
- $pass: 0;
15
- $fail: 0;
16
-
17
- @each $test in $results {
18
- @if $test == 'p' { $pass: $pass + 1; }
19
- @if $test == 'f' { $fail: $fail + 1; }
20
- }
21
-
22
- @return $total $pass $fail;
23
- }
4
+ $test-module-results : null;
24
5
 
25
6
  // Establish a new test module
26
7
  @mixin test-module(
27
- $name,
28
- $output: $test-output
8
+ $name
29
9
  ) {
30
- $module-name: $name;
31
- $test-results: compact();
10
+ // Setup
11
+ $test-result-context: module;
12
+ $test-module-results: compact();
13
+
14
+ @include result-message('
15
+
16
+ ### #{$name} ------', css);
32
17
 
18
+ // Content
33
19
  @content;
34
20
 
35
- $results: collate-results($test-results);
21
+ // Results
22
+ $results: collate-results($test-module-results);
36
23
  $total: nth($results, 1);
37
24
  $pass: nth($results, 2);
38
25
  $fail: nth($results, 3);
39
26
 
40
- $result-message: '#{$name}: Passed #{$pass} of #{$total} (#{$fail} tests failed)';
27
+ $debug-message: '#{$name}: #{$total} Tests, #{$pass} Passed, #{$fail} failed';
28
+ @include result-message($debug-message, debug);
41
29
 
42
- @if index($output, css) { /* #{$result-message} */ }
43
- @if index($output, terminal) { @debug $result-message; }
30
+ $css-message: '
31
+ Summary:
32
+ - #{$total} Tests
33
+ - #{$pass} Passed
34
+ - #{$fail} Failed';
35
+ @include result-message($css-message, css);
44
36
 
45
- $module-name: null;
46
- $test-results: null;
37
+ // Teardown
38
+ $test-result-context: null;
39
+ $test-module-results: null;
47
40
  }
@@ -0,0 +1,66 @@
1
+ // Results
2
+ // =======
3
+
4
+ $test-result-context: null;
5
+
6
+ $pass-marker : p;
7
+ $fail-marker : f;
8
+
9
+ // Collate test results
10
+ @function collate-results(
11
+ $results
12
+ ) {
13
+ $total: length($results);
14
+ $pass: 0;
15
+ $fail: 0;
16
+
17
+ @each $test in $results {
18
+ @if $test == $pass-marker { $pass: $pass + 1; }
19
+ @if $test == $fail-marker { $fail: $fail + 1; }
20
+ }
21
+
22
+ @return $total $pass $fail;
23
+ }
24
+
25
+ // Record the results
26
+ @mixin record-result(
27
+ $result,
28
+ $context: $test-result-context
29
+ ) {
30
+ $marker: null;
31
+
32
+ @if $result == 'pass' {
33
+ $marker: $pass-marker;
34
+ } @else if $result == 'fail' {
35
+ $marker: $fail-marker;
36
+ }
37
+
38
+ // record results
39
+ @if $context == 'test' {
40
+ $test-results: append($test-results, $marker);
41
+ } @else if $context == 'module' {
42
+ $test-module-results: append($test-module-results, $marker);
43
+ }
44
+ }
45
+
46
+ // Pass / Fail
47
+ // -----------
48
+
49
+ $test-pass-message : '.' !default;
50
+ $test-fail-message : 'F' !default;
51
+
52
+ @mixin pass(
53
+ $pass: $test-pass-message,
54
+ $context: $test-result-context
55
+ ) {
56
+ @include record-result(pass, $context);
57
+ @include result-message($pass, debug);
58
+ }
59
+
60
+ @mixin fail(
61
+ $fail: $test-fail-message,
62
+ $context: $test-result-context
63
+ ) {
64
+ @include record-result(fail, $context);
65
+ @include result-message($fail, warn);
66
+ }
@@ -0,0 +1,51 @@
1
+ // Tests
2
+ // =====
3
+
4
+ $test-results: null;
5
+
6
+ // Establish a new test
7
+ @mixin test(
8
+ $name
9
+ ) {
10
+ // Setup
11
+ $test-results: compact();
12
+
13
+ // Content
14
+ $old-result-context: $test-result-context;
15
+ $test-result-context: test;
16
+
17
+ @content;
18
+
19
+ $test-result-context: $old-result-context;
20
+
21
+ // Results
22
+ @include report-test($name, $test-results, $test-result-context);
23
+
24
+ // Teardown
25
+ $test-results: null;
26
+ }
27
+
28
+ @mixin report-test(
29
+ $name,
30
+ $results,
31
+ $context
32
+ ) {
33
+ $results: collate-results($test-results);
34
+ $total: nth($results, 1);
35
+ $pass: nth($results, 2);
36
+ $fail: nth($results, 3);
37
+
38
+ $message: '#{$name} (#{$total} assertions, #{$pass} passed, #{$fail} failed)';
39
+
40
+ @if $fail > 0 {
41
+ $fail-message: '- FAIL: ' + $message;
42
+ @include fail($fail-message, module);
43
+ @include result-message('FAIL: ' + $message, css);
44
+ }
45
+ @else {
46
+ $pass-message: '- ' + $message;
47
+ @include pass($test-pass-message, module);
48
+ @include result-message($pass-message, css);
49
+ }
50
+
51
+ }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: "true"
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eric Meyer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-06-06 00:00:00 Z
18
+ date: 2013-06-07 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: compass
@@ -67,6 +67,8 @@ files:
67
67
  - sass/true/_assert.scss
68
68
  - sass/true/_messages.scss
69
69
  - sass/true/_modules.scss
70
+ - sass/true/_results.scss
71
+ - sass/true/_tests.scss
70
72
  - CHANGELOG.md
71
73
  - LICENSE.txt
72
74
  - README.md