opal-rspec 0.5.0.beta2 → 0.5.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (281) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +23 -4
  4. data/CHANGELOG.md +22 -1
  5. data/Gemfile +10 -3
  6. data/README.md +142 -36
  7. data/Rakefile +101 -75
  8. data/config.ru +8 -6
  9. data/gemfiles/opal_master.gemfile +18 -0
  10. data/lib/opal/rspec.rb +6 -10
  11. data/lib/opal/rspec/cached_environment.rb +23 -0
  12. data/lib/opal/rspec/post_rack_locator.rb +20 -0
  13. data/lib/opal/rspec/pre_rack_locator.rb +68 -0
  14. data/lib/opal/rspec/rake_task.rb +97 -20
  15. data/lib/opal/rspec/sprockets_environment.rb +35 -0
  16. data/lib/opal/rspec/version.rb +1 -1
  17. data/opal-rspec.gemspec +9 -12
  18. data/opal/opal/rspec.rb +11 -8
  19. data/opal/opal/rspec/async.rb +1 -0
  20. data/opal/opal/rspec/async/async_example.rb +27 -18
  21. data/opal/opal/rspec/async/example_group.rb +23 -21
  22. data/opal/opal/rspec/async/hooks.rb +0 -36
  23. data/opal/opal/rspec/async/reporter.rb +9 -0
  24. data/opal/opal/rspec/fixes.rb +3 -10
  25. data/opal/opal/rspec/fixes/opal.rb +5 -0
  26. data/opal/opal/rspec/fixes/opal/class.rb +8 -0
  27. data/opal/opal/rspec/fixes/opal/compatibility.rb +228 -0
  28. data/opal/opal/rspec/fixes/opal/corelib.rb +3 -0
  29. data/opal/opal/rspec/fixes/opal/corelib/error.rb +61 -0
  30. data/opal/opal/rspec/fixes/opal/corelib/regexp.rb +92 -0
  31. data/opal/opal/rspec/fixes/opal/corelib/struct.rb +260 -0
  32. data/opal/opal/rspec/fixes/opal/kernel.rb +80 -0
  33. data/opal/opal/rspec/fixes/opal/stdlib.rb +2 -0
  34. data/opal/opal/rspec/fixes/opal/stdlib/pp.rb +23 -0
  35. data/opal/opal/rspec/fixes/opal/stdlib/set.rb +36 -0
  36. data/opal/opal/rspec/fixes/rspec.rb +7 -0
  37. data/opal/opal/rspec/fixes/{caller_filter.rb → rspec/caller_filter.rb} +0 -0
  38. data/opal/opal/rspec/fixes/rspec/core.rb +9 -0
  39. data/opal/opal/rspec/fixes/rspec/core/configuration.rb +11 -0
  40. data/opal/opal/rspec/fixes/{example.rb → rspec/core/example.rb} +1 -1
  41. data/opal/opal/rspec/fixes/rspec/core/example_group.rb +9 -0
  42. data/opal/opal/rspec/fixes/rspec/core/formatters.rb +6 -0
  43. data/opal/opal/rspec/fixes/rspec/core/formatters/backtrace_formatter.rb +20 -0
  44. data/opal/opal/rspec/fixes/rspec/core/formatters/console_codes.rb +11 -0
  45. data/opal/opal/rspec/fixes/rspec/core/formatters/deprecation_formatter.rb +20 -0
  46. data/opal/opal/rspec/fixes/rspec/core/formatters/generated_deprecation_message.rb +15 -0
  47. data/opal/opal/rspec/fixes/rspec/core/formatters/json_formatter.rb +10 -0
  48. data/opal/opal/rspec/fixes/rspec/core/formatters/loader.rb +38 -0
  49. data/opal/opal/rspec/fixes/rspec/core/metadata.rb +39 -0
  50. data/opal/opal/rspec/fixes/rspec/core/notifications.rb +3 -0
  51. data/opal/opal/rspec/fixes/rspec/core/notifications/examples_notification.rb +30 -0
  52. data/opal/opal/rspec/fixes/rspec/core/notifications/failed_example_notification.rb +20 -0
  53. data/opal/opal/rspec/fixes/rspec/core/notifications/summary_notification.rb +26 -0
  54. data/opal/opal/rspec/fixes/rspec/core/ordering.rb +1 -0
  55. data/opal/opal/rspec/fixes/rspec/core/ordering/random.rb +13 -0
  56. data/opal/opal/rspec/fixes/rspec/core/reporter.rb +14 -0
  57. data/opal/opal/rspec/fixes/rspec/core/warnings.rb +18 -0
  58. data/opal/opal/rspec/fixes/rspec/example_groups.rb +49 -0
  59. data/opal/opal/rspec/fixes/rspec/expectations.rb +2 -0
  60. data/opal/opal/rspec/fixes/{expectations.rb → rspec/expectations/fail_with.rb} +0 -0
  61. data/opal/opal/rspec/fixes/rspec/expectations/syntax.rb +25 -0
  62. data/opal/opal/rspec/fixes/rspec/matchers.rb +2 -0
  63. data/opal/opal/rspec/fixes/rspec/matchers/built_in.rb +4 -0
  64. data/opal/opal/rspec/fixes/rspec/matchers/built_in/all.rb +10 -0
  65. data/opal/opal/rspec/fixes/rspec/matchers/built_in/compound.rb +15 -0
  66. data/opal/opal/rspec/fixes/rspec/matchers/built_in/start_and_end_with.rb +42 -0
  67. data/opal/opal/rspec/fixes/rspec/matchers/built_in/yield.rb +21 -0
  68. data/opal/opal/rspec/fixes/{matchers.rb → rspec/matchers/pretty.rb} +0 -0
  69. data/opal/opal/rspec/fixes/rspec/mocks.rb +4 -0
  70. data/opal/opal/rspec/fixes/rspec/mocks/error_generator.rb +40 -0
  71. data/opal/opal/rspec/fixes/rspec/mocks/space.rb +37 -0
  72. data/opal/opal/rspec/fixes/rspec/mocks/test_double.rb +39 -0
  73. data/opal/opal/rspec/fixes/rspec/mocks/verifying_double.rb +29 -0
  74. data/opal/opal/rspec/fixes/rspec/support.rb +4 -0
  75. data/opal/opal/rspec/fixes/rspec/support/encoded_string.rb +10 -0
  76. data/opal/opal/rspec/fixes/rspec/support/fuzzy_matcher.rb +23 -0
  77. data/opal/opal/rspec/fixes/rspec/support/recursive_const_methods.rb +7 -0
  78. data/opal/opal/rspec/fixes/rspec/support/ruby_features.rb +8 -0
  79. data/opal/opal/rspec/fixes/rspec/support/warnings.rb +18 -0
  80. data/opal/opal/rspec/formatter/browser_formatter.rb +38 -0
  81. data/opal/opal/rspec/formatter/document_io.rb +27 -0
  82. data/opal/opal/rspec/formatter/element.rb +88 -0
  83. data/opal/opal/rspec/formatter/html_printer.rb +109 -0
  84. data/opal/opal/rspec/formatter/noop_flush_string_io.rb +9 -0
  85. data/opal/opal/rspec/formatter/opal_closed_tty_io.rb +27 -0
  86. data/opal/opal/rspec/pre_require_fixes.rb +7 -0
  87. data/opal/opal/rspec/requires.rb +32 -0
  88. data/opal/opal/rspec/runner.rb +71 -53
  89. data/opal/opal/rspec/spec_opts.rb.erb +28 -0
  90. data/opal/opal/rspec/sprockets_runner.rb.erb +5 -3
  91. data/spec/mri/integration/browser_spec.rb +31 -0
  92. data/spec/mri/integration/rack/sprockets_runner_js_errors.rb.erb +20 -0
  93. data/spec/mri/integration/spec_opts_spec.rb +81 -0
  94. data/spec/mri/unit/opal/rspec/browser_formatter_spec.rb +35 -0
  95. data/spec/mri/unit/opal/rspec/cached_environment_spec.rb +103 -0
  96. data/spec/mri/unit/opal/rspec/opal/browser_formatter_spec.rb +14 -0
  97. data/spec/mri/unit/opal/rspec/rack/config.ru +12 -0
  98. data/spec/mri/unit/opal/rspec/rake_task_spec.rb +245 -0
  99. data/spec/mri/unit/opal/rspec/sprockets_environment_spec.rb +94 -0
  100. data/spec/mri/unit/opal/rspec/temp_dir_helper.rb +19 -0
  101. data/spec/{after_hooks_spec.rb → opal/after_hooks_spec.rb} +0 -0
  102. data/spec/{around_hooks_spec.rb → opal/around_hooks_spec.rb} +46 -105
  103. data/spec/{async_spec.rb → opal/async_spec.rb} +0 -0
  104. data/spec/{before_hooks_spec.rb → opal/before_hooks_spec.rb} +0 -0
  105. data/spec/{example_spec.rb → opal/example_spec.rb} +0 -0
  106. data/spec/opal/expected_failures.txt +40 -0
  107. data/spec/{matchers_spec.rb → opal/matchers_spec.rb} +0 -0
  108. data/spec/{mock_spec.rb → opal/mock_spec.rb} +0 -0
  109. data/spec/{should_syntax_spec.rb → opal/should_syntax_spec.rb} +0 -0
  110. data/spec/{skip_pending_spec.rb → opal/skip_pending_spec.rb} +0 -0
  111. data/spec/{subject_spec.rb → opal/subject_spec.rb} +16 -16
  112. data/spec/other/color_on_by_default_spec.rb +9 -0
  113. data/spec/other/dummy_spec.rb +5 -0
  114. data/spec/other/formatter_dependency.rb +3 -0
  115. data/spec/other/ignored_spec.opal +5 -0
  116. data/spec/other/test_formatter.rb +9 -0
  117. data/spec/rspec/core/config.rb +5 -0
  118. data/spec/rspec/core/config.ru +4 -0
  119. data/spec/rspec/core/core_spec_loader.rb +42 -0
  120. data/spec/rspec/core/filter/core/async/example_group.txt +13 -0
  121. data/spec/rspec/core/filter/core/async/hooks.rb +12 -0
  122. data/spec/rspec/core/filter/core/async/memoized_helpers.txt +3 -0
  123. data/spec/rspec/core/filter/core/async/metadata.txt +2 -0
  124. data/spec/rspec/core/filter/core/bugs/filter_manager.txt +4 -0
  125. data/spec/rspec/core/filter/core/bugs/formatters.txt +4 -0
  126. data/spec/rspec/core/filter/core/bugs/memoized_helpers.rb +11 -0
  127. data/spec/rspec/core/filter/core/bugs/metadata.txt +5 -0
  128. data/spec/rspec/core/filter/core/bugs/sandbox/subject_issue_test.rb +328 -0
  129. data/spec/rspec/core/filter/core/bugs/warnings_deprecations.txt +3 -0
  130. data/spec/rspec/core/filter/core/unsupported/core.txt +5 -0
  131. data/spec/rspec/core/filter/core/unsupported/example.txt +7 -0
  132. data/spec/rspec/core/filter/core/unsupported/example_group.txt +13 -0
  133. data/spec/rspec/core/filter/core/unsupported/filter_manager.txt +7 -0
  134. data/spec/rspec/core/filter/core/unsupported/formatters.txt +27 -0
  135. data/spec/rspec/core/filter/core/unsupported/hooks.txt +2 -0
  136. data/spec/rspec/core/filter/core/unsupported/memoized_helpers.txt +6 -0
  137. data/spec/rspec/core/filter/core/unsupported/metadata.txt +14 -0
  138. data/spec/rspec/core/filter/core/unsupported/metadata_filter.txt +2 -0
  139. data/spec/rspec/core/filter/core/unsupported/notifications.txt +8 -0
  140. data/spec/rspec/core/filter/core/unsupported/world.txt +3 -0
  141. data/spec/rspec/core/fixes/missing_constants.rb +20 -0
  142. data/spec/rspec/core/fixes/opal_itself.rb +38 -0
  143. data/spec/rspec/core/fixes/shared_examples.rb +3 -0
  144. data/spec/rspec/core/opal_alternates/rspec/core/example_group_spec.rb +145 -0
  145. data/spec/rspec/core/opal_alternates/rspec/core/failed_example_notification_spec.rb +31 -0
  146. data/spec/rspec/core/opal_alternates/rspec/core/hooks_spec.rb +113 -0
  147. data/spec/rspec/core/opal_alternates/rspec/core/memoized_helpers_spec.rb +36 -0
  148. data/spec/rspec/core/opal_alternates/rspec/core/metadata_spec.rb +48 -0
  149. data/spec/rspec/core/require_specs.rb +25 -0
  150. data/spec/rspec/core/sandboxing.rb +72 -0
  151. data/spec/rspec/core/spec_files_exclude.txt +41 -0
  152. data/spec/rspec/expectations/config.rb +16 -0
  153. data/spec/rspec/expectations/config.ru +4 -0
  154. data/spec/rspec/expectations/expectation_spec_loader.rb +106 -0
  155. data/spec/rspec/expectations/filter/bugs/aliased_matcher.txt +2 -0
  156. data/spec/rspec/expectations/filter/bugs/aliases.rb +13 -0
  157. data/spec/rspec/expectations/filter/bugs/base_matcher.txt +2 -0
  158. data/spec/rspec/expectations/filter/bugs/be.rb +4 -0
  159. data/spec/rspec/expectations/filter/bugs/be_instance_of.rb +7 -0
  160. data/spec/rspec/expectations/filter/bugs/be_spec.txt +2 -0
  161. data/spec/rspec/expectations/filter/bugs/configuration.txt +8 -0
  162. data/spec/rspec/expectations/filter/bugs/contain_exactly.rb +13 -0
  163. data/spec/rspec/expectations/filter/bugs/define_negated_matcher.rb +9 -0
  164. data/spec/rspec/expectations/filter/bugs/description_generation.rb +4 -0
  165. data/spec/rspec/expectations/filter/bugs/dsl.txt +14 -0
  166. data/spec/rspec/expectations/filter/bugs/equal.txt +3 -0
  167. data/spec/rspec/expectations/filter/bugs/expectation_target.txt +2 -0
  168. data/spec/rspec/expectations/filter/bugs/expectations.txt +2 -0
  169. data/spec/rspec/expectations/filter/bugs/have_attributes.rb +8 -0
  170. data/spec/rspec/expectations/filter/bugs/include.rb +4 -0
  171. data/spec/rspec/expectations/filter/bugs/operators.txt +2 -0
  172. data/spec/rspec/expectations/filter/bugs/raise_error.txt +2 -0
  173. data/spec/rspec/expectations/filter/bugs/respond_to.rb +13 -0
  174. data/spec/rspec/expectations/filter/bugs/sandbox/undef.rb +20 -0
  175. data/spec/rspec/expectations/filter/unsupported/aliases.txt +5 -0
  176. data/spec/rspec/expectations/filter/unsupported/be.txt +2 -0
  177. data/spec/rspec/expectations/filter/unsupported/be_instance_of.txt +3 -0
  178. data/spec/rspec/expectations/filter/unsupported/change.txt +2 -0
  179. data/spec/rspec/expectations/filter/unsupported/configuration.txt +2 -0
  180. data/spec/rspec/expectations/filter/unsupported/contain_exactly.txt +2 -0
  181. data/spec/rspec/expectations/filter/unsupported/description_generation.txt +6 -0
  182. data/spec/rspec/expectations/filter/unsupported/dsl.txt +8 -0
  183. data/spec/rspec/expectations/filter/unsupported/eq.txt +10 -0
  184. data/spec/rspec/expectations/filter/unsupported/equal.txt +3 -0
  185. data/spec/rspec/expectations/filter/unsupported/expectation_target.txt +2 -0
  186. data/spec/rspec/expectations/filter/unsupported/expectations.txt +8 -0
  187. data/spec/rspec/expectations/filter/unsupported/has.txt +2 -0
  188. data/spec/rspec/expectations/filter/unsupported/include.txt +3 -0
  189. data/spec/rspec/expectations/filter/unsupported/match.txt +2 -0
  190. data/spec/rspec/expectations/filter/unsupported/matchers.txt +11 -0
  191. data/spec/rspec/expectations/filter/unsupported/output.txt +14 -0
  192. data/spec/rspec/expectations/filter/unsupported/raise_error.txt +3 -0
  193. data/spec/rspec/expectations/filter/unsupported/respond_to.rb +5 -0
  194. data/spec/rspec/expectations/filter/unsupported/syntax.txt +3 -0
  195. data/spec/rspec/expectations/filter/unsupported/yield.txt +2 -0
  196. data/spec/rspec/expectations/fixes/example_patches.rb +32 -0
  197. data/spec/rspec/expectations/fixes/missing_constants.rb +12 -0
  198. data/spec/rspec/expectations/fixes/not_compatible.rb +6 -0
  199. data/spec/rspec/expectations/fixes/opal_itself.rb +140 -0
  200. data/spec/rspec/expectations/opal_alternates/be_instance_of_spec.rb +11 -0
  201. data/spec/rspec/expectations/opal_alternates/dsl_spec.rb +66 -0
  202. data/spec/rspec/expectations/opal_alternates/expectation_target_spec.rb +21 -0
  203. data/spec/rspec/expectations/opal_alternates/yield_spec.rb +11 -0
  204. data/spec/rspec/expectations/require_specs.rb +16 -0
  205. data/spec/rspec/expectations/shared_examples.rb +47 -0
  206. data/spec/rspec/expectations/spec_files_exclude.txt +2 -0
  207. data/spec/rspec/expectations/spec_helper_opal.rb +13 -0
  208. data/spec/rspec/filter_processor.rb +77 -0
  209. data/spec/rspec/mocks/config.ru +4 -0
  210. data/spec/rspec/mocks/filter/bugs/and_call_original.txt +9 -0
  211. data/spec/rspec/mocks/filter/bugs/and_wrap_original.txt +2 -0
  212. data/spec/rspec/mocks/filter/bugs/any_instance.rb +24 -0
  213. data/spec/rspec/mocks/filter/bugs/argument_matchers.rb +3 -0
  214. data/spec/rspec/mocks/filter/bugs/configuration.txt +2 -0
  215. data/spec/rspec/mocks/filter/bugs/double.txt +3 -0
  216. data/spec/rspec/mocks/filter/bugs/expiration.txt +2 -0
  217. data/spec/rspec/mocks/filter/bugs/instance_method_stasher.txt +2 -0
  218. data/spec/rspec/mocks/filter/bugs/methods.rb +5 -0
  219. data/spec/rspec/mocks/filter/bugs/mocks.txt +6 -0
  220. data/spec/rspec/mocks/filter/bugs/mutate_const.txt +2 -0
  221. data/spec/rspec/mocks/filter/bugs/partial_double.rb +8 -0
  222. data/spec/rspec/mocks/filter/bugs/receive.txt +5 -0
  223. data/spec/rspec/mocks/filter/bugs/should_syntax.txt +5 -0
  224. data/spec/rspec/mocks/filter/bugs/space.txt +2 -0
  225. data/spec/rspec/mocks/filter/bugs/spy.txt +5 -0
  226. data/spec/rspec/mocks/filter/bugs/stub_implementation.rb +9 -0
  227. data/spec/rspec/mocks/filter/unsupported/and_call_original.txt +5 -0
  228. data/spec/rspec/mocks/filter/unsupported/and_return.txt +2 -0
  229. data/spec/rspec/mocks/filter/unsupported/any_instance.rb +6 -0
  230. data/spec/rspec/mocks/filter/unsupported/argument_matchers.rb +10 -0
  231. data/spec/rspec/mocks/filter/unsupported/combining_implementation_instructions.rb +9 -0
  232. data/spec/rspec/mocks/filter/unsupported/double.rb +16 -0
  233. data/spec/rspec/mocks/filter/unsupported/expected_arg_verification.txt +2 -0
  234. data/spec/rspec/mocks/filter/unsupported/have_received.txt +2 -0
  235. data/spec/rspec/mocks/filter/unsupported/instance_double_with_class_loaded.txt +8 -0
  236. data/spec/rspec/mocks/filter/unsupported/mocks.rb +8 -0
  237. data/spec/rspec/mocks/filter/unsupported/nil_expectation_warning.rb +8 -0
  238. data/spec/rspec/mocks/filter/unsupported/partial_double.rb +6 -0
  239. data/spec/rspec/mocks/filter/unsupported/receive.txt +13 -0
  240. data/spec/rspec/mocks/filter/unsupported/receive_message_chain.rb +4 -0
  241. data/spec/rspec/mocks/filter/unsupported/receive_messages.txt +2 -0
  242. data/spec/rspec/mocks/filter/unsupported/should_syntax.txt +1 -0
  243. data/spec/rspec/mocks/filter/unsupported/space.rb +7 -0
  244. data/spec/rspec/mocks/filter/unsupported/stub.rb +7 -0
  245. data/spec/rspec/mocks/fixes/doubled_classes.rb +76 -0
  246. data/spec/rspec/mocks/fixes/missing_constants.rb +3 -0
  247. data/spec/rspec/mocks/fixes/opal_itself.rb +59 -0
  248. data/spec/rspec/mocks/mocks_spec_loader.rb +87 -0
  249. data/spec/rspec/mocks/require_specs.rb +15 -0
  250. data/spec/rspec/mocks/spec_files_exclude.txt +11 -0
  251. data/spec/rspec/mocks/spec_helper_opal.rb +129 -0
  252. data/spec/rspec/opal_rspec_spec_loader.rb +349 -0
  253. data/spec/rspec/shared/opal/fixes/deprecation_helpers.rb +31 -0
  254. data/spec/rspec/shared/opal/fixes/rspec_helpers.rb +6 -0
  255. data/spec/rspec/shared/opal/progress_json_formatter.rb +29 -0
  256. data/spec/rspec/support/config.rb +5 -0
  257. data/spec/rspec/support/config.ru +4 -0
  258. data/spec/rspec/support/filter/bugs/recursive_const_methods.txt +3 -0
  259. data/spec/rspec/support/filter/bugs/sandbox/basic_object.rb +30 -0
  260. data/spec/rspec/support/filter/bugs/stderr_splitter_spec.txt +2 -0
  261. data/spec/rspec/support/filter/bugs/support.txt +2 -0
  262. data/spec/rspec/support/filter/unsupported/fuzzy_matcher.txt +2 -0
  263. data/spec/rspec/support/filter/unsupported/support.rb +7 -0
  264. data/spec/rspec/support/filter/unsupported/warnings.txt +6 -0
  265. data/spec/rspec/support/fixes/missing_constants.rb +3 -0
  266. data/spec/rspec/support/fixes/opal_itself.rb +13 -0
  267. data/spec/rspec/support/require_specs.rb +15 -0
  268. data/spec/rspec/support/spec_files_exclude.txt +26 -0
  269. data/spec/rspec/support/spec_helper.rb +27 -0
  270. data/spec/rspec/support/support_spec_loader.rb +34 -0
  271. data/util/create_requires.rb +6 -2
  272. data/vendor/spec_runner.js +14 -0
  273. metadata +255 -43
  274. data/opal/opal/rspec/browser_formatter.rb +0 -225
  275. data/opal/opal/rspec/fixes/example_groups.rb +0 -32
  276. data/opal/opal/rspec/fixes/formatter.rb +0 -62
  277. data/opal/opal/rspec/fixes/kernel.rb +0 -48
  278. data/opal/opal/rspec/fixes/mocks.rb +0 -13
  279. data/opal/opal/rspec/fixes/reporter.rb +0 -12
  280. data/opal/opal/rspec/text_formatter.rb +0 -88
  281. data/spec_mri/integration/browser_spec.rb +0 -37
