true 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1765574280f707dd23e99e32259fd5638bfb15de
4
- data.tar.gz: cadbeaf9375bc3588433f28d738b653b6f180fb7
3
+ metadata.gz: fd6cc4853271c5c85b0991afcdb45a63cf9af818
4
+ data.tar.gz: 463cddf82b9dbe01121277074f257377af2dd2da
5
5
  SHA512:
6
- metadata.gz: 2808ca9ddf9585413ac6ef95bdc6210b3886dbb3e50580fc8602eaee3b31df5b5f77589d3d8122695ecd7e7a657acb949a3b27f16fe73305328a63d265b9b93f
7
- data.tar.gz: 0a7ca6fbd4313a181807d2f340185e0cef115a7d69c2abff44d9c3b1deb7d94145083c70cb44db05e53d6b48f177cd05c361c60553f20bc23d261146f19be171
6
+ metadata.gz: de700ce77b7ddabe698e23def93433bce2096f9c0c44fbe740bdf883f11ab6c46cd040b199f2e8b914f56308278e02f6c3632f7ebf28a14234324aebd2e73ac4
7
+ data.tar.gz: ad30953383bc554625fce61bda64eaf9355486fb8afe018a42d26682ee3947250d2e121c2f1d0ce100b4c16d4321531e271d18bcd7619fd7f82c58c756332d69
@@ -1,6 +1,12 @@
1
1
  True Changelog
2
2
  ==============
3
3
 
4
+ 2.2.2 (4/11/17)
5
+ ---------------
6
+ - `assert-true` returns false on empty strings and lists
7
+ - `assert-false` returns true on empty strings and lists
8
+ - Module/Test/Assertion stats are included in reports
9
+
4
10
 
5
11
  2.2.1 (2/7/17)
6
12
  --------------
data/README.md CHANGED
@@ -181,3 +181,146 @@ toggles output to the terminal on or off.
181
181
  - `true` will show detailed information on failing assertions.
182
182
  This is the default, and best for using `true-cli`.
183
183
  - `false` to turn off all terminal output.
184
+
185
+ ## API
186
+
187
+ ### Tests
188
+
189
+ Tests help define what we are testing for. They can be used individually or
190
+ grouped as a test module.
191
+
192
+ #### `@include test-module()`
193
+
194
+ Defines a test module. Allows the grouping of several common purposed tests.
195
+
196
+ - `@param` {`String`} `$description` [''] - Module description
197
+
198
+ ```scss
199
+ @include test-module('Description of the module being tested') {
200
+ // Your tests here
201
+ }
202
+ ```
203
+
204
+ #### `@include test()`
205
+
206
+ Defines a test. Allows the definition of a single test for your module.
207
+
208
+ - `@param` {`String`} `$description` [''] - Test description
209
+
210
+ ```scss
211
+ @include test-module('My test module description') {
212
+ @include test('Your test description') {
213
+ // Your asserts go here.
214
+ }
215
+ }
216
+ ```
217
+
218
+ ### Asserts
219
+
220
+ Asserts help define what we are testing for. A test must contain at least one
221
+ assert but can have as many as necessary based on your testing needs.
222
+
223
+ #### `@include assert()`
224
+
225
+ Defines a single assert for a CSS output. It's used together with the
226
+ `output()` and `expect()` mixins to compare a mixin with it's expected output.
227
+
228
+
229
+ ```scss
230
+ @include test('Your test description') {
231
+ @include assert('Your assert description') {
232
+ @include output {
233
+ // Mixin to be evaluated
234
+ @include the-mixin-to-be-tested();
235
+ }
236
+
237
+ @include expect {
238
+ // The expected output of the-mixin-to-be-tested()
239
+ ...
240
+ }
241
+ }
242
+ }
243
+ ```
244
+
245
+
246
+ #### `@include assert-false()`
247
+
248
+ Asserts that the output of a test is falsy. This includes `false`, `null`,
249
+ `''` (empty string) and `()` (empty list).
250
+
251
+ - `@param` {`*`} `$assert` - Assert to be tested
252
+ - `@param` {`String`} `$description` [''] - Assert description
253
+
254
+ ```scss
255
+ @include test('Your test description') {
256
+ $test: sample-function(5);
257
+
258
+ @include assert-false($test, 'Your assert description');
259
+ }
260
+ ```
261
+
262
+
263
+ #### `@include assert-true()`
264
+
265
+ Asserts that the output of a test is not falsy. The test will pass as long as
266
+ the assert returns something.
267
+
268
+ - `@param` {`*`} `$assert` - Assert to be tested
269
+ - `@param` {`String`} `$description` [''] - Assert description
270
+
271
+ ```scss
272
+ @include test('Your test description') {
273
+ $test: sample-function(5);
274
+
275
+ @include assert-true($test, 'Your assert description');
276
+ }
277
+ ```
278
+
279
+
280
+ #### `@include assert-equal()`
281
+
282
+ Asserts that two parameters are equal.
283
+
284
+ - `@param` {`*`} `$assert` - Assert to be tested
285
+ - `@param` {`*`} `$expected` - Expected result
286
+ - `@param` {`String`} `$description` [''] - Assert description
287
+
288
+ ```scss
289
+ @include test('Your test description') {
290
+ $test: sample-function(5);
291
+
292
+ @include assert-equals($test, 10, 'Your assert description');
293
+ }
294
+ ```
295
+
296
+
297
+ #### `@include assert-unequal()`
298
+
299
+ Asserts that two parameters are unequal.
300
+
301
+ - `@param` {`*`} `$assert` - Assert to be tested
302
+ - `@param` {`*`} `$expected` - Expected result
303
+ - `@param` {`String`} `$description` [''] - Assert description
304
+
305
+ ```scss
306
+ @include test('Your test description') {
307
+ $test: sample-function(5);
308
+
309
+ @include assert-unequal($test, 10, 'Your assert description');
310
+ }
311
+ ```
312
+
313
+ ### Summary
314
+
315
+ Reports show a summary of total, passed, failed, and output to CSS tests. The summary can be output into CSS and/or onto the terminal. If you use Mocha, reporting to the command line is automatic. If you use true-cli, `@include report(terminal)` is required at the end of your main test file for output.
316
+
317
+ #### `@include report()`
318
+
319
+ Reports summary and stats data into CSS and/or onto the terminal.
320
+
321
+ - `@param` {`Bool`} `$terminal` [`true`] - Optionally output results to the terminal
322
+ - `@param` {`Bool`} `$fail-on-error` [`false`] - Optionally error out the compiler if tests have failed
323
+
324
+ ```scss
325
+ @include report();
326
+ ```
@@ -59,8 +59,9 @@ output = with_captured_stdout do
59
59
  end
