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,3 @@
1
+ # Long standing issue with doing defined?(@instance_var) - See https://github.com/opal/opal/blob/master/lib/opal/nodes/defined.rb, compile_ivar method
2
+ # RSpec::Matchers::BuiltIn::BaseMatcher#description does one of these and when @expected is nil, it will not appear defined but it should be
3
+ equal when the expected object is falsey in conditinal semantics describes itself with the expected object
@@ -0,0 +1,2 @@
1
+ # Arity
2
+ RSpec::Expectations::ExpectationTarget when constructed via #expect raises a wrong number of args ArgumentError when given two args
@@ -0,0 +1,2 @@
1
+ # Probably more related to nesting lambdas in the test than with using raise_error - https://github.com/opal/opal/pull/1117
2
+ RSpec::Expectations does not allow expectation failures to be caught by a bare rescue
@@ -0,0 +1,8 @@
1
+ rspec_filter 'have_attributes' do
2
+ # https://github.com/opal/opal/pull/1136 - operators and method missing issues with a_value > < etc
3
+ unless at_least_opal_0_9?
4
+ filter('#have_attributes matcher expect(...).to have_attributes(with_one_attribute) expect(...).to have_attributes(key => matcher) fails with a clear message when the matcher does not match')
5
+ filter('#have_attributes matcher expect(...).to have_attributes(with_one_attribute) expect(...).to have_attributes(key => matcher) provides a description')
6
+ filter('#have_attributes matcher expect(...).to have_attributes(with_one_attribute) expect(...).to have_attributes(key => matcher) passes when the matchers match')
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ rspec_filter 'include' do
2
+ # https://github.com/opal/opal/pull/1136 - operators and method missing issues with a_value > < etc
3
+ filter('#include matcher Composing matchers with `include` expect(array).to include(matcher) works with comparison matchers').unless { at_least_opal_0_9? }
4
+ end
@@ -0,0 +1,2 @@
1
+ # https://github.com/opal/opal/pull/1136 - operators and method missing issues with a_value > < etc
2
+ operator matchers.*
@@ -0,0 +1,2 @@
1
+ # there are 2 examples w/ the same name, 1 fails because it used load (Opal), the other for the same reason as above
2
+ expect { ... }.to raise_error\(NamedError\) fails if another error is raised \(NameError\)
@@ -0,0 +1,13 @@
1
+ rspec_filter 'respond_to' do
2
+ # Also arity related, but looks like opal is returning the optional arg splat as arity
3
+ filter('expect(...).not_to respond_to(:sym).with(1).argument fails if target responds to :sym with one or more args').unless { at_least_opal_0_9? }
4
+ filter('expect(...).to respond_to(:sym).with(2).arguments passes if target responds to two or more arguments').unless { at_least_opal_0_9? }
5
+ filter 'expect(...).to respond_to(:sym).with(2).arguments passes if target responds to any number of arguments'
6
+ filter('expect(...).to respond_to(:sym).with(1).argument passes if target responds to one or more arguments').unless { at_least_opal_0_9? }
7
+
8
+ # arity related
9
+ filter('expect(...).to respond_to(:sym).with(1).argument passes if target responds to any number of arguments').if { at_least_opal_0_9? }
10
+ filter('expect(...).to respond_to(:sym).with(2).arguments passes if target responds to one or more arguments').if { at_least_opal_0_9? }
11
+ filter('expect(...).not_to respond_to(:sym).with(1).argument fails if target responds to :sym with any number of args').if { at_least_opal_0_9? }
12
+ filter('expect(...).not_to respond_to(:sym).with(2).arguments fails if target responds to :sym with one or more args').if { at_least_opal_0_9? }
13
+ end
@@ -0,0 +1,20 @@
1
+ module Foo
2
+ def howdy
3
+ puts 'howdy'
4
+ end
5
+ end
6
+
7
+ class Stuff
8
+ include Foo
9
+ end
10
+
11
+ # This approach fails on opal-master
12
+ # module Foo
13
+ # undef howdy
14
+ # end
15
+ #
16
+ # Stuff.new.howdy
17
+
18
+ # This approach also fails on opal-master
19
+ Foo.send(:remove_method, :howdy)
20
+ Stuff.new.howdy
@@ -0,0 +1,5 @@
1
+ # opal symbols are strings
2
+ RSpec::Matchers should have an alias for "have attributes \{\\"age\\" => 32\}" with description: "an object having attributes \{:age => 32\}"
3
+ RSpec::Matchers should have an alias for "include \{\\"a\\" => 5\}" with description: "a hash including \{:a => 5\}"
4
+ RSpec::Matchers should have an alias for "throw foo" with description: "a block throwing :foo"
5
+ RSpec::Matchers should have an alias for "throw foo" with description: "throwing :foo"
@@ -0,0 +1,2 @@
1
+ # no private methods in opal
2
+ expect\(...\).to be_predicate fails when :predicate\? is private
@@ -0,0 +1,3 @@
1
+ # Fixnum/Numeric
2
+ expect\(actual\).to be_an_instance_of\(expected\) provides a description
3
+ expect\(actual\).to be_instance_of\(expected\) provides a description
@@ -0,0 +1,2 @@
1
+ # strings are immutable
2
+ expect { ... }.to change\(actual, message\) with a string passes when actual is modified by the block
@@ -0,0 +1,2 @@
1
+ # backtrace/line #
2
+ RSpec::Expectations::Configuration#backtrace_formatter defaults to rspec-core's backtrace formatter when rspec-core is loaded
@@ -0,0 +1,2 @@
1
+ # no timeout in opal
2
+ expect\(array\).to contain_exactly\(\*other_array\) fails a match of 11 items with duplicates in a reasonable amount of time
@@ -0,0 +1,6 @@
1
+ # Symbols are strings
2
+ Matchers should be able to generate their own descriptions expect\(...\).to have_key
3
+ Matchers should be able to generate their own descriptions expect\(...\).not_to eql
4
+
5
+ # throw not in Opal
6
+ Matchers should be able to generate their own descriptions expect\(...\).to throw symbol.*
@@ -0,0 +1,8 @@
1
+ # mutable strings, see opal alternates
2
+ RSpec::Matchers::DSL::Matcher defined using the dsl raises NoMethodError for methods not in the running_example
3
+
4
+ # Fixnum = Numeric on Opal, see opal alternates
5
+ Spec::Matchers::DSL::Matcher wrapping another expectation \(expect\(...\).to eq ...\) can use the `include` matcher from a `match` block
6
+
7
+ # regex compatibility, see opal alternates
8
+ RSpec::Matchers::DSL::Matcher wrapping another expectation \(expect\(...\).to eq ...\) can use the `match` matcher from a `match` block
@@ -0,0 +1,10 @@
1
+ # no bigdecimal on opal
2
+ eq with BigDecimal objects fails with a conventional representation of the decimal
3
+
4
+ # no activesupport on opal
5
+ eq Time Equality with DateTime objects.*
6
+ eq Time Equality with Time objects produces different output for Times differing by milliseconds
7
+
8
+ # symbols
9
+ eq #description with "symbol" is "eq :symbol"
10
+ eq #description with {"foo"=>"bar"} is "eq {:foo=>:bar}"
@@ -0,0 +1,3 @@
1
+ # == and .equal? on Opal are still largely the same
2
+ equal suggests the `eq` matcher on failure
3
+ equal does not match when \!actual.equal\?\(expected\)
@@ -0,0 +1,2 @@
1
+ # Fixnum = Numeric on Opal, see opal alternates
2
+ RSpec::Expectations::ExpectationTarget when constructed via #expect fails an invalid negative expectation
@@ -0,0 +1,8 @@
1
+ # diff on Opal
2
+ RSpec::Expectations includes a diff if expected and actual are diffable
3
+ RSpec::Expectations does not include the diff if expected and actual are not diffable
4
+ RSpec::Expectations uses matcher descriptions in place of matchers in diffs
5
+ RSpec::Expectations tells the differ to use color
6
+
7
+ # Dir
8
+ RSpec::Expectations behaves like a library that issues no warnings when loaded issues no warnings when loaded
@@ -0,0 +1,2 @@
1
+ # private method
2
+ expect\(...\).to have_sym\(\*args\) fails if #has_sym\?\(\*args\) is private
@@ -0,0 +1,3 @@
1
+ # Diff
2
+ .include matcher expect\(...\).to include\(with_one_arg\) for a string target includes a diff when actual is multiline and there are multiple expecteds
3
+ .include matcher expect\(...\).to include\(with_one_arg\) for a string target includes a diff when actual is multiline
@@ -0,0 +1,2 @@
1
+ # diffing on Opal
2
+ expect\(...\).to match\(expected\) provides a diff on failure
@@ -0,0 +1,11 @@
1
+ # diffs not yet supported on Opal
2
+ RSpec::Matchers::DSL::Matcher handles multiline string diffs
3
+
4
+ # throw not in Opal
5
+ RSpec::Matchers::BuiltIn::ThrowSymbol.*
6
+
7
+ # subprocess/threading
8
+ RSpec::Matchers can be mixed into `main`
9
+
10
+ # minitest/opal compatibility
11
+ built in matchers RSpec::Matchers method_missing hook when invoked in a Minitest::Test behaves like a well-behaved method_missing hook raises a NoMethodError \(and not SystemStackError\) for an undefined method
@@ -0,0 +1,14 @@
1
+ # diff
2
+ output.to_stdout matcher expect { ... }.to_not output\(matcher\).to_stdout fails if the block outputs a string to stdout that passes the given matcher
3
+ output.to_stdout matcher expect { ... }.to output\(matcher\).to_stdout fails if the block outputs a string to stdout that does not pass the given matcher
4
+ output.to_stdout matcher expect { ... }.to_not output\(/regex/\).to_stdout fails if the block outputs a string to stdout that matches the regex
5
+ output.to_stdout matcher expect { ... }.to output\(/regex/\).to_stdout fails if the block outputs a string to stdout that does not match
6
+ output.to_stdout matcher expect { ... }.to output\(/regex/\).to_stdout fails if the block does not output to stdout
7
+ output.to_stderr matcher expect { ... }.to_not output\(matcher\).to_stderr fails if the block outputs a string to stderr that passes the given matcher
8
+ output.to_stderr matcher expect { ... }.to output\(matcher\).to_stderr fails if the block outputs a string to stderr that does not pass the given matcher
9
+ output.to_stderr matcher expect { ... }.to_not output\(/regex/\).to_stderr fails if the block outputs a string to stderr that matches the regex
10
+ output.to_stderr matcher expect { ... }.to output\(/regex/\).to_stderr fails if the block outputs a string to stderr that does not match
11
+ output.to_stderr matcher expect { ... }.to output\(/regex/\).to_stderr fails if the block does not output to stderr
12
+
13
+ # $VERBOSE global variable
14
+ output..* matcher does not produce warnings when the failure message is accessed first
@@ -0,0 +1,3 @@
1
+ # backtrace / line numbers
2
+ expect { ... }.to raise_error\(message\) includes the backtrace of any other error in the failure message
3
+ expect { ... }.not_to raise_error with no specific error class includes the backtrace of the error that was raised in the error message
@@ -0,0 +1,5 @@
1
+ rspec_filter 'respond_to' do
2
+ # arity
3
+ filter('expect(...).not_to respond_to(:sym).with(2).arguments fails if target responds to :sym with two or more args').unless { at_least_opal_0_9? }
4
+ filter('expect(...).not_to respond_to(:sym).with(2).arguments fails if target responds to :sym with any number args')
5
+ end
@@ -0,0 +1,3 @@
1
+ # these tests are using symbols but in Opal symbols are strings
2
+ RSpec::Expectations::Syntax when passing a message to an expectation expect\(...\).to prints a warning when the message object isn't a String
3
+ RSpec::Expectations::Syntax when passing a message to an expectation expect\(...\).not_to prints a warning when the message object isn't a String
@@ -0,0 +1,2 @@
1
+ # symbols == strings, see opal alternates
2
+ yield_successive_args matcher has a description
@@ -0,0 +1,32 @@
1
+ module Opal
2
+ module RSpec
3
+ def self.get_constants_for(object)
4
+ result = []
5
+ %x{
6
+ for (var prop in #{object}) {
7
+ if (#{object}.hasOwnProperty(prop) && #{!`prop`.start_with?('$')}) {
8
+ #{result << `prop`}
9
+ }
10
+ }
11
+ }
12
+ result.reject { |c| c == 'constructor' }
13
+ end
14
+ end
15
+ end
16
+
17
+ unless Opal::RSpec::Compatibility.constant_resolution_works_right?
18
+ groups_are_in = RSpec::ExampleGroups
19
+ built_in_spec = :BuiltInMatchers
20
+ # in case we aren't running all of the examples
21
+ if groups_are_in.const_defined? built_in_spec
22
+ example_group = groups_are_in.const_get built_in_spec
23
+ example_group.let(:matchers) do
24
+ # .constants is broken in Opal, this is a hack
25
+ constants = Opal::RSpec.get_constants_for(RSpec::Matchers::BuiltIn) - [:NullCapture, :CaptureStdOut, :CaptureStdErr]
26
+ constants.map { |n| RSpec::Matchers::BuiltIn.const_get(n) }.select do |m|
27
+ #BuiltIn.constants.map { |n| BuiltIn.const_get(n) }.select do |m|
28
+ m.method_defined?(:matches?) && m.method_defined?(:failure_message)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ ComplexStruct = Struct.new(:args)
2
+
3
+ def Complex(*args)
4
+ ComplexStruct.new(args)
5
+ end
6
+
7
+ # In Opal 0.9
8
+ unless Object.const_defined?(:Math) && Object.const_defined?(:PI)
9
+ module Math
10
+ PI = `Math.PI`
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ module RSpec::Support::ShellOut
2
+ end
3
+
4
+ # Uses forking/threads
5
+ module ::RSpec::Support::InSubProcess
6
+ end
@@ -0,0 +1,140 @@
1
+ # https://github.com/opal/opal/issues/1110, fixed in Opal 0.9
2
+ unless Opal::RSpec::Compatibility.class_within_class_new_works?
3
+ require 'delegate'
4
+
5
+ class ArrayDelegate < DelegateClass(Array)
6
+ def initialize(array)
7
+ @internal_array = array
8
+ super(@internal_array)
9
+ end
10
+
11
+ def large?
12
+ @internal_array.size >= 5
13
+ end
14
+ end
15
+
16
+ class FooError < StandardError
17
+ def foo;
18
+ :bar;
19
+ end
20
+ end
21
+
22
+ # description_generaiton_spec
23
+ class Parent;
24
+ end
25
+ class Child < Parent
26
+ def child_of?(*parents)
27
+ parents.all? { |parent| self.is_a?(parent) }
28
+ end
29
+ end
30
+
31
+ # be_between spec
32
+ class SizeMatters
33
+ include Comparable
34
+ attr :str
35
+
36
+ def <=>(other)
37
+ str.size <=> other.str.size
38
+ end
39
+
40
+ def initialize(str)
41
+ @str = str
42
+ end
43
+
44
+ def inspect
45
+ @str
46
+ end
47
+ end
48
+ end
49
+
50
+ # https://github.com/opal/opal/pull/1135
51
+ unless Opal::RSpec::Compatibility.ostruct_works_right?
52
+ class OpenStruct
53
+ def initialize(hash = nil)
54
+ @table = {}
55
+
56
+ hash.each_pair { |key, value|
57
+ @table[new_ostruct_member(key)] = value
58
+ } if hash
59
+ end
60
+
61
+ def []=(name, value)
62
+ @table[new_ostruct_member(name)] = value
63
+ end
64
+
65
+ def method_missing(name, *args)
66
+ if args.length > 2
67
+ raise NoMethodError.new "undefined method `#{name}' for #<OpenStruct>"
68
+ end
69
+ if name.end_with? '='
70
+ if args.length != 1
71
+ raise ArgumentError.new "wrong number of arguments (0 for 1)"
72
+ end
73
+ @table[new_ostruct_member(name[0 .. -2])] = args[0]
74
+ else
75
+ @table[name.to_sym]
76
+ end
77
+ end
78
+
79
+ attr_reader :table
80
+
81
+ def delete_field(name)
82
+ sym = name.to_sym
83
+ begin
84
+ singleton_class.__send__(:remove_method, sym, "#{sym}=")
85
+ rescue NameError
86
+ end
87
+ @table.delete sym
88
+ end
89
+
90
+ def new_ostruct_member(name)
91
+ name = name.to_sym
92
+ unless respond_to?(name)
93
+ define_singleton_method(name) { @table[name] }
94
+ define_singleton_method("#{name}=") { |x| @table[name] = x }
95
+ end
96
+ name
97
+ end
98
+
99
+ `var ostruct_ids;`
100
+
101
+ def inspect
102
+ %x{
103
+ var top = (ostruct_ids === undefined),
104
+ ostruct_id = self.$object_id();
105
+ }
106
+ begin
107
+ result = "#<#{self.class}"
108
+ %x{
109
+ if (top) {
110
+ ostruct_ids = {};
111
+ }
112
+
113
+ if (ostruct_ids.hasOwnProperty(ostruct_id)) {
114
+ return #{result + ' ...>'};
115
+ }
116
+
117
+ ostruct_ids[ostruct_id] = true;
118
+ }
119
+
120
+ result += ' ' if @table.any?
121
+
122
+ result += each_pair.map { |name, value|
123
+ "#{name}=#{value.inspect}"
124
+ }.join ", "
125
+
126
+ result += ">"
127
+
128
+ result
129
+ ensure
130
+ %x{
131
+ if (top) {
132
+ ostruct_ids = undefined;
133
+ }
134
+ }
135
+ end
136
+ end
137
+
138
+ alias to_s inspect
139
+ end
140
+ end
@@ -0,0 +1,11 @@
1
+ [:be_an_instance_of, :be_instance_of].each do |method|
2
+ describe "Opal expect(actual).to #{method}(expected)" do
3
+ it "provides a description" do
4
+ matcher = be_an_instance_of(Fixnum)
5
+ matcher.matches?(Numeric)
6
+ # opal fixnum == numeric
7
+ # expect(matcher.description).to eq "be an instance of Fixnum"
8
+ expect(matcher.description).to eq "be an instance of Numeric"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,66 @@
1
+ describe 'Opal RSpec::Matchers::DSL::Matcher' do
2
+ context "defined using the dsl" do
3
+ it "raises NoMethodError for methods not in the running_example" do |example|
4
+ RSpec::Matchers.define(:__raise_no_method_error) do
5
+ match do |actual|
6
+ self.a_method_not_in_the_example == "method defined in the example"
7
+ end
8
+ end
9
+
10
+ # mutable strings
11
+ #expected_msg = "RSpec::Matchers::DSL::Matcher"
12
+ #expected_msg << " __raise_no_method_error" unless rbx?
13
+ expected_msg = "RSpec::Matchers::DSL::Matcher" + " __raise_no_method_error"
14
+
15
+ expect {
16
+ expect(example).to __raise_no_method_error
17
+ }.to raise_error(NoMethodError, /#{expected_msg}/)
18
+ end
19
+ end
20
+
21
+ context "wrapping another expectation (expect(...).to eq ...)" do
22
+ it "can use the `include` matcher from a `match` block" do
23
+ RSpec::Matchers.define(:descend_from) do |mod|
24
+ match do |klass|
25
+ expect(klass.ancestors).to include(mod)
26
+ end
27
+ end
28
+
29
+ expect(Fixnum).to descend_from(Object)
30
+ expect(Fixnum).not_to descend_from(Array)
31
+
32
+ expect {
33
+ expect(Fixnum).to descend_from(Array)
34
+ }.to fail_with(/expected Numeric to descend from Array/)
35
+ # Fixnum = Numeric on Opal
36
+ #}.to fail_with(/expected Fixnum to descend from Array/)
37
+
38
+ expect {
39
+ expect(Fixnum).not_to descend_from(Object)
40
+ # Fixnum = Numeric on Opal
41
+ }.to fail_with(/expected Numeric not to descend from Object/)
42
+ #}.to fail_with(/expected Fixnum not to descend from Object/)
43
+ end
44
+
45
+ it "can use the `match` matcher from a `match` block" do
46
+ RSpec::Matchers.define(:be_a_phone_number_string) do
47
+ match do |string|
48
+ # \A and \Z in JS regex
49
+ # expect(string).to match(/\A\d{3}\-\d{3}\-\d{4}\z/)
50
+ expect(string).to match(/^\d{3}\-\d{3}\-\d{4}$/)
51
+ end
52
+ end
53
+
54
+ expect("206-123-1234").to be_a_phone_number_string
55
+ expect("foo").not_to be_a_phone_number_string
56
+
57
+ expect {
58
+ expect("foo").to be_a_phone_number_string
59
+ }.to fail_with(/expected "foo" to be a phone number string/)
60
+
61
+ expect {
62
+ expect("206-123-1234").not_to be_a_phone_number_string
63
+ }.to fail_with(/expected "206-123-1234" not to be a phone number string/)
64
+ end
65
+ end
66
+ end