@@ -0,0 +1,109 @@
1
+ require_relative 'noop_flush_string_io'
2
+ require_relative 'element'
3
+
4
+ module Opal
5
+ module RSpec
6
+ class HtmlPrinter < ::RSpec::Core::Formatters::HtmlPrinter
7
+ def initialize(output)
8
+ super
9
+ @group_stack = []
10
+ @update_stack = []
11
+ end
12
+
13
+ def print_html_start
14
+ # Will output the header
15
+ super
16
+ # Now close out the doc so we can use DOM manipulation for the rest
17
+ @output.puts "</div>"
18
+ @output.puts "</div>"
19
+ @output.puts "</body>"
20
+ @output.puts "</html>"
21
+ @output.close
22
+ # From here, we'll do more direct DOM manipulation
23
+ reset_output
24
+ @root_node = Element.klass 'results'
25
+ end
26
+
27
+ def flush_output
28
+ node = @group_stack.last ? @group_stack.last : @root_node
29
+ new_node = Element.from_string(@output.string)
30
+ node.append new_node
31
+ reset_output
32
+ end
33
+
34
+ def reset_output
35
+ @output = NoopFlushStringIO.new
36
+ end
37
+
38
+ def print_example_group_start(group_id, description, number_of_parents)
39
+ super
40
+ @output.puts '</dl></div>'
41
+ parent_node = @group_stack.last ? @group_stack.last : @root_node
42
+ new_node = Element.from_string(@output.string)
43
+ reset_output
44
+ parent_node << new_node
45
+ @group_stack << new_node.get_child_by_tag_name('dl')
46
+ # We won't have this in the DOM until group ends, so need to queue up yellow/red updates
47
+ @update_stack << []
48
+ end
49
+
50
+ def print_example_group_end
51
+ @group_stack.pop
52
+ @update_stack.pop.each(&:call)
53
+ end
54
+
55
+ def print_example_passed(description, run_time)
56
+ super
57
+ flush_output
58
+ end
59
+
60
+ def print_example_failed(pending_fixed, description, run_time, failure_id, exception, extra_content, escape_backtrace=false)
61
+ super
62
+ flush_output
63
+ end
64
+
65
+ def print_example_pending(description, pending_message)
66
+ super
67
+ flush_output
68
+ end
69
+
70
+ def print_summary(duration, example_count, failure_count, pending_count)
71
+ # string mutation
72
+ totals = "#{example_count} example#{'s' unless example_count == 1}, "
73
+ totals += "#{failure_count} failure#{'s' unless failure_count == 1}"
74
+ totals += ", #{pending_count} pending" if pending_count > 0
75
+
76
+ formatted_duration = "%.5f" % duration
77
+ Element.id('duration').html = "Finished in <strong>#{formatted_duration} seconds</strong>"
78
+ Element.id('totals').html = totals
79
+ end
80
+
81
+ # Directly manipulate scripts here
82
+ def move_progress(percent_done)
83
+ `moveProgressBar(#{percent_done})`
84
+ end
85
+
86
+ def make_header_red
87
+ `makeRed('rspec-header')`
88
+ end
89
+
90
+ def make_header_yellow
91
+ `makeYellow('rspec-header')`
92
+ end
93
+
94
+ def make_example_group_header_red(group_id)
95
+ @update_stack.last << lambda do
96
+ `makeRed(#{"div_group_#{group_id}"})`
97
+ `makeRed(#{"example_group_#{group_id}"})`
98
+ end
99
+ end
100
+
101
+ def make_example_group_header_yellow(group_id)
102
+ @update_stack.last << lambda do
103
+ `makeYellow(#{"div_group_#{group_id}"})`
104
+ `makeYellow(#{"example_group_#{group_id}"})`
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,9 @@
1
+ module Opal
2
+ module RSpec
3
+ class NoopFlushStringIO < StringIO
4
+ # make printer happy
5
+ def flush
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ class OpalClosedTtyIO < IO
2
+ include IO::Writable
3
+
4
+ def initialize(runner_type, io_type)
5
+ raise "Unknown IO type #{io_type}!" unless [:stdout, :stderr].include?(io_type)
6
+ self.write_proc = case runner_type
7
+ when :phantom
8
+ `function(str){callPhantom([#{io_type}, str])}`
9
+ when :node, :browser
10
+ # opal io is already node aware, browser works as well, but we can't do anything about puts vs. print with the browser
11
+ case io_type
12
+ when :stdout
13
+ $stdout.write_proc
14
+ when :stderr
15
+ $stderr.write_proc
16
+ end
17
+ else
18
+ raise "Unknown runner type #{runner_type}"
19
+ end
20
+ @tty = true
21
+ end
22
+
23
+ # We're deferring to stdout here, which doesn't need to be closed, but RSpec::BaseTextFormatter doesn't know that, so override this
24
+ def closed?
25
+ true
26
+ end
27
+ end
@@ -2,3 +2,10 @@
2
2
  RUBY_DESCRIPTION = RUBY_VERSION unless defined?(RUBY_DESCRIPTION)
