true 2.0.0.alpha.4 → 2.0.0.beta.1

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: 2e47d57acd1a657e398b93a6552f5b3c167fb866
4
- data.tar.gz: 2fc755c6ac44d775c55666bae450abb446e798a8
3
+ metadata.gz: 82b889e126441092c78fae0935640eddff42dd26
4
+ data.tar.gz: 5ced6822242622c9d5b2c535a020595c4e27af45
5
5
  SHA512:
6
- metadata.gz: b625764346d9b96172c3537fe473aca943fd80cb322b7be47eccba863785c4a6464b5554c9325f4fb5bcf29b17b18c083c6f9d42b8f5ca105a33a511d30bbe80
7
- data.tar.gz: e393a372934285e50f3c284f9fe2b966646d1bae3ab8becdfb0a8371e1417cb6fcb7230ace34554b352abbbe5703f554f6fdfd4775ce9cf2bb3059c7bed6624e
6
+ metadata.gz: 5a0aefdab1acf74ad6a17293014f084f626f16d858ea61fa6b54f67ba066889c0de896d0613907d8d1e6ef26d10e74a024b7d10b395fd0e0d07642f681d46e44
7
+ data.tar.gz: e170d9287c8043791a2936dd894aad9c7a3c3a1e6553e5fddb944de40df1535f1bbc0975dd704616c17dbae8d1958e18fb8d44de17817da761b7dc7ff4e83219
data/CHANGELOG.md CHANGED
@@ -5,8 +5,11 @@ True Changelog
5
5
  ----------------
6
6
  - Improve internal logic, and namespace private functions behind `_true-*`.
7
7
  - Add `assert()`, `input`, and `expect` mixins for testing CSS output.
8
- - Support for LibSass
8
+ - Support for LibSass.
9
+ - Add Mocha JS integration.
10
+ — Create NPM package.
9
11
  - Simplify output options down to single `$true-terminal-output` setting.
12
+ Defaults to `false` (required for libsass).
10
13
 
11
14
 
12
15
  1.0.1 (10/18/14)
data/README.md CHANGED
@@ -34,12 +34,15 @@ bower install true
34
34
  Command Line
35
35
  ------------
36
36
 
37
+ _This command-line tool uses Ruby
38
+ and the Ruby Sass compiler._
39
+
37
40
  ```bash
38
41
  true-cli [options] PATH
39
42
  ```
40
43
 
41
44
  Options:
42
- * `-s` slient
45
+ * `-s` silent
43
46
  * `-c` config file
44
47
  * `-d` debug config file settings
45
48
 
@@ -93,15 +96,12 @@ Usage
93
96
  Settings
94
97
  --------
95
98
 
96
- There is only one setting.
97
- `$true-terminal-output` controls what output (if any)
98
- is shown in the terminal.
99
- The default setting is `true`,
100
- which will show warnings in the terminal
101
- when an assertion fails.
102
- You can set it to `false` to turn off all terminal output,
103
- or `details` to show more `@debug` info on failures,
104
- and a final summary of the results.
105
-
106
- * LibSass doesn't support `@debug`.
107
- * The Ruby CLI requires the final summary output.
99
+ There is only one setting:
100
+ `$true-terminal-output`
101
+ toggles output to the terminal on and off.
102
+
103
+ - `true` will display a final summary of your test results in the terminal,
104
+ and show detailed information on failing assertions.
105
+ *Required for `true-cli`.*
106
+ - `false` to turn off all terminal output.
107
+ *Required for Libsass.*
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0.alpha.3
1
+ 2.0.0.beta.0
data/bin/true-cli CHANGED
@@ -8,7 +8,7 @@ COLORS = {
8
8
  :fail => "\033[91m",
9
9
  :end => "\033[0m"
10
10
  }
11
- options = {'debug' => false, 'slient' => false, 'color' => false}
11
+ options = {'debug' => false, 'silent' => false, 'color' => false}
12
12
  config_file = File.join(Dir.pwd, 'test', 'true.yml')
13
13
  OptionParser.new do |opts|
14
14
  opts.banner = "Usage: true-cli [options] file"
@@ -19,8 +19,8 @@ OptionParser.new do |opts|
19
19
  opts.on('-d', '--debug') do
20
20
  options['debug'] = true
21
21
  end
22
- opts.on('-s', '--slient') do
23
- options['slient'] = true
22
+ opts.on('-s', '--silent') do
23
+ options['silent'] = true
24
24
  end
25
25
  end.parse!(ARGV)
26
26
 
