teaspoon 0.7.9 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +382 -260
  3. data/app/assets/javascripts/teaspoon-angular.js +108 -26241
  4. data/app/assets/javascripts/teaspoon-jasmine.js +103 -2642
  5. data/app/assets/javascripts/teaspoon-mocha.js +109 -5416
  6. data/app/assets/javascripts/teaspoon-qunit.js +107 -2255
  7. data/app/assets/javascripts/teaspoon-teaspoon.js +0 -1
  8. data/app/assets/javascripts/teaspoon/angular.coffee +3 -1
  9. data/app/assets/javascripts/teaspoon/base/hook.coffee +21 -0
  10. data/app/assets/javascripts/teaspoon/base/reporters/html.coffee +26 -14
  11. data/app/assets/javascripts/teaspoon/base/reporters/html/progress_view.coffee +1 -1
  12. data/app/assets/javascripts/teaspoon/base/reporters/html/template.coffee +3 -3
  13. data/app/assets/javascripts/teaspoon/base/teaspoon.coffee +10 -1
  14. data/app/assets/javascripts/teaspoon/jasmine.coffee +3 -1
  15. data/app/assets/javascripts/teaspoon/mocha.coffee +3 -1
  16. data/app/assets/javascripts/teaspoon/mocha/reporters/html.coffee +1 -1
  17. data/app/assets/javascripts/teaspoon/qunit.coffee +3 -1
  18. data/app/assets/javascripts/teaspoon/qunit/reporters/html.coffee +1 -1
  19. data/app/assets/javascripts/teaspoon/teaspoon.coffee +0 -1
  20. data/app/assets/stylesheets/teaspoon.css +12 -8
  21. data/app/controllers/teaspoon/suite_controller.rb +32 -0
  22. data/app/views/teaspoon/suite/_body.html.erb +0 -0
  23. data/app/views/teaspoon/suite/_boot.html.erb +4 -0
  24. data/app/views/teaspoon/suite/_boot_require_js.html.erb +19 -0
  25. data/app/views/teaspoon/{spec/suites.html.erb → suite/index.html.erb} +6 -7
  26. data/app/views/teaspoon/suite/show.html.erb +19 -0
  27. data/bin/teaspoon +1 -1
  28. data/config/routes.rb +14 -4
  29. data/lib/generators/teaspoon/install/POST_INSTALL +2 -2
  30. data/lib/generators/teaspoon/install/install_generator.rb +22 -11
  31. data/lib/generators/teaspoon/install/templates/_body.html.erb +0 -0
  32. data/lib/generators/teaspoon/install/templates/_boot.html.erb +4 -0
  33. data/lib/generators/teaspoon/install/templates/jasmine/env.rb +11 -0
  34. data/lib/generators/teaspoon/install/templates/jasmine/env_comments.rb +182 -0
  35. data/lib/generators/teaspoon/install/templates/jasmine/spec_helper.coffee +8 -6
  36. data/lib/generators/teaspoon/install/templates/jasmine/spec_helper.js +8 -7
  37. data/lib/generators/teaspoon/install/templates/mocha/env.rb +11 -0
  38. data/lib/generators/teaspoon/install/templates/mocha/env_comments.rb +182 -0
  39. data/lib/generators/teaspoon/install/templates/mocha/spec_helper.coffee +13 -13
  40. data/lib/generators/teaspoon/install/templates/mocha/spec_helper.js +13 -13
  41. data/lib/generators/teaspoon/install/templates/qunit/env.rb +11 -0
  42. data/lib/generators/teaspoon/install/templates/qunit/env_comments.rb +182 -0
  43. data/lib/generators/teaspoon/install/templates/qunit/test_helper.coffee +6 -5
  44. data/lib/generators/teaspoon/install/templates/qunit/test_helper.js +6 -5
  45. data/lib/tasks/teaspoon.rake +9 -2
  46. data/lib/teaspoon.rb +4 -6
  47. data/lib/teaspoon/command_line.rb +116 -134
  48. data/lib/teaspoon/configuration.rb +144 -66
  49. data/lib/teaspoon/console.rb +70 -37
  50. data/lib/teaspoon/coverage.rb +42 -15
  51. data/lib/teaspoon/deprecated.rb +65 -0
  52. data/lib/teaspoon/drivers/base.rb +10 -0
  53. data/lib/teaspoon/drivers/phantomjs/runner.js +9 -11
  54. data/lib/teaspoon/drivers/phantomjs_driver.rb +21 -21
  55. data/lib/teaspoon/drivers/selenium_driver.rb +32 -13
  56. data/lib/teaspoon/engine.rb +32 -12
  57. data/lib/teaspoon/environment.rb +16 -12
  58. data/lib/teaspoon/exceptions.rb +41 -5
  59. data/lib/teaspoon/exporter.rb +52 -0
  60. data/lib/teaspoon/formatters/base.rb +171 -0
  61. data/lib/teaspoon/formatters/clean_formatter.rb +2 -4
  62. data/lib/teaspoon/formatters/documentation_formatter.rb +60 -0
  63. data/lib/teaspoon/formatters/dot_formatter.rb +12 -90
  64. data/lib/teaspoon/formatters/json_formatter.rb +36 -0
  65. data/lib/teaspoon/formatters/junit_formatter.rb +51 -32
  66. data/lib/teaspoon/formatters/modules/report_module.rb +76 -0
  67. data/lib/teaspoon/formatters/pride_formatter.rb +23 -27
  68. data/lib/teaspoon/formatters/snowday_formatter.rb +7 -11
  69. data/lib/teaspoon/formatters/swayze_or_oprah_formatter.rb +88 -64
  70. data/lib/teaspoon/formatters/tap_formatter.rb +18 -27
  71. data/lib/teaspoon/formatters/tap_y_formatter.rb +35 -45
  72. data/lib/teaspoon/formatters/teamcity_formatter.rb +69 -31
  73. data/lib/teaspoon/instrumentation.rb +33 -33
  74. data/lib/teaspoon/result.rb +2 -1
  75. data/lib/teaspoon/runner.rb +40 -28
  76. data/lib/teaspoon/server.rb +23 -25
  77. data/lib/teaspoon/suite.rb +52 -72
  78. data/lib/teaspoon/utility.rb +3 -14
  79. data/lib/teaspoon/version.rb +1 -1
  80. data/spec/dummy/app/assets/javascripts/integration/integration_spec.coffee +3 -0
  81. data/spec/dummy/app/assets/javascripts/integration/spec_helper.coffee +2 -0
  82. data/spec/dummy/config/application.rb +3 -0
  83. data/spec/features/console_reporter_spec.rb +48 -18
  84. data/spec/features/hooks_spec.rb +23 -41
  85. data/spec/features/html_reporter_spec.rb +38 -21
  86. data/spec/features/install_generator_spec.rb +34 -20
  87. data/spec/features/instrumentation_spec.rb +3 -2
  88. data/spec/fixtures/coverage.json +243 -0
  89. data/spec/javascripts/fixtures/_body.html.erb +1 -0
  90. data/spec/javascripts/jasmine_helper.coffee +1 -1
  91. data/spec/javascripts/teaspoon/base/fixture_spec.coffee +4 -4
  92. data/spec/javascripts/teaspoon/base/reporters/html_spec.coffee +9 -10
  93. data/spec/javascripts/teaspoon/mocha/reporters/html_mspec.coffee +0 -6
  94. data/spec/javascripts/teaspoon/phantomjs/runner_spec.coffee +5 -6
  95. data/spec/javascripts/turbolinks_helper.coffee +1 -1
  96. data/spec/spec_helper.rb +3 -4
  97. data/spec/teaspoon/command_line_spec.rb +139 -23
  98. data/spec/teaspoon/configuration_spec.rb +164 -46
  99. data/spec/teaspoon/console_spec.rb +142 -47
  100. data/spec/teaspoon/coverage_spec.rb +98 -28
  101. data/spec/teaspoon/drivers/base_spec.rb +5 -0
  102. data/spec/teaspoon/drivers/phantomjs_driver_spec.rb +32 -14
  103. data/spec/teaspoon/drivers/selenium_driver_spec.rb +32 -24
  104. data/spec/teaspoon/engine_spec.rb +8 -5
  105. data/spec/teaspoon/environment_spec.rb +56 -33
  106. data/spec/teaspoon/exceptions_spec.rb +57 -0
  107. data/spec/teaspoon/exporter_spec.rb +96 -0
  108. data/spec/teaspoon/formatters/base_spec.rb +259 -0
  109. data/spec/teaspoon/formatters/clean_formatter_spec.rb +37 -0
  110. data/spec/teaspoon/formatters/documentation_formatter_spec.rb +127 -0
  111. data/spec/teaspoon/formatters/dot_formatter_spec.rb +52 -56
  112. data/spec/teaspoon/formatters/json_formatter_spec.rb +77 -0
  113. data/spec/teaspoon/formatters/junit_formatter_spec.rb +72 -35
  114. data/spec/teaspoon/formatters/pride_formatter_spec.rb +37 -0
  115. data/spec/teaspoon/formatters/snowday_formatter_spec.rb +35 -0
  116. data/spec/teaspoon/formatters/tap_formatter_spec.rb +29 -81
  117. data/spec/teaspoon/formatters/tap_y_formatter_spec.rb +31 -141
  118. data/spec/teaspoon/formatters/teamcity_formatter_spec.rb +99 -42
  119. data/spec/teaspoon/instrumentation_spec.rb +44 -44
  120. data/spec/teaspoon/result_spec.rb +37 -0
  121. data/spec/teaspoon/runner_spec.rb +70 -59
  122. data/spec/teaspoon/server_spec.rb +34 -52
  123. data/spec/teaspoon/suite_spec.rb +42 -188
  124. data/spec/teaspoon_env.rb +39 -28
  125. data/vendor/assets/javascripts/{angular-scenario-1.0.5.js → angular/1.0.5.js} +0 -0
  126. data/vendor/assets/javascripts/{angular-scenario-1.0.5.MIT-LICENSE → angular/MIT-LICENSE} +0 -0
  127. data/vendor/assets/javascripts/{jasmine-1.3.1.js → jasmine/1.3.1.js} +0 -0
  128. data/vendor/assets/javascripts/jasmine/2.0.0.js +2412 -0
  129. data/vendor/assets/javascripts/{jasmine-1.3.1.MIT.LICENSE → jasmine/MIT.LICENSE} +0 -0
  130. data/vendor/assets/javascripts/{mocha-1.10.0.js → mocha/1.10.0.js} +1 -0
  131. data/vendor/assets/javascripts/mocha/1.17.1.js +5813 -0
  132. data/vendor/assets/javascripts/{mocha-1.10.1.MIT.LICENSE → mocha/MIT.LICENSE} +0 -0
  133. data/vendor/assets/javascripts/{qunit-1.12.0.js → qunit/1.12.0.js} +1 -1
  134. data/vendor/assets/javascripts/qunit/1.14.0.js +2288 -0
  135. data/vendor/assets/javascripts/{qunit-1.12.0.MIT.LICENSE → qunit/MIT.LICENSE} +0 -0
  136. data/vendor/assets/javascripts/support/chai.js +827 -385
  137. data/vendor/assets/javascripts/support/jasmine-jquery-1.7.0.js +720 -0
  138. data/vendor/assets/javascripts/support/jasmine-jquery-2.0.0.js +812 -0
  139. data/vendor/assets/javascripts/support/sinon-chai.js +17 -0
  140. data/vendor/assets/javascripts/support/sinon.js +1138 -643
  141. metadata +57 -36
  142. data/app/controllers/teaspoon/spec_controller.rb +0 -38
  143. data/app/helpers/teaspoon/spec_helper.rb +0 -36
  144. data/app/views/teaspoon/spec/_require_js.html.erb +0 -21
  145. data/app/views/teaspoon/spec/_standard.html.erb +0 -4
  146. data/app/views/teaspoon/spec/runner.html.erb +0 -19
  147. data/lib/generators/teaspoon/install/templates/env.rb +0 -38
  148. data/lib/generators/teaspoon/install/templates/jasmine/initializer.rb +0 -64
  149. data/lib/generators/teaspoon/install/templates/mocha/initializer.rb +0 -64
  150. data/lib/generators/teaspoon/install/templates/qunit/initializer.rb +0 -64
  151. data/lib/teaspoon/check_coverage.rb +0 -33
  152. data/lib/teaspoon/drivers/base_driver.rb +0 -10
  153. data/lib/teaspoon/exception_handling.rb +0 -18
  154. data/lib/teaspoon/formatters/base_formatter.rb +0 -63
  155. data/spec/dummy/config/initializers/teaspoon.rb +0 -41
  156. data/spec/teaspoon/check_coverage_spec.rb +0 -50
  157. data/spec/teaspoon/formatters/base_formatter_spec.rb +0 -45
  158. data/vendor/assets/javascripts/support/chai.MIT.LICENSE +0 -22
  159. data/vendor/assets/javascripts/support/expect.MIT.LICENSE +0 -22
  160. data/vendor/assets/javascripts/support/jasmine-jquery.MIT.LICENSE +0 -20
  161. data/vendor/assets/javascripts/support/jasmine-jquery.js +0 -659
  162. data/vendor/assets/javascripts/support/sinon-chai.MIT-ISH.LICENSE +0 -13
  163. data/vendor/assets/javascripts/support/sinon.BSD.LICENSE +0 -27