60
60
  end
61
61
 
62
+ matches = output.match(%r{(?<tests>\d+) Tests?, (?<passed>\d+) Passed, (?<failed>\d+) Failed})
63
+ stats_matches = output.match(%r{(?<modules>\d+) Modules?, (?<tests>\d+) Tests?, (?<assertions>\d+) Assertions?})
62
64
 
63
- matches = output.match(%r{(?<tests>\d+) Tests, (?<passed>\d+) Passed, (?<failed>\d+) Failed})
64
65
  if matches.nil? # return sass errors
65
66
  puts output
66
67
  exit(2)
@@ -68,10 +69,15 @@ end
68
69
 
69
70
  if matches[:failed] == '0'
70
71
  if options['color']
71
- noun = matches[:tests].to_i == 1 ? 'Test' : 'Tests'
72
- puts COLORS[:ok] + "#{matches[:tests]} #{noun}, #{matches[:passed]} Passed, #{matches[:failed]} Failed" + COLORS[:end] unless options['silent']
72
+ unless options['silent']
73
+ puts COLORS[:ok] + matches.to_s + COLORS[:end]
74
+ puts COLORS[:ok] + stats_matches.to_s + COLORS[:end]
75
+ end
73
76
  else
74
- puts output unless options['silent']
77
+ unless options['silent']
78
+ puts matches
79
+ puts stats_matches
80
+ end
75
81
  end
76
82
  exit(0)
77
83
  else
@@ -5,7 +5,7 @@
5
5
 
6
6
  // Assert True
7
7
  // -----------
8
- /// Assert that a parameter is `true`
8
+ /// Assert that a parameter is truey (anything not falsey)
9
9
  /// @access public
10
10
  /// @group testing
11
11
  /// @param {*} $assert - Assert
@@ -15,15 +15,21 @@
15
15
  $description: null
16
16
  ) {
17
17
  $default: '"#{inspect($assert)}" should be truthy';
18
+ $truey-assert: if(
19
+ not not $assert and
20
+ $assert != '' and
21
+ $assert != (),
22
+ true,
23
+ false);
18
24
  @include _true-context('assert', $description or $default);
19
- @include _true-assert-results('assert-true', not not $assert, true);
25
+ @include _true-assert-results('assert-true', $truey-assert, true);
20
26
  }
