learn-test 3.0.0 → 3.2.1.pre.1

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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -12
  3. data/.gitignore +1 -0
  4. data/.rspec +1 -0
  5. data/Gemfile +4 -2
  6. data/README.md +2 -2
  7. data/Rakefile +2 -1
  8. data/bin/learn-test +15 -14
  9. data/bin/learn-test-wip +359 -0
  10. data/learn-test.gemspec +15 -18
  11. data/lib/learn_test.rb +3 -1
  12. data/lib/learn_test/client.rb +2 -0
  13. data/lib/learn_test/dependencies/ant.rb +2 -0
  14. data/lib/learn_test/dependencies/csharp.rb +3 -1
  15. data/lib/learn_test/dependencies/imagemagick.rb +2 -0
  16. data/lib/learn_test/dependencies/java.rb +2 -0
  17. data/lib/learn_test/dependencies/karma.rb +2 -0
  18. data/lib/learn_test/dependencies/nodejs.rb +2 -0
  19. data/lib/learn_test/dependencies/phantomjs.rb +6 -4
  20. data/lib/learn_test/dependencies/protractor.rb +2 -0
  21. data/lib/learn_test/dependencies/selenium_server.rb +2 -0
  22. data/lib/learn_test/dependency.rb +4 -4
  23. data/lib/learn_test/file_finder.rb +2 -1
  24. data/lib/learn_test/git_wip.rb +23 -0
  25. data/lib/learn_test/github_interactor.rb +2 -1
  26. data/lib/learn_test/js_strategy.rb +3 -1
  27. data/lib/learn_test/learn_oauth_token_parser.rb +2 -0
  28. data/lib/learn_test/netrc_interactor.rb +2 -1
  29. data/lib/learn_test/repo_parser.rb +2 -0
  30. data/lib/learn_test/reporter.rb +14 -7
  31. data/lib/learn_test/runner.rb +5 -4
  32. data/lib/learn_test/strategies/csharp_nunit.rb +5 -3
  33. data/lib/learn_test/strategies/java_junit.rb +9 -8
  34. data/lib/learn_test/strategies/karma.rb +9 -5
  35. data/lib/learn_test/strategies/mocha.rb +10 -8
  36. data/lib/learn_test/strategies/protractor.rb +7 -6
  37. data/lib/learn_test/strategies/pytest.rb +13 -13
  38. data/lib/learn_test/strategies/pytest/requirements_checker.rb +14 -12
  39. data/lib/learn_test/strategies/rspec.rb +11 -10
  40. data/lib/learn_test/strategy.rb +5 -6
  41. data/lib/learn_test/user_id_parser.rb +2 -1
  42. data/lib/learn_test/username_parser.rb +3 -2
  43. data/lib/learn_test/version.rb +3 -1
  44. data/spec/features/rspec_unit_spec.rb +4 -2
  45. data/spec/fixtures/rspec-unit-spec/lib/dog.rb +3 -1
  46. data/spec/fixtures/rspec-unit-spec/spec/dog_spec.rb +4 -2
  47. data/spec/fixtures/rspec-unit-spec/spec/spec_helper.rb +2 -0
  48. data/spec/learn_test/git_spec.rb +40 -0
  49. data/spec/learn_test/reporter_spec.rb +69 -31
  50. data/spec/learn_test/username_parser_spec.rb +2 -0
  51. data/spec/lib/learn_test/strategies/mocha_spec.rb +21 -20
  52. data/spec/repo_parser_spec.rb +14 -12
  53. data/spec/spec_helper.rb +2 -0
  54. metadata +20 -126
  55. data/Gemfile.lock +0 -71
  56. data/lib/learn_test/strategies/jasmine.rb +0 -181
  57. data/lib/learn_test/strategies/jasmine/boot.js +0 -184
  58. data/lib/learn_test/strategies/jasmine/console.js +0 -161
  59. data/lib/learn_test/strategies/jasmine/formatters/jasmine2-junit.js +0 -199
  60. data/lib/learn_test/strategies/jasmine/helpers/ConsoleHelper.js +0 -12
  61. data/lib/learn_test/strategies/jasmine/helpers/ConsoleHelperNoColor.js +0 -12
  62. data/lib/learn_test/strategies/jasmine/initializer.rb +0 -27
  63. data/lib/learn_test/strategies/jasmine/jasmine-html.js +0 -360
  64. data/lib/learn_test/strategies/jasmine/jasmine-jquery.js +0 -813
  65. data/lib/learn_test/strategies/jasmine/jasmine.css +0 -56
  66. data/lib/learn_test/strategies/jasmine/jasmine.js +0 -2403
  67. data/lib/learn_test/strategies/jasmine/jasmine_favicon.png +0 -0
  68. data/lib/learn_test/strategies/jasmine/jquery-1.8.0.min.js +0 -2
  69. data/lib/learn_test/strategies/jasmine/jquery-ui-1.8.23.custom.min.js +0 -125
  70. data/lib/learn_test/strategies/jasmine/runners/SpecRunner.html +0 -35
  71. data/lib/learn_test/strategies/jasmine/runners/run-jasmine.js +0 -229
  72. data/lib/learn_test/strategies/jasmine/templates/SpecRunnerTemplate.html.erb +0 -35
  73. data/lib/learn_test/strategies/jasmine/templates/SpecRunnerTemplateNoColor.html.erb +0 -35
  74. data/lib/learn_test/strategies/jasmine/templates/requires.yml.example +0 -7
  75. data/lib/learn_test/strategies/jasmine/vendor/require.js +0 -2077
  76. data/spec/features/jasmine_jquery_fixtures_spec.rb +0 -10
  77. data/spec/fixtures/jasmine-jquery-fixtures/index.html +0 -10
  78. data/spec/fixtures/jasmine-jquery-fixtures/requires.yml +0 -4
  79. data/spec/fixtures/jasmine-jquery-fixtures/spec/jasmine-jquery-fixtures-spec.js +0 -11
