guard-jasmine 1.19.2 → 2.0.0beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -234
  3. data/lib/generators/guard_jasmine/install_generator.rb +17 -0
  4. data/lib/generators/guard_jasmine/templates/Guardfile +9 -0
  5. data/lib/guard/jasmine.rb +18 -15
  6. data/lib/guard/jasmine/cli.rb +5 -5
  7. data/lib/guard/jasmine/formatter.rb +10 -0
  8. data/lib/guard/jasmine/inspector.rb +1 -2
  9. data/lib/guard/jasmine/phantomjs/guard-jasmine.js +54 -180
  10. data/lib/guard/jasmine/phantomjs/guard-reporter.js +187 -0
  11. data/lib/guard/jasmine/phantomjs/src/guard-jasmine.coffee +101 -0
  12. data/lib/guard/jasmine/phantomjs/src/guard-reporter.coffee +109 -0
  13. data/lib/guard/jasmine/phantomjs/test/guard-reporter_spec.coffee +41 -0
  14. data/lib/guard/jasmine/runner.rb +178 -268
  15. data/lib/guard/jasmine/server.rb +17 -3
  16. data/lib/guard/jasmine/util.rb +1 -7
  17. data/lib/guard/jasmine/version.rb +1 -1
  18. metadata +135 -26
  19. data/lib/guard/jasmine/phantomjs/guard-jasmine.coffee +0 -193
  20. data/lib/guard/jasmine/phantomjs/lib/console.js +0 -188
  21. data/lib/guard/jasmine/phantomjs/lib/junit_reporter.js +0 -224
  22. data/lib/guard/jasmine/phantomjs/lib/reporter.js +0 -144
  23. data/lib/guard/jasmine/phantomjs/lib/result.js +0 -155
  24. data/lib/guard/jasmine/phantomjs/src/console.coffee +0 -149
  25. data/lib/guard/jasmine/phantomjs/src/reporter.coffee +0 -139
  26. data/lib/guard/jasmine/phantomjs/src/result.coffee +0 -95
  27. data/lib/guard/jasmine/phantomjs/test/console_spec.coffee +0 -125
  28. data/lib/guard/jasmine/phantomjs/test/reporter_spec.coffee +0 -0
  29. data/lib/guard/jasmine/phantomjs/test/result_spec.coffee +0 -311