@@ -0,0 +1,171 @@
1
+ module Teaspoon
2
+ module Formatters
3
+
4
+ # CONTRIBUTORS:
5
+ # If you add a formatter you should do the following before it will be considered for merging.
6
+ # - add it to this list so it can be autoloaded
7
+ # - write specs for it
8
+ # - add it to the readme so it's documented
9
+ # - add it to the list in command_line.rb so others know it's available
10
+ # - add it to the initializers in /lib/generators/install/templates so it's documented there as well
11
+
12
+ autoload :CleanFormatter, "teaspoon/formatters/clean_formatter"
13
+ autoload :DocumentationFormatter, "teaspoon/formatters/documentation_formatter"
14
+ autoload :DotFormatter, "teaspoon/formatters/dot_formatter"
15
+ autoload :JsonFormatter, "teaspoon/formatters/json_formatter"
16
+ autoload :JunitFormatter, "teaspoon/formatters/junit_formatter"
17
+ autoload :PrideFormatter, "teaspoon/formatters/pride_formatter"
18
+ autoload :SnowdayFormatter, "teaspoon/formatters/snowday_formatter"
19
+ autoload :SwayzeOrOprahFormatter, "teaspoon/formatters/swayze_or_oprah_formatter"
20
+ autoload :TapFormatter, "teaspoon/formatters/tap_formatter"
21
+ autoload :TapYFormatter, "teaspoon/formatters/tap_y_formatter"
22
+ autoload :TeamcityFormatter, "teaspoon/formatters/teamcity_formatter"
23
+
24
+ class Base
25
+
26
+ attr_accessor :total_count, :run_count, :passes, :pendings, :failures, :errors
27
+
28
+ def initialize(suite_name = :default, output_file = nil)
29
+ @suite_name = suite_name.to_s
30
+ @output_file = output_file
31
+ @stdout = ""
32
+ @suite = nil
33
+ @last_suite = nil
34
+
35
+ @total_count = 0
36
+ @run_count = 0
37
+ @passes = []
38
+ @pendings = []
39
+ @failures = []
40
+ @errors = []
41
+ File.open(@output_file, "w") { |f| f.write("") } if @output_file
42
+ end
43
+
44
+ # beginning of the run
45
+ def runner(result, log = true)
46
+ @total_count = result.total
47
+ log_runner(result) if log
48
+ end
49
+
50
+ # each suite, before any specs
51
+ def suite(result, log = true)
52
+ @suite = result
53
+ log_suite(result) if log
54
+ @last_suite = result
55
+ end
56
+
57
+ # each spec, after the spec has reported to the client runner
58
+ def spec(result, log = true)
59
+ @run_count += 1
60
+ if result.passing?
61
+ @passes << result
62
+ elsif result.pending?
63
+ @pendings << result
64
+ else
65
+ @failures << result
66
+ end
67
+ log_spec(result) if log
68
+ @stdout = ""
69
+ end
70
+
71
+ # errors are reported from the onError handler in phantomjs, so they're not linked to a result
72
+ def error(result, log = true)
73
+ @errors << result
74
+ log_error(result) if log
75
+ end
76
+
77
+ # exception came from startup errors in the server (will exit after logging)
78
+ def exception(result = {}, log = true)
79
+ log_exception(result) if log
80
+ end
81
+
82
+ # console message come from console.log/debug/error
83
+ def console(message, log = true)
84
+ @stdout << message
85
+ log_console(message) if log
86
+ end
87
+
88
+ # final report
89
+ def result(result, log = true)
90
+ log_result(result) if log
91
+ end
92
+
93
+ # called with the text versions of coverage if configured to do so
94
+ def coverage(message, log = true)
95
+ log_coverage(message) if log
96
+ end
97
+
98
+ # called with an array of strings which explain which coverage thresholds failed
99
+ def threshold_failure(message, log = true)
100
+ log_threshold_failure(message) if log
101
+ end
102
+
103
+ def complete(failure_count, log = true)
104
+ log_complete(failure_count) if log
105
+ end
106
+
107
+ protected
108
+
109
+ def log_runner(result); end
110
+
111
+ def log_suite(result); end
112
+
113
+ def log_spec(result)
114
+ return log_passing_spec(result) if result.passing?
115
+ return log_pending_spec(result) if result.pending?
116
+ log_failing_spec(result)
117
+ end
118
+
119
+ def log_passing_spec(result); end
120
+
121
+ def log_pending_spec(result); end
122
+
123
+ def log_failing_spec(result); end
124
+
125
+ def log_error(result); end
126
+
127
+ def log_exception(result); end
128
+
129
+ def log_console(message); end
130
+
131
+ def log_result(result); end
132
+
133
+ def log_coverage(message); end
134
+
135
+ def log_threshold_failure(message); end
136
+
137
+ def log_complete(failure_count); end
138
+
139
+ private
140
+
141
+ def log_str(str, color_code = nil)
142
+ return log_to_file(str, @output_file) if @output_file
143
+ STDOUT.print(color_code ? colorize(str, color_code) : str)
144
+ end
145
+
146
+ def log_line(str = "", color_code = nil)
147
+ return log_to_file("#{str}\n", @output_file) if @output_file
148
+ STDOUT.print("#{color_code ? colorize(str, color_code) : str}\n")
149
+ end
150
+
151
+ def log_to_file(str, output_file)
152
+ @_output_file = File.open(output_file, "a") { |f| f.write(str) }
153
+ rescue IOError => e
154
+ raise Teaspoon::FileNotWritable, e.message
155
+ end
156
+
157
+ def colorize(str, color_code)
158
+ return str unless Teaspoon.configuration.color || @output_file
159
+ "\e[#{color_code}m#{str}\e[0m"
160
+ end
161
+
162
+ def pluralize(str, value)
163
+ value == 1 ? "#{value} #{str}" : "#{value} #{str}s"
164
+ end
165
+
166
+ def filename(file)
167
+ file.gsub(%r(^http://127.0.0.1:\d+/assets/), "").gsub(/[\?|&]?body=1/, "")
168
+ end
169
+ end
170
+ end
171
+ end
@@ -1,13 +1,11 @@
1
- require 'teaspoon/formatters/dot_formatter'
2
-
3
1
  module Teaspoon
4
2
  module Formatters
5
3
  class CleanFormatter < DotFormatter
6
4
 
5
+ private
6
+
7
7
  def log_failed_examples
8
- log "\n" if failures.size > 0
9
8
  end
10
-
11
9
  end
12
10
  end
13
11
  end
@@ -0,0 +1,60 @@
1
+ require "teaspoon/formatters/modules/report_module"
2
+
3
+ module Teaspoon
4
+ module Formatters
5
+ class DocumentationFormatter < Base
6
+ include ReportModule
7
+
8
+ protected
9
+
10
+ def initialize(*args)
11
+ @level = 0
12
+ super
13
+ end
14
+
15
+ def log_suite(result)
16
+ log_indent_line(result.label, result.level)
17
+ @level = result.level
18
+ end
19
+
20
+ def log_passing_spec(result)
21
+ log_indent_spec(result.label, GREEN)
22
+ end
23
+
24
+ def log_pending_spec(result)
25
+ log_indent_spec("#{result.label} (PENDING)", YELLOW)
26
+ end
27
+
28
+ def log_failing_spec(result)
29
+ log_indent_spec("#{result.label} (FAILED - #{@failures.length})", RED)
30
+ end
31
+
32
+ def log_result(result)
33
+ log_line
34
+ super
35
+ end
36
+
37
+ private
38
+
39
+ def log_indent_spec(str, color)
40
+ log_indent_line(str, level = (@last_suite ? @level + 1 : 0), color)
41
+ log_intent_stdout(level + 1)
42
+ end
43
+
44
+ def log_intent_stdout(level)
45
+ return if @stdout.blank?
46
+ log_indent_line("# #{@stdout.gsub(/\n$/, "").gsub("\n", "\n# ")}", level, CYAN)
47
+ end
48
+
49
+ def log_indent_line(str = "", level = nil, color = nil)
50
+ log_line(indent(str, level || @level), color)
51
+ end
52
+
53
+ def indent(str = "", level = nil)
54
+ indent = "#{" " * level}"
55
+ str.gsub!("\n", "\n#{indent}")
56
+ "#{indent}#{str}"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,103 +1,25 @@
1
- require 'teaspoon/formatters/base_formatter'
1
+ require "teaspoon/formatters/modules/report_module"
2
2
 
3
3
  module Teaspoon
4
4
  module Formatters
5
- class DotFormatter < BaseFormatter
6
-
7
- RED = 31
8
- GREEN = 32
9
- YELLOW = 33
10
- CYAN = 36
11
-
12
- def spec(result, logged = false)
13
- super(result)
14
- return if logged
15
- if result.passing?
16
- log ".", GREEN
17
- elsif result.pending?
18
- log "*", YELLOW
19
- else
20
- log "F", RED
21
- end
22
- end
23
-
24
- # Errors are reported from the onError handler in Phantom, so they're not linked to a result
25
- def error(error)
26
- log "#{error["message"]}\n", RED
27
- for trace in error["trace"] || []
28
- log " # #{filename(trace["file"])}:#{trace["line"]}#{trace["function"].present? ? " -- #{trace["function"]}" : ""}\n", CYAN
29
- end
30
- log "\n"
31
- end
32
-
33
- def result(results)
34
- log "\n\n"
35
- log_information
36
- log_stats(results)
37
- log_failed_examples
38
- super
39
- end
5
+ class DotFormatter < Base
6
+ include ReportModule
40
7
 
41
8
  protected
42
9
 
43
- def log_information
44
- log_pending if pendings.size > 0
45
- log_failures if failures.size > 0
46
- end
47
-
48
- def log_pending
49
- log "Pending:\n"
50
- pendings.each do |result|
51
- log " #{result.description}\n", YELLOW
52
- log " # Not yet implemented\n\n", CYAN
53
- end
54
- end
55
-
56
- def log_failures
57
- log "Failures:\n\n"
58
- failures.each_with_index do |failure, index|
59
- log " #{index + 1}) #{failure.description}\n"
60
- log " Failure/Error: #{failure.message}\n\n", RED
61
- end
10
+ def log_spec(result)
11
+ return log_str(".", GREEN) if result.passing?
12
+ return log_str("*", YELLOW) if result.pending?
13
+ log_str("F", RED)
62
14
  end
63
15
 
64
- def log_stats(results)
65
- log "Finished in #{results["elapsed"]} seconds\n"
66
- stats = "#{pluralize("example", total)}, #{pluralize("failure", failures.size)}"
67
- stats << ", #{pendings.size} pending" if pendings.size > 0
68
- log "#{stats}\n", stats_color
69
- log "\n" unless failures.size == 0
16
+ def log_console(message)
17
+ log_str(message)
70
18
  end
71
19
 
72
- def log_failed_examples
73
- return if failures.size == 0
74
- log "Failed examples:\n\n"
75
- failures.each do |failure|
76
- log "teaspoon -s #{@suite_name} --filter=\"#{failure.link}\"\n", RED
77
- end
78
- end
79
-
80
- private
81
-
82
- def log(str, color_code = nil)
83
- STDOUT.print(color_code ? colorize(str, color_code) : str)
84
- end
85
-
86
- def colorize(str, color_code)
87
- return str unless Teaspoon.configuration.color
88
- "\e[#{color_code}m#{str}\e[0m"
89
- end
90
-
91
- def pluralize(str, value)
92
- value == 1 ? "#{value} #{str}" : "#{value} #{str}s"
93
- end
94
-
95
- def stats_color
96
- failures.size > 0 ? RED : pendings.size > 0 ? YELLOW : GREEN
97
- end
98
-
99
- def filename(file)
100
- file.gsub(%r(^http://127.0.0.1:\d+/assets/), "").gsub(/[\?|&]?body=1/, "")
20
+ def log_result(result)
21
+ log_line("\n")
22
+ super
101
23
  end
102
24
  end
103
25
  end
@@ -0,0 +1,36 @@
1
+ module Teaspoon
2
+ module Formatters
3
+ class JsonFormatter < Base
4
+
5
+ protected
6
+
7
+ def log_runner(result)
8
+ log_result(result)
9
+ end
10
+
11
+ def log_suite(result)
12
+ log_result(result)
13
+ end
14
+
15
+ def log_spec(result)
16
+ log_result(result)
17
+ end
18
+
19
+ def log_error(result)
20
+ log_result(result)
21
+ end
22
+
23
+ def log_exception(result)
24
+ log_result(result)
25
+ end
26
+
27
+ def log_console(message)
28
+ log_line(%Q{{"type":"console","log":"#{message.gsub(/\n$/, "").gsub("\n", "\\n")}"}})
29
+ end
30
+
31
+ def log_result(result)
32
+ log_str(result.original_json)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,59 +1,78 @@
1
- require 'teaspoon/formatters/base_formatter'
1
+ require "cgi"
2
2
 
3
3
  module Teaspoon
4
4
  module Formatters
5
- class JunitFormatter < BaseFormatter
5
+ class JunitFormatter < Base
6
6
 
7
- def runner(result)
8
- @count = result.total;
7
+ protected
9
8
 
10
- log "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
11
- log "<testsuites name=\"jasmine\"><testsuite name=\"#{result.suite}\" tests=\"#{@count}\">"
9
+ def log_runner(result)
10
+ log_line(%Q{<?xml version="1.0" encoding="UTF-8"?>})
11
+ log_line(%Q{<testsuites name="Teaspoon">})
12
+ log_line(%Q{<testsuite name="#{@suite_name}" tests="#{@total_count}" time="#{result.start}">})
12
13
  end
13
14
 
14
- def spec(result)
15
- super
16
- @result = result
17
- return passing_spec if result.passing?
18
- return pending_spec if result.pending?
19
- failing_spec
15
+ def log_suite(result)
16
+ log_end_suite
17
+ log_line(%Q{<testsuite name="#{result.label}">})
20
18
  end
21
19
 
22
- def error(error)
23
- @errors << error
20
+ def log_passing_spec(result)
21
+ log_junit_spec(suite: result.suite, label: result.label)
24
22
  end
25
23
 
26
- def result(result)
27
- log "</testsuite></testsuites>"
24
+ def log_pending_spec(result)
25
+ log_junit_spec(suite: result.suite, label: result.label) do
26
+ log_line(%Q{ <skipped/>})
27
+ end
28
28
  end
29
29
 
30
- def suppress_logs?
31
- false
30
+ def log_failing_spec(result)
31
+ log_junit_spec(suite: result.suite, label: result.label) do
32
+ log_line(%Q{ <failure type="AssertionFailed">#{cdata(result.message)}</failure>})
33
+ end
32
34
  end
33
35
 
34
- private
36
+ def log_result(result)
37
+ log_end_suite
38
+ end
35
39
 
36
- def passing_spec
37
- log %Q[<testcase classname="#{@result.suite}" name="#{@result.label}"></testcase>\n]
40
+ def log_coverage(message)
41
+ log_line(%Q{<testsuite name="Coverage summary" tests="0">\n<properties>#{cdata(message)}<properties>\n</testsuite>})
38
42
  end
39
43
 
40
- def pending_spec
41
- log %Q[<testcase classname="#{@result.suite}" name="#{@result.label}"><skipped /></testcase>\n]
44
+ def log_threshold_failure(message)
45
+ log_line(%Q{<testsuite name="Coverage thresholds" tests="1">})
46
+ log_junit_spec(suite: "Coverage thresholds", label: "were not met") do
47
+ log_line(%Q{ <failure type="AssertionFailed">#{cdata(message)}</failure>})
48
+ end
49
+ log_line(%Q{</testsuite>})
42
50
  end
43
51
 
44
- def failing_spec
45
- str = <<EOL;
46
- <testcase classname="#{@result.suite}" name="#{@result.label}">
47
- <failure type="AssertionFailed">#{@result.message}</failure>
48
- </testcase>\n
49
- EOL
50
- log str
52
+ def log_complete(failure_count)
53
+ log_line(%Q{</testsuite>\n</testsuites>})
51
54
  end
52
55
 
53
- def log(str)
54
- STDOUT.print("#{str}\n")
56
+ private
57
+
58
+ def log_end_suite
59
+ log_line(%Q{</testsuite>}) if @last_suite
55
60
  end
56
61
 
62
+ def log_junit_spec(opts, &block)
63
+ log_line(%Q{<testcase classname="#{escape(opts[:suite])}" name="#{escape(opts[:label])}">})
64
+ yield if block_given?
65
+ log_line(%Q{<system-out>#{cdata(@stdout)}</system-out>}) unless @stdout.blank?
66
+ log_line(%Q{</testcase>})
67
+ end
68
+
69
+ def escape(str)
70
+ CGI::escapeHTML(str)
71
+ end
72
+
73
+ def cdata(str)
74
+ "\n<![CDATA[\n#{str.gsub(/\n$/, "")}\n]]>\n"
75
+ end
57
76
  end
58
77
  end
59
78
  end