@@ -35,7 +35,7 @@ def with_captured_stdout
35
35
  end
36
36
  end
37
37
  if File.exists?(config_file)
38
- puts "Using config file: #{config_file}" unless options['slient']
38
+ puts "Using config file: #{config_file}" unless options['silent']
39
39
  config_options = YAML.load(File.read(config_file))
40
40
  options.merge!(config_options['options']) if config_options.has_key?('options')
41
41
  if options['debug']
@@ -68,16 +68,16 @@ end
68
68
  if matches[:failed] == '0'
69
69
  if options['color']
70
70
  noun = matches[:tests].to_i == 1 ? 'Test' : 'Tests'
71
- puts COLORS[:ok] + "#{matches[:tests]} #{noun}, #{matches[:passed]} Passed, #{matches[:failed]} Failed" + COLORS[:end] unless options['slient']
71
+ puts COLORS[:ok] + "#{matches[:tests]} #{noun}, #{matches[:passed]} Passed, #{matches[:failed]} Failed" + COLORS[:end] unless options['silent']
72
72
  else
73
- puts output unless options['slient']
73
+ puts output unless options['silent']
74
74
  end
75
75
  exit(0)
76
76
  else
77
77
  if options['color']
78
- puts COLORS[:fail] + output + COLORS[:end] unless options['slient']
78
+ puts COLORS[:fail] + output + COLORS[:end] unless options['silent']
79
79
  else
80
- puts output unless options['slient']
80
+ puts output unless options['silent']
81
81
  end
82
82
  exit(3)
83
83
  end
data/lib/main.js ADDED
@@ -0,0 +1,147 @@
1
+ var _ = require('underscore');
2
+ var parseCss = require('css').parse;
3
+ var sass = require('node-sass');
4
+ var CssSelectorParser = require('css-selector-parser').CssSelectorParser;
5
+ var selectorParser = new CssSelectorParser();
6
+
7
+
8
+ // @@@ maybe catch errors and display as warnings instead?
9
+
10
+
11
+ module.exports.runSass = function (options, describe, it) {
12
+ var assert = require('assert');
13
+ var css = sass.renderSync(options);
14
+ var modules = parse(css);
15
+
16
+ _.each(modules, function (module) {
17
+ describe(module.module, function () {
18
+ _.each(module.tests, function (test) {
19
+ it(test.test, function () {
20
+ _.each(test.assertions, function (assertion) {
21
+ if (!assertion.passed) {
22
+ var msg = (
23
+ assertion.description + ' ("' +
24
+ assertion.returned + '" ' +
25
+ assertion.assert + ' "' +
26
+ assertion.expected +
27
+ '")'
28
+ );
29
+ assert.fail(
30
+ assertion.returned,
31
+ assertion.expected,
32
+ msg,
33
+ assertion.assert
34
+ );
35
+ }
36
+ });
37
+ });
38
+ });
39
+ });
40
+ });
41
+ };
42
+
43
+ // parse True output CSS and return an array of test modules.
44
+ var parse = module.exports.parse = function (css) {
45
+ var modules = [];
46
+ var ast = parseCss(css);
47
+
48
+ _.each(_.where(ast.stylesheet.rules, {type: 'rule'}), function (rule) {
49
+ var decls = _.where(rule.declarations, {type: 'declaration'});
50
+ var declPairs = _.zip(
51
+ _.pluck(decls, 'property'),
52
+ _.pluck(decls, 'value')
53
+ );
54
+ var declInfo = _.object(declPairs);
55
+ var curAssertion, declString;
56
+ _.each(rule.selectors, function (sel) {
57
+ var selInfo = parseSelector(sel);
58
+ if (!selInfo) {
59
+ throw new Error("Can't understand selector: " + sel);
60
+ }
61
+ var curModule = _.findWhere(modules, {module: selInfo.module});
62
+ if (!curModule) {
63
+ curModule = {module: selInfo.module, tests: []};
64
+ modules.push(curModule);
65
+ }
66
+ var curTest = _.findWhere(curModule.tests, {test: selInfo.test});
67
+ if (!curTest) {
68
+ curTest = {test: selInfo.test, assertions: []};
69
+ curModule.tests.push(curTest);
70
+ }
71
+ if (selInfo.output) {
72
+ curAssertion = _.findWhere(
73
+ curTest.assertions, {description: selInfo.assert});
74
+ if (!curAssertion) {
75
+ curAssertion = {
76
+ description: selInfo.assert,
77
+ assert: 'equal',
78
+ };
79
+ curTest.assertions.push(curAssertion);
80
+ }
81
+ declString = _.map(declPairs, function (pair) {
82
+ return pair[0] + ': ' + pair[1] + ';';
83
+ }).join(' ');
84
+ if (selInfo.type === 'input') {
85
+ curAssertion.returned = declString;
86
+ } else { // if (selInfo.type == 'expect') {
87
+ curAssertion.expected = declString;
88
+ }
89
+ if (curAssertion.returned && curAssertion.expected) {
90
+ curAssertion.passed = curAssertion.returned === curAssertion.expected;
91
+ }
92
+ } else {
93
+ curAssertion = {
94
+ assert: selInfo.assert,
95
+ description: (declInfo['-description'] || '""').slice(1, -1),
96
+ passed: declInfo['-result'] === 'PASS',
97
+ };
98
+ _.each(_.pairs(declInfo), function (pair) {
99
+ if (_.contains(['-expected--', '-returned--'], pair[0].slice(0, 11))) {
100
+ var attr = pair[0].slice(1, 9);
101
+ var type = pair[0].slice(11);
102
+ var val = pair[1];
103
+ curAssertion[attr] = type + ': ' + val;
104
+ }
105
+ });
106
+ curTest.assertions.push(curAssertion);
107
+ }
108
+ });
109
+ });
110
+
111
+ return modules;
112
+ };
113
+
114
+
115
+ var parseSelector = module.exports.parseSelector = function (sel) {
116
+ var rule = selectorParser.parse(sel).rule;
117
+ var ret = {output: false};
118
+ var attrName = function (rule, name) {
119
+ return (rule &&
120
+ rule.attrs &&
121
+ rule.attrs.length == 1 &&
122
+ rule.attrs[0].name === name
123
+ );
124
+ };
125
+ if (attrName(rule, 'data-module')) {
126
+ ret.module = rule.attrs[0].value;
127
+ rule = rule.rule;
128
+ if (attrName(rule, 'data-test')) {
129
+ ret.test = rule.attrs[0].value;
130
+ rule = rule.rule;
131
+ if (attrName(rule, 'data-assert')) {
132
+ ret.output = true;
133
+ ret.assert = rule.attrs[0].value;
134
+ rule = rule.rule;
135
+ if (rule.classNames.length === 1 &&
136
+ _.contains(['input', 'expect'], rule.classNames[0])) {
137
+ ret.type = rule.classNames[0];
138
+ return ret;
139
+ }
140
+ } else if (rule.classNames.length === 1 &&
141
+ rule.classNames[0].slice(0, 7) === 'assert-') {
142
+ ret.assert = rule.classNames[0].slice(7);
143
+ return ret;
144
+ }
145
+ }
146
+ }
147
+ };
@@ -143,7 +143,7 @@
143
143
  -expected--#{$expected-type}: _true-inspect($expected);