21
27
 
22
28
 
23
29
 
24
30
  // Assert False
25
31
  // ------------
26
- /// Assert that a parameter is `false`
32
+ /// Assert that a parameter is falsey (false, null, empty stirng or empty list)
27
33
  /// @access public
28
34
  /// @group testing
29
35
  /// @param {*} $assert -
@@ -35,8 +41,14 @@
35
41
  $description: null
36
42
  ) {
37
43
  $default: '"#{inspect($assert)}" should be falsey';
44
+ $falsey-assert: if(
45
+ not $assert or
46
+ $assert == '' or
47
+ $assert == (),
48
+ true,
49
+ false);
38
50
  @include _true-context('assert', $description or $default);
39
- @include _true-assert-results('assert-false', not $assert, true);
51
+ @include _true-assert-results('assert-false', $falsey-assert, true);
40
52
  }
41
53
 
42
54
 
@@ -105,6 +117,7 @@
105
117
  @content;
106
118
 
107
119
  @include _true-update-test('output-to-css');
120
+ @include _true-update-stats-count('assertions');
108
121
  @include _true-context-pop();
109
122
  @include _true-message(' END_ASSERT ', 'comments');
110
123
  }
@@ -211,5 +224,6 @@
211
224
  }
212
225
 
213
226
  @include _true-update-test($result);
227
+ @include _true-update-stats-count('assertions');
214
228
  @include _true-context-pop();
215
229
  }
@@ -49,6 +49,7 @@
49
49
  /// Module stop helper
50
50
  /// @access private
51
51
  @mixin _true-module-stop {
52
+ @include _true-update-stats-count('modules');
52
53
  @include _true-context-pop();
53
54
  @include _true-message('', 'comments');
54
55
  }
@@ -11,12 +11,13 @@
11
11
  /// @param {Bool} $terminal [$true-terminal-output] -
12
12
  /// Optionally output results to the terminal
13
13
  /// @param {Bool} $fail-on-error [false] -