3
3
 
4
4
  class SecurityError < Exception; end unless defined?(SecurityError)
5
+
6
+ # This completely changes the struct class, so need it before RSpec runs
7
+ require_relative 'fixes/opal/compatibility'
8
+ require_relative 'fixes/opal/corelib/struct'
9
+
10
+ # RSpec code changes based on this
11
+ require_relative 'fixes/rspec/support/ruby_features'
@@ -7,6 +7,7 @@ require 'diff/lcs/change'
7
7
  require 'diff/lcs/hunk'
8
8
  require 'diff/lcs/internals'
9
9
  require 'erb'
10
+ require 'json'
10
11
  require 'optparse'
11
12
  require 'pathname'
12
13
  require 'pp'
@@ -25,9 +26,14 @@ require 'rspec/core/filter_manager'
25
26
  require 'rspec/core/flat_map'
26
27
  require 'rspec/core/formatters'
27
28
  require 'rspec/core/formatters/base_formatter'
29
+ require 'rspec/core/formatters/base_text_formatter'
30
+ require 'rspec/core/formatters/console_codes'
28
31
  require 'rspec/core/formatters/deprecation_formatter'
32
+ require 'rspec/core/formatters/documentation_formatter'
29
33
  require 'rspec/core/formatters/helpers'
30
34
  require 'rspec/core/formatters/html_printer'