144
144
  -returned--#{$returned-type}: _true-inspect($returned);
145
145
 
146
- @if $terminal == details {
146
+ @if $terminal {
147
147
  @debug '[FAIL] #{_true-context(test)} » #{_true-context(assert)}';
148
148
  @debug 'Expected #{$expected-type} »';
149
149
  @debug _true-inspect($expected);
@@ -151,7 +151,5 @@
151
151
  @debug _true-inspect($returned);
152
152
  }
153
153
 
154
- @if $terminal {
155
- @warn '#{_true-context(test)} » #{_true-context(assert)}';
156
- }
154
+ @warn '#{_true-context(test)} » #{_true-context(assert)}';
157
155
  }
@@ -143,7 +143,7 @@ $_true-results: (
143
143
  @include _true-message($message, comments);
144
144
  @include _true-message('--------------------', comments);
145
145
 
146
- @if $terminal == details {
146
+ @if $terminal {
147
147
  $message: _true-report-message(global, single);
148
148
  @include _true-message($message, debug);
149
149
  }
@@ -1,7 +1,7 @@
1
1
  // True Settings
2
2
  // =============
3
3
 
4
- $true-terminal-output: true !default;
4
+ $true-terminal-output: false !default;
5
5
 
6
6
 
7
7
  // Context (private)
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.0.0.alpha.4
4
+ version: 2.0.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Suzanne
@@ -41,6 +41,7 @@ extra_rdoc_files:
41
41
  - lib/true.rb
42
42
  files:
43
43
  - lib/compass-true.rb
44
+ - lib/main.js
44
45
  - lib/true.rb
45
46
  - sass/_true.scss
46
47
  - sass/true/_assert.scss