14
- /// Optionally error out of the compiler if tests have failed
14
+ /// Optionally error out the compiler if tests have failed
15
15
  @mixin report(
16
16
  $terminal: $true-terminal-output,
17
17
  $fail-on-error: false
18
18
  ) {
19
19
  $message: _true-report-message('global', 'multiple');
20
+ $stats-message: _true-stats-message($_true-stats-count, 'multiple');
20
21
 
21
22
  $fail: map-get($_true-results, 'fail');
22
23
  @if $fail-on-error and ($fail > 0) {
@@ -25,12 +26,17 @@
25
26
 
26
27
  @include _true-message('# SUMMARY ----------', 'comments');
27
28
  @include _true-message($message, 'comments');
29
+ @include _true-message($stats-message, 'comments');
28
30
  @include _true-message('--------------------', 'comments');
29
31
 
30
32
  @if $terminal {
31
33
  $message: _true-report-message('global', 'single');
32
34
  @include _true-message($message, 'debug');
35
+
36
+ $stats-message: _true-stats-message($_true-stats-count, 'single');
37
+ @include _true-message($stats-message, 'debug');
33
38
  }
39
+
34
40
  }
35
41
 
36
42
 
@@ -95,7 +101,8 @@ $_true-test-result: null;
95
101
  /// Report message
96
102
  /// @access private
97
103
  /// @param {String} $scope [test] - Scope
98
- /// @param {String} $lines [single] - Lines
104
+ /// @param {String} $lines [single] -
105
+ /// Return message either as a single line or in multiple lines
99
106
  /// @return {String} - Reported message
100
107
  @function _true-report-message(
101
108
  $scope: 'test',
@@ -110,9 +117,9 @@ $_true-test-result: null;
110
117
  $message: null;
111
118
 
112
119
  @if $scope == 'global' or $scope == 'module' {
113
- $items: 'Tests';
120
+ $items: if($run == 1, 'Test', 'Tests');
114
121
  } @else if $scope == 'test' {
115
- $items: 'Assertions';
122
+ $items: if($run == 1, 'Assertion', 'Assertions');
116
123
  }
117
124
 
118
125
  @if $lines == 'single' {
@@ -125,3 +132,59 @@ $_true-test-result: null;
125
132
 
126
133
  @return $message;
127
134
  }
135
+
136
+ // Stats Count
137
+ // -----------
138
+ /// Global stats count of how many modules, tests, and assertions are found
139
+ /// @access private
140
+ /// @type Map<String: Number>
141
+ $_true-stats-count: (
142
+ 'modules': 0,
143
+ 'tests': 0,
144
+ 'assertions': 0
145
+ );
146
+
147
+
148
+
149
+ // Update stats count
150
+ // ------------------
151
+ /// Add to a stats count type count by 1
152
+ /// @param {String} $type - The stats type to add to
153
+ /// @access private
154
+ @mixin _true-update-stats-count($type) {
155
+ $_true-stats-count: _true-map-increment($_true-stats-count, ($type: 1)) !global;
156
+ }
157
+
158
+
159
+
160
+ // Stats Message
161
+ // -------------
162
+ /// Stats message
163
+ /// @access private
164
+ /// @param {Map<String: Number>} $stats [$_true-stats-count] -
165
+ /// Map that contains the stats counts for modules, tests, and assertions found
166
+ /// @param {String} $lines [single] -
167
+ /// Return message either as a single line or in multiple lines
168
+ /// @return {String} - Stats count message
169
+ @function _true-stats-message(
170
+ $stats: $_true-stats-count,
171
+ $lines: 'single'
172
+ ) {
173
+ $message: null;
174
+
175
+ $modules: map-get($stats, 'modules');
176
+ $tests: map-get($stats, 'tests');
177
+ $assertions: map-get($stats, 'assertions');
178
+
179
+ $modules-label: if($modules == 1, 'Module', 'Modules');
180
+ $tests-label: if($tests == 1, 'Test', 'Tests');
181
+ $assertions-label: if($assertions == 1, 'Assertion', 'Assertions');
182
+
183
+ @if $lines == 'single' {
184
+ $message: '#{$modules} #{$modules-label}, #{$tests} #{$tests-label}, #{$assertions} #{$assertions-label}';
185
+ } @else {
186
+ $message: 'Stats: #{$_tnl} - #{$modules} #{$modules-label} #{$_tnl} - #{$tests} #{$tests-label} #{$_tnl} - #{$assertions} #{$assertions-label}';
187
+ }
188
+
189
+ @return $message;
190
+ }
@@ -40,6 +40,7 @@
40
40
  /// @access private
41
41
  @mixin _true-test-stop {
42
42
  @include _true-update($_true-test-result);
43
+ @include _true-update-stats-count('tests');
43
44
  @include _true-context-pop();
44
45
  @include _true-message('', 'comments');
45
46
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: 'true'
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miriam Eric Suzanne
@@ -16,14 +16,14 @@ dependencies:
16
16
  name: sass
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ~>
19
+ - - "~>"
20
20
  - !ruby/object:Gem::Version
21
21
  version: '3.4'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ~>
26
+ - - "~>"
27
27
  - !ruby/object:Gem::Version
28
28
  version: '3.4'
29
29
  description: Unit tests for maintaining test-driven Sass libraries.
@@ -40,6 +40,11 @@ extra_rdoc_files:
40
40
  - README.md
41
41
  - lib/true.rb
42
42
  files:
43
+ - CHANGELOG.md
44
+ - LICENSE.txt
45
+ - README.md
46
+ - VERSION
47
+ - bin/true-cli
43
48
  - lib/compass-true.rb
44
49
  - lib/main.js
45
50
  - lib/true.rb
@@ -52,37 +57,32 @@ files:
52
57
  - sass/true/_settings.scss
53
58
  - sass/true/_tests.scss
54
59
  - sass/true/_utilities.scss
55
- - CHANGELOG.md
56
- - LICENSE.txt
57
- - README.md
58
- - VERSION
59
- - bin/true-cli
60
60
  homepage: http://oddbird.net/true
61
61
  licenses: []
62
62
  metadata: {}
63
63
  post_install_message:
64
64
  rdoc_options:
65
- - --line-numbers
66
- - --inline-source
67
- - --title
65
+ - "--line-numbers"
66
+ - "--inline-source"
67
+ - "--title"
68
68
  - 'true'
69
- - --main
69
+ - "--main"
70
70
  - README.md
71
71
  require_paths:
72
72
  - lib
73
73
  required_ruby_version: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - '>='
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.2'
83
83
  requirements: []
84
84
  rubyforge_project: 'true'
85
- rubygems_version: 2.1.10
85
+ rubygems_version: 2.6.10
86
86
  signing_key:
87
87
  specification_version: 3
88
88
  summary: Testing framework for Sass libraries.