35
+ require 'rspec/core/formatters/json_formatter'
36
+ require 'rspec/core/formatters/progress_formatter'
31
37
  require 'rspec/core/hooks'
32
38
  require 'rspec/core/memoized_helpers'
33
39
  require 'rspec/core/metadata'
@@ -54,7 +60,33 @@ require 'rspec/expectations/version'
54
60
  require 'rspec/matchers'
55
61
  require 'rspec/matchers/aliased_matcher'
56
62
  require 'rspec/matchers/built_in'
63
+ require 'rspec/matchers/built_in/all'
57
64
  require 'rspec/matchers/built_in/base_matcher'
65
+ require 'rspec/matchers/built_in/be'
66
+ require 'rspec/matchers/built_in/be_between'
67
+ require 'rspec/matchers/built_in/be_instance_of'
68
+ require 'rspec/matchers/built_in/be_kind_of'
69
+ require 'rspec/matchers/built_in/be_within'
70
+ require 'rspec/matchers/built_in/change'
71
+ require 'rspec/matchers/built_in/compound'
72
+ require 'rspec/matchers/built_in/contain_exactly'
73
+ require 'rspec/matchers/built_in/cover'
74
+ require 'rspec/matchers/built_in/eq'
75
+ require 'rspec/matchers/built_in/eql'
76
+ require 'rspec/matchers/built_in/equal'
77
+ require 'rspec/matchers/built_in/exist'
78
+ require 'rspec/matchers/built_in/has'
79
+ require 'rspec/matchers/built_in/have_attributes'
80
+ require 'rspec/matchers/built_in/include'
81
+ require 'rspec/matchers/built_in/match'
82
+ require 'rspec/matchers/built_in/operators'
83
+ require 'rspec/matchers/built_in/output'
84
+ require 'rspec/matchers/built_in/raise_error'
85
+ require 'rspec/matchers/built_in/respond_to'
86
+ require 'rspec/matchers/built_in/satisfy'
87
+ require 'rspec/matchers/built_in/start_and_end_with'
88
+ require 'rspec/matchers/built_in/throw_symbol'
89
+ require 'rspec/matchers/built_in/yield'
58
90
  require 'rspec/matchers/composable'