@@ -1,155 +0,0 @@
1
- (function() {
2
- var Result;
3
-
4
- Result = (function() {
5
- function Result(result, logs, errors, options) {
6
- this.result = result;
7
- this.logs = logs != null ? logs : {};
8
- this.errors = errors != null ? errors : {};
9
- this.options = options != null ? options : {};
10
- }
11
-
12
- Result.prototype.addLogs = function(suite) {
13
- var id, s, spec;
14
-
15
- suite.suites = (function() {
16
- var _i, _len, _ref, _results;
17
-
18
- _ref = suite.suites;
19
- _results = [];
20
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
21
- s = _ref[_i];
22
- _results.push(this.addLogs(s));
23
- }
24
- return _results;
25
- }).call(this);
26
- if (suite.specs) {
27
- suite.specs = (function() {
28
- var _i, _len, _ref, _results;
29
-
30
- _ref = suite.specs;
31
- _results = [];
32
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
33
- spec = _ref[_i];
34
- if (this.options.console === 'always' || (this.options.console === 'failure' && !spec.passed)) {
35
- id = Number(spec['id']);
36
- if (this.logs[id] && this.logs[id].length !== 0) {
37
- spec.logs = this.logs[id];
38
- }
39
- }
40
- _results.push(spec);
41
- }
42
- return _results;
43
- }).call(this);
44
- }
45
- return suite;
46
- };
47
-
48
- Result.prototype.addErrors = function(suite) {
49
- var id, s, spec;
50
-
51
- suite.suites = (function() {
52
- var _i, _len, _ref, _results;
53
-
54
- _ref = suite.suites;
55
- _results = [];
56
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
57
- s = _ref[_i];
58
- _results.push(this.addErrors(s));
59
- }
60
- return _results;
61
- }).call(this);
62
- if (suite.specs) {
63
- suite.specs = (function() {
64
- var _i, _len, _ref, _results;
65
-
66
- _ref = suite.specs;
67
- _results = [];
68
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
69
- spec = _ref[_i];
70
- if (this.options.errors === 'always' || (this.options.errors === 'failure' && !spec.passed)) {
71
- id = Number(spec['id']);
72
- if (this.errors[id] && this.errors[id].length !== 0) {
73
- spec.errors = this.errors[id];
74
- }
75
- }
76
- _results.push(spec);
77
- }
78
- return _results;
79
- }).call(this);
80
- }
81
- return suite;
82
- };
83
-
84
- Result.prototype.addGlobalError = function(suite) {
85
- var b, err, errMsg, globalErrors, noSpecs, noSuites, _i, _len, _ref;
86
-
87
- noSuites = !suite.suites || suite.suites.length === 0;
88
- noSpecs = !suite.specs || suite.specs.length === 0;
89
- globalErrors = this.errors[-1] && this.errors[-1].length !== 0;
90
- if (noSuites && noSpecs && globalErrors) {
91
- err = this.errors[-1][0];
92
- errMsg = [err.msg];
93
- _ref = err.trace;
94
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
95
- b = _ref[_i];
96
- errMsg.push("\n " + b.file + ":" + b.line + " " + b["function"]);
97
- }
98
- suite.error = errMsg.join("");
99
- return suite.passed = false;
100
- }
101
- };
102
-
103
- Result.prototype.cleanResult = function(suite) {
104
- var s, spec, _i, _len, _ref;
105
-
106
- suite.suites = (function() {
107
- var _i, _len, _ref, _results;
108
-
109
- _ref = suite.suites;
110
- _results = [];
111
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
112
- s = _ref[_i];
113
- _results.push(this.cleanResult(s));
114
- }
115
- return _results;
116
- }).call(this);
117
- if (suite.specs) {
118
- _ref = suite.specs;
119
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
120
- spec = _ref[_i];
121
- delete spec['id'];
122
- }
123
- }
124
- delete suite['id'];
125
- delete suite['parent'];
126
- return suite;
127
- };
128
-
129
- Result.prototype.process = function() {
130
- if (this.options.console !== 'never') {
131
- this.addLogs(this.result);
132
- }
133
- if (this.options.errors !== 'never') {
134
- this.addErrors(this.result);
135
- this.addGlobalError(this.result);
136
- }
137
- this.cleanResult(this.result);
138
- return this.result;
139
- };
140
-
141
- return Result;
142
-
143
- })();
144
-
145
- if (typeof module !== 'undefined' && module.exports) {
146
- if (module) {
147
- module.exports = Result;
148
- }
149
- } else {
150
- if (window) {
151
- window.Result = Result;
152
- }
153
- }
154
-
155
- }).call(this);
@@ -1,149 +0,0 @@
1
- # Simplified console logger replacement.
2
- #
3
- class Console
4
-
5
- # Construct the console wrapper and attach
6
- # the log methods.
7
- #
8
- constructor: (console) ->
9
- log = console.log
10
-
11
- console.log = (args...) ->
12
- log.call console, Console.format(args...)
13
-
14
- console.info = (args...) ->
15
- log.call console, "INFO: #{ Console.format(args...) }"
16
-
17
- console.warn = (args...) ->
18
- log.call console, "WARN: #{ Console.format(args...) }"
19
-
20
- console.error = (args...) ->
21
- log.call console, "ERROR: #{ Console.format(args...) }"
22
-
23
- console.debug = (args...) ->
24
- log.call console, "DEBUG: #{ Console.format(args...) }"
25
-
26
- @MAX_OBJECT_DEPTH: 2
27
-
28
- # Format the console arguments. This parses the known
29
- # % placeholder with the object value and/or concatenates
30
- # the arguments.
31
- #
32
- # @param [Array] args the log arguments
33
- #
34
- @format: (args...) ->
35
- result = []
36
-
37
- if typeof args[0] is 'string' and /%[sdifo]/gi.test args[0]
38
- arg = args.shift()
39
- result.push arg.replace /%[sdifo]/gi, (str) => Console.inspect args.shift(), str
40
-
41
- result.push Console.inspect arg for arg in args
42
- result.join ' '
43
-
44
- # Inspect a log object and return a string representation.
45
- #
46
- # @param [Object] object the object to inspect
47
- # @param [String] type the format type
48
- # @return [String] a string representation
49
- #
50
- @inspect: (object, type) ->
51
- switch type
52
- when '%s'
53
- result = String(object)
54
- result = match[1] if match = /'(.*)'/.exec result
55
-
56
- when '%d', '%i'
57
- result = parseInt object
58
-
59
- when '%f'
60
- result = parseFloat object
61
-
62
- else
63
- type = Object::toString.call(object).slice 8, -1
64
-
65
- if type is 'Object' and object.toJSON
66
- result = Console.pp object.toJSON()
67
-
68
- else if type is 'Object' and object.toString and object.toString() isnt '[object Object]'
69
- result = Console.pp object.toString()
70
- result = match[1] if match = /'(.*)'/.exec result
71
-
72
- else if type is 'String'
73
- result = String(object)
74
- result = match[1] if match = /'(.*)'/.exec result
75
-
76
- else
77
- result = Console.pp object
78
-
79
- result
80
-
81
- # Pretty print an object
82
- #
83
- # @param [Object] object the object to inspect
84
- # @param [Number] depth the object depth
85
- # @return [String] a string representation
86
- #
87
- @pp: (object, depth = 0) ->
88
- type = Object::toString.call(object).slice 8, -1
89
- result = ''
90
-
91
- switch type
92
- when 'Undefined', 'Null'
93
- result += type.toLowerCase()
94
-
95
- when 'Boolean', 'Number', 'Date'
96
- result += object.toString()
97
-
98
- when 'String'
99
- result += "'#{ object.toString() }'"
100
-
101
- when 'Array'
102
- if object.length > 0
103
- result += '['
104
-
105
- for value in object
106
- if depth < Console.MAX_OBJECT_DEPTH or Object::toString.call(value).slice(8, -1) isnt 'Object'
107
- result += "#{ Console.pp value, depth + 1 }, "
108
- else
109
- result += "[Object], "
110
-
111
- result = result.slice(0, -2)
112
- result += ']'
113
- else
114
- result += '[]'
115
-
116
- when 'Object'
117
- if object.jquery
118
- if object.length > 0
119
- result += '['
120
-
121
- object.each -> result += jQuery(@).html()
122
-
123
- result += ']'
124
- else
125
- result += '[]'
126
-
127
- else if Object.keys(object).length > 0
128
- result += '{ '
129
-
130
- for key, value of object
131
- if depth < Console.MAX_OBJECT_DEPTH or Object::toString.call(value).slice(8, -1) isnt 'Object'
132
- result += "#{ key }: #{ Console.pp value, depth + 1 }, " if object.hasOwnProperty key
133
- else
134
- result += "#{ key }: [Object], "
135
-
136
- result = result.slice(0, -2)
137
- result += ' }'
138
- else
139
- result += '{}'
140
-
141
- when 'Function'
142
- result += '[Function]'
143
-
144
- result
145
-
146
- if typeof module isnt 'undefined' and module.exports
147
- module.exports = Console if module
148
- else
149
- new Console(window.console) if window
@@ -1,139 +0,0 @@
1
- # Jasmine Reporter that logs reporter steps
2
- # and results to the console.
3
- #
4
- class ConsoleReporter
5
-
6
- runnerResult: {
7
- passed: false
8
- stats: {
9
- specs: 0
10
- failures: 0
11
- time: 0.0
12
- }
13
- suites: []
14
- }
15
-
16
- specCount: 0
17
- currentSpecs: {}
18
- nestedSuiteResults: {}
19
-
20
- # Report the start of a spec.
21
- #
22
- # @param spec [jasmine.Spec] the spec
23
- #
24
- reportSpecStarting: (spec) ->
25
- console.log "SPEC_START: #{ spec.id }"
26
-
27
- # Report results from a spec.
28
- #
29
- # @param spec [jasmine.Spec] the spec
30
- #
31
- reportSpecResults: (spec) ->
32
- unless spec.results().skipped
33
- specResult = {
34
- id: spec.id
35
- description: '' + spec.description
36
- passed: spec.results().failedCount is 0
37
- }
38
-
39
- if spec.results().failedCount isnt 0
40
- messages = []
41
- messages.push result.message for result in spec.results().getItems()
42
- specResult['messages'] = messages if messages.length isnt 0
43
-
44
- @specCount += 1
45
- @currentSpecs[spec.suite.id] or= []
46
- @currentSpecs[spec.suite.id].push specResult
47
-
48
- # Report results from a suite.
49
- #
50
- # @param suite [jasmine.Suite] the suite
51
- #
52
- reportSuiteResults: (suite) ->
53
- unless suite.results().skipped
54
- suiteResult = {
55
- id: suite.id
56
- parent: suite.parentSuite?.id
57
- description: '' + suite.description
58
- passed: suite.results().failedCount is 0
59
- specs: @currentSpecs[suite.id] || []
60
- suites: []
61
- }
62
-
63
- if suite.parentSuite?
64
- parent = suite.parentSuite.id
65
- @nestedSuiteResults[parent] or= []
66
- @nestedSuiteResults[parent].push suiteResult
67
- else
68
- @addNestedSuites suiteResult
69
- @removeEmptySuites suiteResult
70
-
71
- if suiteResult.specs.length isnt 0 || suiteResult.suites.length isnt 0
72
- @runnerResult.suites.push suiteResult
73
-
74
- # Report results from the runner.
75
- #
76
- # @param runner [jasmine.Runner] the runner
77
- #
78
- reportRunnerResults: (runner) ->
79
- runtime = (new Date().getTime() - @startTime) / 1000
80
-
81
- @runnerResult['passed'] = runner.results().failedCount is 0
82
-
83
- @runnerResult['stats'] = {
84
- specs: @specCount
85
- failures: runner.results().failedCount
86
- time: runtime
87
- }
88
-
89
- # Report coverage results if data present
90
- if window.__coverage__
91
- @runnerResult['coverage'] = window.__coverage__
92
-
93
- # Delay the end runner message, so that logs and errors can be retreived in between
94
- end = -> console.log "RUNNER_END"
95
- setTimeout end, 10
96
-
97
- # Report the start of the runner
98
- #
99
- # @param runner [jasmine.Runner] the runner
100
- #
101
- reportRunnerStarting: (runner) ->
102
- @startTime = new Date().getTime()
103
-
104
- # Add all nested suites that have previously
105
- # been processed.
106
- #
107
- # @param suiteResult [Object] the suite result
108
- #
109
- addNestedSuites: (suiteResult) ->
110
- if @nestedSuiteResults[suiteResult.id]
111
- for suite in @nestedSuiteResults[suiteResult.id]
112
- @addNestedSuites suite
113
- suiteResult.suites.push suite
114
-
115
- # Removes suites without child suites or specs.
116
- #
117
- # @param suiteResult [Object] the suite result
118
- #
119
- removeEmptySuites: (suiteResult) ->
120
- suites = []
121
-
122
- for suite in suiteResult.suites
123
- @removeEmptySuites suite
124
-
125
- suites.push suite if suite.suites.length isnt 0 || suite.specs.length isnt 0
126
-
127
- suiteResult.suites = suites
128
-
129
- # Log a message
130
- #
131
- # @param message [String] the log message
132
- #
133
- log: (message) ->
134
-
135
-
136
- if typeof module isnt 'undefined' and module.exports
137
- module.exports = ConsoleReporter
138
- else
139
- window.ConsoleReporter = ConsoleReporter
@@ -1,95 +0,0 @@
1
- # Combines various information into the final result set
2
- # that will be outputted to the console.
3
- #
4
- class Result
5
-
6
- # Construct the result parser
7
- #
8
- constructor: (@result, @logs = {}, @errors = {}, @options = {}) ->
9
-
10
- # Add captured log statements to the result
11
- #
12
- # @param [Object] suite the suite result
13
- # @return [Object] the suite
14
- #
15
- addLogs: (suite) ->
16
- suite.suites = for s in suite.suites
17
- @addLogs(s)
18
-
19
- if suite.specs
20
- suite.specs = for spec in suite.specs
21
- if @options.console is 'always' || (@options.console is 'failure' && !spec.passed)
22
- id = Number(spec['id'])
23
- spec.logs = @logs[id] if @logs[id] && @logs[id].length isnt 0
24
-
25
- spec
26
-
27
- suite
28
-
29
- # Add captured errors to the result
30
- #
31
- # @param [Object] suite the suite result
32
- # @return [Object] the suite
33
- #
34
- addErrors: (suite) ->
35
- suite.suites = for s in suite.suites
36
- @addErrors(s)
37
-
38
- if suite.specs
39
- suite.specs = for spec in suite.specs
40
- if @options.errors is 'always' || (@options.errors is 'failure' && !spec.passed)
41
- id = Number(spec['id'])
42
- spec.errors = @errors[id] if @errors[id] && @errors[id].length isnt 0
43
-
44
- spec
45
-
46
- suite
47
-
48
- addGlobalError: (suite) ->
49
- noSuites = !suite.suites || suite.suites.length == 0
50
- noSpecs = !suite.specs || suite.specs.length == 0
51
- globalErrors = @errors[-1] && @errors[-1].length != 0
52
-
53
- if noSuites && noSpecs && globalErrors
54
- err = @errors[-1][0]
55
- errMsg = [ err.msg ]
56
- for b in err.trace
57
- errMsg.push "\n #{b.file}:#{b.line} #{b.function}"
58
- suite.error = errMsg.join("")
59
- suite.passed = false
60
-
61
- # Clean unnecessary properties from the result
62
- #
63
- # @param [Object] suite the suite result
64
- # @return [Object] the cleaned suite
65
- #
66
- cleanResult: (suite) ->
67
- suite.suites = for s in suite.suites
68
- @cleanResult(s)
69
-
70
- if suite.specs
71
- delete spec['id'] for spec in suite.specs
72
-
73
- delete suite['id']
74
- delete suite['parent']
75
-
76
- suite
77
-
78
- # Processes the collected results and returns
79
- # a single result object.
80
- #
81
- # @return [Object] the Jasmine result
82
- #
83
- process: ->
84
- @addLogs(@result) if @options.console isnt 'never'
85
- if @options.errors isnt 'never'
86
- @addErrors(@result)
87
- @addGlobalError(@result)
88
- @cleanResult(@result)
89
-
90
- @result
91
-
92
- if typeof module isnt 'undefined' and module.exports
93
- module.exports = Result if module
94
- else
95
- window.Result = Result if window