@@ -1,71 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- learn-test (2.7.0)
5
- colorize (~> 0.8.1)
6
- crack (~> 0.4.3)
7
- faraday (~> 0.9)
8
- git (~> 1.2)
9
- jasmine (~> 2.6.0, >= 2.6.0)
10
- jasmine-core (< 2.99.1)
11
- netrc (~> 0.11.0)
12
- oj (~> 2.9)
13
- rainbow (= 1.99.2)
14
- rspec (~> 3.0)
15
- webrick (~> 1.3.1, >= 1.3.1)
16
-
17
- GEM
18
- remote: https://rubygems.org/
19
- specs:
20
- colorize (0.8.1)
21
- crack (0.4.3)
22
- safe_yaml (~> 1.0.0)
23
- diff-lcs (1.4.4)
24
- faraday (0.17.3)
25
- multipart-post (>= 1.2, < 3)
26
- git (1.7.0)
27
- rchardet (~> 1.8)
28
- jasmine (2.6.0)
29
- jasmine-core (>= 2.6.0, < 3.0.0)
30
- phantomjs
31
- rack (>= 1.2.1)
32
- rake
33
- jasmine-core (2.99.0)
34
- multipart-post (2.1.1)
35
- netrc (0.11.0)
36
- oj (2.18.5)
37
- phantomjs (2.1.1.0)
38
- rack (2.2.3)
39
- rainbow (1.99.2)
40
- rake (13.0.1)
41
- rchardet (1.8.0)
42
- rspec (3.9.0)
43
- rspec-core (~> 3.9.0)
44
- rspec-expectations (~> 3.9.0)
45
- rspec-mocks (~> 3.9.0)
46
- rspec-core (3.9.2)
47
- rspec-support (~> 3.9.3)
48
- rspec-expectations (3.9.2)
49
- diff-lcs (>= 1.2.0, < 2.0)
50
- rspec-support (~> 3.9.0)
51
- rspec-mocks (3.9.1)
52
- diff-lcs (>= 1.2.0, < 2.0)
53
- rspec-support (~> 3.9.0)
54
- rspec-support (3.9.3)
55
- rspec_junit_formatter (0.4.1)
56
- rspec-core (>= 2, < 4, != 2.12.0)
57
- safe_yaml (1.0.5)
58
- webrick (1.3.1)
59
-
60
- PLATFORMS
61
- ruby
62
-
63
- DEPENDENCIES
64
- bundler (~> 2.1.4)
65
- learn-test!
66
- rake (~> 13.0.1)
67
- rspec (~> 3.8)
68
- rspec_junit_formatter (~> 0.4.1)
69
-
70
- BUNDLED WITH
71
- 2.1.4
@@ -1,181 +0,0 @@
1
- require_relative 'jasmine/initializer'
2
-
3
- module LearnTest
4
- module Strategies
5
- class Jasmine < LearnTest::Strategy
6
- def service_endpoint
7
- '/e/flatiron_jasmine'
8
- end
9
-
10
- def detect
11
- runner.files.include?('requires.yml')
12
- end
13
-
14
- def check_dependencies
15
- Dependencies::PhantomJS.new.execute unless options[:skip]
16
- end
17
-
18
- def run
19
- require 'crack'
20
- require 'erb'
21
- require 'yaml'
22
- require 'json'
23
-
24
- if options[:init]
25
- LearnTest::Jasmine::Initializer.run
26
- else
27
- set_up_runner
28
- run_jasmine
29
- make_json
30
- end
31
- end
32
-
33
- def results
34
- @results ||= {
35
- username: username,
36
- github_user_id: user_id,
37
- learn_oauth_token: learn_oauth_token,
38
- repo_name: runner.repo,
39
- build: {
40
- test_suite: [{
41
- framework: 'jasmine',
42
- formatted_output: [],
43
- duration: 0.0
44
- }]
45
- },
46
- tests: 0,
47
- errors: 0,
48
- failures: 0
49
- }
50
- end
51
-
52
- def push_results?
53
- !local? && !browser?
54
- end
55
-
56
- def cleanup
57
- test_xml_files.each do |file|
58
- FileUtils.rm(file)
59
- end
60
-
61
- FileUtils.rm_rf("#{Dir.pwd}/tmpTestSupport") if !browser?
62
- end
63
-
64
- def username
65
- options[:skip] ? "jasmine-flatiron" : super
66
- end
67
-
68
- def user_id
69
- options[:skip] ? "none" : super
70
- end
71
-
72
- def learn_oauth_token
73
- options[:skip] ? nil : super
74
- end
75
-
76
- private
77
-
78
- def set_up_runner
79
- template = ERB.new(File.read("#{LearnTest::FileFinder.location_to_dir('strategies/jasmine/templates')}/SpecRunnerTemplate#{color_option}.html.erb"))
80
-
81
- yaml = YAML.load(File.read('requires.yml'))["javascripts"]
82
-
83
- required_files = yaml["files"]
84
- required_specs = yaml["specs"]
85
-
86
- @javascripts = []
87
- @javascripts << (required_files && required_files.map {|f| "#{test_path}/#{f}"})
88
- @javascripts << (required_specs && required_specs.map {|f| "#{test_path}/#{f}"} )
89
- @javascripts.flatten!.compact!
90
-
91
- copy_support_files
92
-
93
- File.open("#{Dir.pwd}/tmpTestSupport/SpecRunner#{color_option}.html", "w+") do |f|
94
- f << template.result(binding)
95
- end
96
- end
97
-
98
- def copy_support_files
99
- FileUtils.mkdir("#{Dir.pwd}/tmpTestSupport") if !File.exist?("#{Dir.pwd}/tmpTestSupport")
100
-
101
- FileUtils.cp("#{LearnTest::FileFinder.location_to_dir('strategies/jasmine')}/jasmine.js","#{Dir.pwd}/tmpTestSupport/")
102
- FileUtils.cp("#{LearnTest::FileFinder.location_to_dir('strategies/jasmine')}/jasmine-html.js","#{Dir.pwd}/tmpTestSupport/")
103
- FileUtils.cp("#{LearnTest::FileFinder.location_to_dir('strategies/jasmine')}/console.js","#{Dir.pwd}/tmpTestSupport/")
104
- FileUtils.cp("#{LearnTest::FileFinder.location_to_dir('strategies/jasmine')}/boot.js","#{Dir.pwd}/tmpTestSupport/")
105
- FileUtils.cp("#{LearnTest::FileFinder.location_to_dir('strategies/jasmine')}/jquery-1.8.0.min.js","#{Dir.pwd}/tmpTestSupport/")
106
- FileUtils.cp("#{LearnTest::FileFinder.location_to_dir('strategies/jasmine')}/jquery-ui-1.8.23.custom.min.js","#{Dir.pwd}/tmpTestSupport/")
107
- FileUtils.cp("#{LearnTest::FileFinder.location_to_dir('strategies/jasmine')}/jasmine-jquery.js","#{Dir.pwd}/tmpTestSupport/")
108
- FileUtils.cp("#{LearnTest::FileFinder.location_to_dir('strategies/jasmine')}/jasmine.css","#{Dir.pwd}/tmpTestSupport/")
109
- FileUtils.cp("#{LearnTest::FileFinder.location_to_dir('strategies/jasmine')}/jasmine_favicon.png","#{Dir.pwd}/tmpTestSupport/")
110
- FileUtils.cp("#{LearnTest::FileFinder.location_to_dir('strategies/jasmine/formatters')}/jasmine2-junit.js","#{Dir.pwd}/tmpTestSupport/")
111
- FileUtils.cp("#{LearnTest::FileFinder.location_to_dir('strategies/jasmine/helpers')}/ConsoleHelper.js","#{Dir.pwd}/tmpTestSupport/")
112
- end
113
-
114
- def run_jasmine
115
- if browser?
116
- chrome_on_mac_path ="\"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome\""
117
- chrome_on_linux_path = "google-chrome"
118
- jasmine_lab_path_for_chrome = "\"#{Dir.pwd}/tmpTestSupport/SpecRunner#{color_option}.html\" --allow-file-access-from-files"
119
-
120
- if RUBY_PLATFORM.include?("linux")
121
- system("#{chrome_on_linux_path} #{jasmine_lab_path_for_chrome}")
122
- else
123
- system("#{chrome_on_mac_path} #{jasmine_lab_path_for_chrome}")
124
- end
125
- else
126
- system("phantomjs #{LearnTest::FileFinder.location_to_dir('strategies/jasmine/runners')}/run-jasmine.js #{Dir.pwd}/tmpTestSupport/SpecRunner#{color_option}.html")
127
- end
128
- end
129
-
130
- def test_xml_files
131
- Dir.entries(test_path).keep_if { |f| f.match(/TEST/) }
132
- end
133
-
134
- def make_json
135
- if local? || !browser?
136
- test_xml_files.each do |f|
137
- parsed = JSON.parse(Crack::XML.parse(File.read(f)).to_json)["testsuites"]["testsuite"]
138
- results[:build][:test_suite][0][:formatted_output] << parsed["testcase"]
139
- results[:build][:test_suite][0][:formatted_output].flatten!
140
- results[:tests] += parsed["tests"].to_i
141
- results[:errors] += parsed["errors"].to_i
142
- results[:failures] += parsed["failures"].to_i
143
- results[:build][:test_suite][0][:duration] += parsed["time"].to_f
144
- end
145
- results[:passing_count] = results[:tests] - results[:failures] - results[:errors]
146
- end
147
-
148
- if out || runner.keep_results?
149
- output_file = out ? out : '.results.json'
150
- write_json_output(output_file: output_file)
151
- end
152
- end
153
-
154
- def write_json_output(output_file:)
155
- File.open(output_file, 'w+') do |f|
156
- f.write(results.to_json)
157
- end
158
- end
159
-
160
- def color_option
161
- !options[:color] ? '' : 'NoColor'
162
- end
163
-
164
- def local?
165
- !!options[:local]
166
- end
167
-
168
- def browser?
169
- !!options[:browser]
170
- end
171
-
172
- def out
173
- options[:out]
174
- end
175
-
176
- def test_path
177
- @test_path ||= FileUtils.pwd
178
- end
179
- end
180
- end
181
- end
@@ -1,184 +0,0 @@
1
- /**
2
- Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
3
-
4
- If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
5
-
6
- The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
7
-
8
- [jasmine-gem]: http://github.com/pivotal/jasmine-gem
9
- */
10
-
11
- (function() {
12
-
13
- /**
14
- * ## Require &amp; Instantiate
15
- *
16
- * Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
17
- */
18
- window.jasmine = jasmineRequire.core(jasmineRequire);
19
-
20
- /**
21
- * Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
22
- */
23
- jasmineRequire.html(jasmine);
24
-
25
- /**
26
- * Create the Jasmine environment. This is used to run all specs in a project.
27
- */
28
- var env = jasmine.getEnv();
29
-
30
- /**
31
- * ## The Global Interface
32
- *
33
- * Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
34
- */
35
- var jasmineInterface = {
36
- describe: function(description, specDefinitions) {
37
- return env.describe(description, specDefinitions);
38
- },
39
-
40
- xdescribe: function(description, specDefinitions) {
41
- return env.xdescribe(description, specDefinitions);
42
- },
43
-
44
- it: function(desc, func) {
45
- return env.it(desc, func);
46
- },
47
-
48
- xit: function(desc, func) {
49
- return env.xit(desc, func);
50
- },
51
-
52
- beforeEach: function(beforeEachFunction) {
53
- return env.beforeEach(beforeEachFunction);
54
- },
55
-
56
- afterEach: function(afterEachFunction) {
57
- return env.afterEach(afterEachFunction);
58
- },
59
-
60
- expect: function(actual) {
61
- return env.expect(actual);
62
- },
63
-
64
- pending: function() {
65
- return env.pending();
66
- },
67
-
68
- spyOn: function(obj, methodName) {
69
- return env.spyOn(obj, methodName);
70
- },
71
-
72
- jsApiReporter: new jasmine.JsApiReporter({
73
- timer: new jasmine.Timer()
74
- })
75
- };
76
-
77
- /**
78
- * Add all of the Jasmine global/public interface to the proper global, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
79
- */
80
- if (typeof window == "undefined" && typeof exports == "object") {
81
- extend(exports, jasmineInterface);
82
- } else {
83
- extend(window, jasmineInterface);
84
- }
85
-
86
- /**
87
- * Expose the interface for adding custom equality testers.
88
- */
89
- jasmine.addCustomEqualityTester = function(tester) {
90
- env.addCustomEqualityTester(tester);
91
- };
92
-
93
- /**
94
- * Expose the interface for adding custom expectation matchers
95
- */
96
- jasmine.addMatchers = function(matchers) {
97
- return env.addMatchers(matchers);
98
- };
99
-
100
- /**
101
- * Expose the mock interface for the JavaScript timeout functions
102
- */
103
- jasmine.clock = function() {
104
- return env.clock;
105
- };
106
-
107
- /**
108
- * ## Runner Parameters
109
- *
110
- * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
111
- */
112
-
113
- var queryString = new jasmine.QueryString({
114
- getWindowLocation: function() { return window.location; }
115
- });
116
-
117
- var catchingExceptions = queryString.getParam("catch");
118
- env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
119
-
120
- /**
121
- * ## Reporters
122
- * The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
123
- */
124
- var htmlReporter = new jasmine.HtmlReporter({
125
- env: env,
126
- onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
127
- getContainer: function() { return document.body; },
128
- createElement: function() { return document.createElement.apply(document, arguments); },
129
- createTextNode: function() { return document.createTextNode.apply(document, arguments); },
130
- timer: new jasmine.Timer()
131
- });
132
-
133
- /**
134
- * The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
135
- */
136
- env.addReporter(jasmineInterface.jsApiReporter);
137
- var JUnitXmlReporter = jasmineRequire.JUnitXmlReporter()
138
- env.addReporter(new JUnitXmlReporter());
139
- env.addReporter(htmlReporter);
140
-
141
- /**
142
- * Filter which specs will be run by matching the start of the full name against the `spec` query param.
143
- */
144
- var specFilter = new jasmine.HtmlSpecFilter({
145
- filterString: function() { return queryString.getParam("spec"); }
146
- });
147
-
148
- env.specFilter = function(spec) {
149
- return specFilter.matches(spec.getFullName());
150
- };
151
-
152
- /**
153
- * Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
154
- */
155
- window.setTimeout = window.setTimeout;
156
- window.setInterval = window.setInterval;
157
- window.clearTimeout = window.clearTimeout;
158
- window.clearInterval = window.clearInterval;
159
-
160
- /**
161
- * ## Execution
162
- *
163
- * Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
164
- */
165
- var currentWindowOnload = window.onload;
166
-
167
- window.onload = function() {
168
- if (currentWindowOnload) {
169
- currentWindowOnload();
170
- }
171
- htmlReporter.initialize();
172
- env.execute();
173
- };
174
-
175
- /**
176
- * Helper function for readability above.
177
- */
178
- function extend(destination, source) {
179
- for (var property in source) destination[property] = source[property];
180
- return destination;
181
- }
182
-
183
- }());
184
-
@@ -1,161 +0,0 @@
1
- /*
2
- Copyright (c) 2008-2013 Pivotal Labs
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining
5
- a copy of this software and associated documentation files (the
6
- "Software"), to deal in the Software without restriction, including
7
- without limitation the rights to use, copy, modify, merge, publish,
8
- distribute, sublicense, and/or sell copies of the Software, and to
9
- permit persons to whom the Software is furnished to do so, subject to
10
- the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be
13
- included in all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- */
23
- function getJasmineRequireObj() {
24
- if (typeof module !== "undefined" && module.exports) {
25
- return exports;
26
- } else {
27
- window.jasmineRequire = window.jasmineRequire || {};
28
- return window.jasmineRequire;
29
- }
30
- }
31
-
32
- getJasmineRequireObj().console = function(jRequire, j$) {
33
- j$.ConsoleReporter = jRequire.ConsoleReporter();
34
- };
35
-
36
- getJasmineRequireObj().ConsoleReporter = function() {
37
-
38
- var noopTimer = {
39
- start: function(){},
40
- elapsed: function(){ return 0; }
41
- };
42
-
43
- function ConsoleReporter(options) {
44
- var print = options.print,
45
- showColors = options.showColors || false,
46
- onComplete = options.onComplete || function() {},
47
- timer = options.timer || noopTimer,
48
- specCount,
49
- failureCount,
50
- failedSpecs = [],
51
- pendingCount,
52
- ansi = {
53
- green: '\x1B[32m',
54
- red: '\x1B[31m',
55
- yellow: '\x1B[33m',
56
- none: '\x1B[0m'
57
- };
58
-
59
- this.jasmineStarted = function() {
60
- specCount = 0;
61
- failureCount = 0;
62
- pendingCount = 0;
63
- print("Started");
64
- printNewline();
65
- timer.start();
66
- };
67
-
68
- this.jasmineDone = function() {
69
- printNewline();
70
- for (var i = 0; i < failedSpecs.length; i++) {
71
- specFailureDetails(failedSpecs[i]);
72
- }
73
-
74
- printNewline();
75
- var specCounts = specCount + " " + plural("spec", specCount) + ", " +
76
- failureCount + " " + plural("failure", failureCount);
77
-
78
- if (pendingCount) {
79
- specCounts += ", " + pendingCount + " pending " + plural("spec", pendingCount);
80
- }
81
-
82
- print(specCounts);
83
-
84
- printNewline();
85
- var seconds = timer.elapsed() / 1000;
86
- print("Finished in " + seconds + " " + plural("second", seconds));
87
-
88
- printNewline();
89
-
90
- onComplete(failureCount === 0);
91
- };
92
-
93
- this.specDone = function(result) {
94
- specCount++;
95
-
96
- if (result.status == "pending") {
97
- pendingCount++;
98
- print(colored("yellow", "*"));
99
- return;
100
- }
101
-
102
- if (result.status == "passed") {
103
- print(colored("green", '.'));
104
- return;
105
- }
106
-
107
- if (result.status == "failed") {
108
- failureCount++;
109
- failedSpecs.push(result);
110
- print(colored("red", 'F'));
111
- }
112
- };
113
-
114
- return this;
115
-
116
- function printNewline() {
117
- print("\n");
118
- }
119
-
120
- function colored(color, str) {
121
- return showColors ? (ansi[color] + str + ansi.none) : str;
122
- }
123
-
124
- function plural(str, count) {
125
- return count == 1 ? str : str + "s";
126
- }
127
-
128
- function repeat(thing, times) {
129
- var arr = [];
130
- for (var i = 0; i < times; i++) {
131
- arr.push(thing);
132
- }
133
- return arr;
134
- }
135
-
136
- function indent(str, spaces) {
137
- var lines = (str || '').split("\n");
138
- var newArr = [];
139
- for (var i = 0; i < lines.length; i++) {
140
- newArr.push(repeat(" ", spaces).join("") + lines[i]);
141
- }
142
- return newArr.join("\n");
143
- }
144
-
145
- function specFailureDetails(result) {
146
- printNewline();
147
- print(result.fullName);
148
-
149
- for (var i = 0; i < result.failedExpectations.length; i++) {
150
- var failedExpectation = result.failedExpectations[i];
151
- printNewline();
152
- print(indent(failedExpectation.stack, 2));
153
- }
154
-
155
- printNewline();
156
- }
157
- }
158
-
159
- return ConsoleReporter;
160
- };
161
-