59
91
  require 'rspec/matchers/dsl'
60
92
  require 'rspec/matchers/generated_descriptions'
@@ -1,72 +1,90 @@
1
- module Opal
2
- module RSpec
3
- class Runner
1
+ require_relative 'formatter/opal_closed_tty_io'
4
2
 
5
- class << self
6
- def browser?
7
- `typeof(document) !== "undefined"`
8
- end
9
-
10
- def phantom?
11
- `typeof(phantom) !== 'undefined' || typeof(OPAL_SPEC_PHANTOM) !== 'undefined'`
12
- end
13
-
14
- def default_formatter
15
- if phantom?
16
- TextFormatter
17
- else # browser
18
- BrowserFormatter
19
- end
20
- end
3
+ module ::RSpec::Core
4
+ class Runner
5
+ class << self
6
+ def browser?
7
+ `typeof(document) !== "undefined"`
8
+ end
21
9
 
22
- def autorun
23
- Runner.new.run
24
- end
10
+ def phantom?
11
+ `typeof(phantom) !== 'undefined' || typeof(OPAL_SPEC_PHANTOM) !== 'undefined'`
25
12
  end
26
13
 
27
- def initialize(options = {})
28
- @options = options
29
- @world = ::RSpec.world
30
- @configuration = ::RSpec.configuration
14
+ def node?
15
+ `typeof(process) !== 'undefined' && typeof(process.versions) !== 'undefined'`
31
16
  end
32
17
 
33
- def run(err=$stdout, out=$stdout)
34
- @configuration.error_stream = err
35
- @configuration.output_stream ||= out
18
+ def non_browser?
19
+ phantom? || node?
20
+ end
36
21
 
37
- self.start
38
- run_examples.then do
39
- self.finish
40
- end
22
+ def get_opal_closed_tty_io
23
+ runner_type = if phantom?
24
+ :phantom
25
+ elsif node?
26
+ :node
27
+ else
28
+ :browser
29
+ end
30
+ std_out = OpalClosedTtyIO.new runner_type,
31
+ :stdout
32
+ std_err = OpalClosedTtyIO.new runner_type,
33
+ :stderr
34
+ [std_err, std_out]
41
35
  end
42
36
 
43
- def run_examples
44
- @world.example_groups.inject(Promise.value) do |previous_promise, group|
45
- previous_promise.then do
46
- group.run @reporter
47
- end
48
- end
49
- end
37
+ def autorun
38
+ # see NoCarriageReturnIO source for why this is being done (not on Node though)
39
+ err, out = get_opal_closed_tty_io
40
+ # Have to do this in 2 places. This will ensure the default formatter gets the right IO, but need to do this in config for custom formatters
41
+ # that will be constructed BEFORE this runs, see rspec.rb
42
+ run(ARGV, err, out).then do |status|
43
+ exit_with_code status.to_i
44
+ end
45
+ end
50
46
 
51
- def config_hook(hook_when)
52
- hook_context = ::RSpec::Core::SuiteHookContext.new
53
- @configuration.hooks.run(hook_when, :suite, hook_context)
47
+ def exit_with_code(code)
48
+ # have to ignore OPAL_SPEC_PHANTOM for this one
49
+ if `typeof(phantom) !== "undefined"`
50
+ `phantom_exit(#{code})`
51
+ elsif node?
52
+ `process.exit(#{code})`
53
+ else
54
+ `Opal.global.OPAL_SPEC_CODE = #{code}`
55
+ end
54
56
  end
55
57
 
56
- def config_hook(hook_when)
57
- hook_context = ::RSpec::Core::SuiteHookContext.new
58
- @configuration.hooks.run(hook_when, :suite, hook_context)
58
+ def run(args, err=$stderr, out=$stdout)
59
+ options = ConfigurationOptions.new(args)
60
+ new(options).run(err, out)
59
61
  end
62
+ end
60
63
 
61
- def start
62
- @reporter = @configuration.reporter
63
- @reporter.start(@world.example_count)
64
- config_hook :before
64
+ def run_groups_async(example_groups, reporter)
65
+ results = []
66
+ last_promise = example_groups.inject(Promise.value(true)) do |previous_promise, group|
67
+ previous_promise.then do |result|
68
+ results << result
69
+ group.run reporter
70
+ end
71
+ end
72
+ last_promise.then do |result|
73
+ results << result
74
+ results.all? ? 0 : @configuration.failure_exit_code
65
75
  end
76
+ end
66
77
 
67
- def finish
68
- config_hook :after
69
- @reporter.finish
78
+ def run_specs(example_groups)
79
+ @configuration.reporter.report_async(@world.example_count(example_groups)) do |reporter|
80
+ hook_context = SuiteHookContext.new
81
+ Promise.value.then do
82
+ @configuration.hooks.run(:before, :suite, hook_context)
83
+ run_groups_async example_groups, reporter
84
+ end.ensure do |result|
85
+ @configuration.hooks.run(:after, :suite, hook_context)
86
+ result
87
+ end
70
88
  end
71
89
  end
72
90
  end
@@ -0,0 +1,28 @@
1
+ <%
2
+ spec_opts = ENV['SPEC_OPTS']
3
+ if spec_opts && !spec_opts.empty?
4
+ %>
5
+ RSpec.configure do |config|
6
+ <%
7
+ if (match = /--(no-)?color\b/.match(spec_opts))
8
+ color_value = !match.captures[0]
9
+ # Have to use instance_variable_set because config.color= is designed to not allow overriding color once it's set, but
10
+ # we do not yet have true SPEC_OPTS parsing via RSpec config to get it initially set
11
+ %>
12
+ config.instance_variable_set(:@color, <%=color_value.to_s%>)
13
+ <%
14
+ end
15
+ if (requires = spec_opts.scan(/--require \S+/)).any?
16
+ requires.map {|r| /--require (.*)/.match(r).captures[0]}.each do |req| %>
17
+
18
+ require "<%= req %>"
19
+
20
+ <% end
21
+ end
22
+ if (match = /--format (\S+)/.match(spec_opts))
23
+ formatter = match.captures[0]
24
+ %>
25
+ config.formatter = "<%=formatter%>"
26
+ <% end %>
27
+ end
28
+ <% end %>
@@ -4,8 +4,10 @@
4
4
  require 'opal'
5
5
  require 'opal-rspec'
6
6
 
7
- <% Dir.glob('spec/**/*_spec.{rb,opal}').each do |s| %>
8
- require <%= s.sub(/^spec\//, '').sub(/\.(rb|opal)$/, '').inspect %>
7
+ <%
8
+ environment.get_opal_spec_requires.each do |s| %>
9
+ require <%= s.inspect %>
9
10
  <% end %>
11
+ require 'opal/rspec/spec_opts'
10
12
 
11
- Opal::RSpec::Runner.autorun
13
+ ::RSpec::Core::Runner.autorun
@@ -0,0 +1,31 @@
1
+ require 'rspec'
2
+ require 'capybara/rspec'
3
+ require 'capybara-webkit'
4
+
5
+ # Use Rack config exactly as shipped in the GEM
6
+ Capybara.app = Rack::Builder.new_from_string(File.read('config.ru'))
7
+
8
+ describe 'browser formatter', type: :feature do
9
+ RSpec.shared_examples :browser do |driver, error_fetcher|
10
+ context "in #{driver}", driver: driver do
11
+ before do
12
+ visit '/'
13
+ # Specs should run in 12 seconds but in case Travis takes longer, provide some cushion
14
+ Capybara.default_wait_time = 40
15
+ end
16
+
17
+ after do
18
+ js_errors = error_fetcher[page]
19
+ puts "Javascript errors: #{js_errors}" if js_errors.any?
20
+ end
21
+
22
+ it 'matches test results' do
23
+ expect(page).to have_content '142 examples, 40 failures, 12 pending'
24
+ end
25
+ end
26
+ end
27
+
28
+ # Travis version (4.x QT) might be causing this to fail
29
+ #include_examples :browser, :webkit, lambda {|page| page.driver.error_messages}
30
+ include_examples :browser, :selenium, lambda {|page| page.evaluate_script('window.jsErrors') }
31
+ end
@@ -0,0 +1,20 @@
1
+ # This file is used by Opal::Server to basically load all spec files that
2
+ # can be found in the spec/ directory.
3
+
4
+ require 'opal'
5
+ # Hard to capture errors w/ Selenium
6
+ %x{
7
+ window.jsErrors = [];
8
+ window.onerror = function (errorMessage) {
9
+ window.jsErrors.push(errorMessage);
10
+ };
11
+ }
12
+
13
+ require 'opal-rspec'
14
+
15
+ <%
16
+ environment.get_opal_spec_requires.each do |s| %>
17
+ require <%= s.inspect %>
18
+ <% end %>
19
+ require 'opal/rspec/spec_opts'
20
+ ::RSpec::Core::Runner.autorun