newbamboo-evented-rspec 1.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (323) hide show
  1. data/.autotest +4 -0
  2. data/History.txt +1263 -0
  3. data/License.txt +22 -0
  4. data/Manifest.txt +327 -0
  5. data/README.txt +57 -0
  6. data/Rakefile +104 -0
  7. data/TODO.txt +18 -0
  8. data/bin/autospec +4 -0
  9. data/bin/spec +4 -0
  10. data/examples/failing/README.txt +7 -0
  11. data/examples/failing/diffing_spec.rb +36 -0
  12. data/examples/failing/failing_autogenerated_docstrings_example.rb +19 -0
  13. data/examples/failing/failure_in_after.rb +10 -0
  14. data/examples/failing/failure_in_before.rb +10 -0
  15. data/examples/failing/mocking_example.rb +40 -0
  16. data/examples/failing/mocking_with_flexmock.rb +26 -0
  17. data/examples/failing/mocking_with_mocha.rb +25 -0
  18. data/examples/failing/mocking_with_rr.rb +27 -0
  19. data/examples/failing/partial_mock_example.rb +20 -0
  20. data/examples/failing/predicate_example.rb +34 -0
  21. data/examples/failing/raising_example.rb +47 -0
  22. data/examples/failing/spec_helper.rb +3 -0
  23. data/examples/failing/syntax_error_example.rb +7 -0
  24. data/examples/failing/team_spec.rb +44 -0
  25. data/examples/failing/timeout_behaviour.rb +7 -0
  26. data/examples/passing/autogenerated_docstrings_example.rb +25 -0
  27. data/examples/passing/before_and_after_example.rb +40 -0
  28. data/examples/passing/behave_as_example.rb +45 -0
  29. data/examples/passing/custom_expectation_matchers.rb +54 -0
  30. data/examples/passing/custom_formatter.rb +12 -0
  31. data/examples/passing/dynamic_spec.rb +9 -0
  32. data/examples/passing/file_accessor.rb +19 -0
  33. data/examples/passing/file_accessor_spec.rb +38 -0
  34. data/examples/passing/greeter_spec.rb +31 -0
  35. data/examples/passing/helper_method_example.rb +14 -0
  36. data/examples/passing/io_processor.rb +8 -0
  37. data/examples/passing/io_processor_spec.rb +21 -0
  38. data/examples/passing/legacy_spec.rb +11 -0
  39. data/examples/passing/mocking_example.rb +27 -0
  40. data/examples/passing/multi_threaded_example_group_runner.rb +26 -0
  41. data/examples/passing/nested_classes_example.rb +36 -0
  42. data/examples/passing/partial_mock_example.rb +29 -0
  43. data/examples/passing/pending_example.rb +20 -0
  44. data/examples/passing/predicate_example.rb +27 -0
  45. data/examples/passing/priority.txt +1 -0
  46. data/examples/passing/shared_example_group_example.rb +81 -0
  47. data/examples/passing/shared_stack_examples.rb +36 -0
  48. data/examples/passing/simple_matcher_example.rb +31 -0
  49. data/examples/passing/spec_helper.rb +3 -0
  50. data/examples/passing/stack.rb +36 -0
  51. data/examples/passing/stack_spec.rb +64 -0
  52. data/examples/passing/stack_spec_with_nested_example_groups.rb +67 -0
  53. data/examples/passing/stubbing_example.rb +69 -0
  54. data/examples/passing/yielding_example.rb +33 -0
  55. data/examples/ruby1.9.compatibility/access_to_constants_spec.rb +86 -0
  56. data/features/before_and_after_blocks/before_and_after_blocks.feature +168 -0
  57. data/features/example_groups/autogenerated_docstrings.feature +45 -0
  58. data/features/example_groups/example_group_with_should_methods.feature +17 -0
  59. data/features/example_groups/nested_groups.feature +17 -0
  60. data/features/example_groups/output.feature +20 -0
  61. data/features/interop/examples_and_tests_together.feature +31 -0
  62. data/features/interop/test_but_not_test_unit.feature +14 -0
  63. data/features/interop/test_case_with_should_methods.feature +17 -0
  64. data/features/mock_framework_integration/use_flexmock.feature +27 -0
  65. data/features/step_definitions/running_rspec.rb +54 -0
  66. data/features/support/env.rb +26 -0
  67. data/features/support/helpers/cmdline.rb +9 -0
  68. data/features/support/matchers/smart_match.rb +37 -0
  69. data/init.rb +9 -0
  70. data/lib/adapters/mock_frameworks/flexmock.rb +24 -0
  71. data/lib/adapters/mock_frameworks/mocha.rb +20 -0
  72. data/lib/adapters/mock_frameworks/rr.rb +22 -0
  73. data/lib/adapters/mock_frameworks/rspec.rb +20 -0
  74. data/lib/autotest/discover.rb +3 -0
  75. data/lib/autotest/rspec.rb +47 -0
  76. data/lib/spec.rb +7 -0
  77. data/lib/spec/dsl.rb +1 -0
  78. data/lib/spec/dsl/main.rb +87 -0
  79. data/lib/spec/example.rb +187 -0
  80. data/lib/spec/example/before_and_after_hooks.rb +99 -0
  81. data/lib/spec/example/errors.rb +30 -0
  82. data/lib/spec/example/example_group.rb +26 -0
  83. data/lib/spec/example/example_group_factory.rb +98 -0
  84. data/lib/spec/example/example_group_methods.rb +376 -0
  85. data/lib/spec/example/example_matcher.rb +44 -0
  86. data/lib/spec/example/example_methods.rb +137 -0
  87. data/lib/spec/example/module_reopening_fix.rb +21 -0
  88. data/lib/spec/example/pending.rb +18 -0
  89. data/lib/spec/example/shared_example_group.rb +59 -0
  90. data/lib/spec/expectations.rb +60 -0
  91. data/lib/spec/expectations/differs/default.rb +66 -0
  92. data/lib/spec/expectations/errors.rb +12 -0
  93. data/lib/spec/expectations/extensions.rb +2 -0
  94. data/lib/spec/expectations/extensions/object.rb +63 -0
  95. data/lib/spec/expectations/extensions/string_and_symbol.rb +17 -0
  96. data/lib/spec/expectations/handler.rb +32 -0
  97. data/lib/spec/interop/test.rb +12 -0
  98. data/lib/spec/interop/test/unit/autorunner.rb +6 -0
  99. data/lib/spec/interop/test/unit/testcase.rb +73 -0
  100. data/lib/spec/interop/test/unit/testresult.rb +6 -0
  101. data/lib/spec/interop/test/unit/testsuite_adapter.rb +34 -0
  102. data/lib/spec/interop/test/unit/ui/console/testrunner.rb +61 -0
  103. data/lib/spec/matchers.rb +141 -0
  104. data/lib/spec/matchers/be.rb +208 -0
  105. data/lib/spec/matchers/be_close.rb +21 -0
  106. data/lib/spec/matchers/change.rb +148 -0
  107. data/lib/spec/matchers/eql.rb +25 -0
  108. data/lib/spec/matchers/equal.rb +25 -0
  109. data/lib/spec/matchers/errors.rb +5 -0
  110. data/lib/spec/matchers/exist.rb +16 -0
  111. data/lib/spec/matchers/generated_descriptions.rb +48 -0
  112. data/lib/spec/matchers/has.rb +15 -0
  113. data/lib/spec/matchers/have.rb +150 -0
  114. data/lib/spec/matchers/include.rb +80 -0
  115. data/lib/spec/matchers/match.rb +22 -0
  116. data/lib/spec/matchers/match_array.rb +79 -0
  117. data/lib/spec/matchers/method_missing.rb +9 -0
  118. data/lib/spec/matchers/operator_matcher.rb +70 -0
  119. data/lib/spec/matchers/raise_error.rb +128 -0
  120. data/lib/spec/matchers/respond_to.rb +71 -0
  121. data/lib/spec/matchers/satisfy.rb +47 -0
  122. data/lib/spec/matchers/simple_matcher.rb +132 -0
  123. data/lib/spec/matchers/throw_symbol.rb +106 -0
  124. data/lib/spec/matchers/wrap_expectation.rb +55 -0
  125. data/lib/spec/mocks.rb +200 -0
  126. data/lib/spec/mocks/argument_expectation.rb +49 -0
  127. data/lib/spec/mocks/argument_matchers.rb +237 -0
  128. data/lib/spec/mocks/error_generator.rb +82 -0
  129. data/lib/spec/mocks/errors.rb +10 -0
  130. data/lib/spec/mocks/extensions.rb +1 -0
  131. data/lib/spec/mocks/extensions/object.rb +3 -0
  132. data/lib/spec/mocks/framework.rb +15 -0
  133. data/lib/spec/mocks/message_expectation.rb +331 -0
  134. data/lib/spec/mocks/methods.rb +51 -0
  135. data/lib/spec/mocks/mock.rb +55 -0
  136. data/lib/spec/mocks/order_group.rb +29 -0
  137. data/lib/spec/mocks/proxy.rb +230 -0
  138. data/lib/spec/mocks/space.rb +28 -0
  139. data/lib/spec/mocks/spec_methods.rb +55 -0
  140. data/lib/spec/rake/spectask.rb +225 -0
  141. data/lib/spec/rake/verify_rcov.rb +52 -0
  142. data/lib/spec/ruby.rb +9 -0
  143. data/lib/spec/runner.rb +88 -0
  144. data/lib/spec/runner/backtrace_tweaker.rb +58 -0
  145. data/lib/spec/runner/class_and_arguments_parser.rb +14 -0
  146. data/lib/spec/runner/command_line.rb +36 -0
  147. data/lib/spec/runner/configuration.rb +166 -0
  148. data/lib/spec/runner/drb_command_line.rb +20 -0
  149. data/lib/spec/runner/example_group_runner.rb +70 -0
  150. data/lib/spec/runner/formatter/base_formatter.rb +79 -0
  151. data/lib/spec/runner/formatter/base_text_formatter.rb +127 -0
  152. data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +27 -0
  153. data/lib/spec/runner/formatter/failing_examples_formatter.rb +20 -0
  154. data/lib/spec/runner/formatter/html_formatter.rb +340 -0
  155. data/lib/spec/runner/formatter/nested_text_formatter.rb +65 -0
  156. data/lib/spec/runner/formatter/profile_formatter.rb +51 -0
  157. data/lib/spec/runner/formatter/progress_bar_formatter.rb +34 -0
  158. data/lib/spec/runner/formatter/snippet_extractor.rb +52 -0
  159. data/lib/spec/runner/formatter/specdoc_formatter.rb +39 -0
  160. data/lib/spec/runner/formatter/text_mate_formatter.rb +16 -0
  161. data/lib/spec/runner/heckle_runner.rb +74 -0
  162. data/lib/spec/runner/heckle_runner_unsupported.rb +10 -0
  163. data/lib/spec/runner/option_parser.rb +204 -0
  164. data/lib/spec/runner/options.rb +320 -0
  165. data/lib/spec/runner/reporter.rb +167 -0
  166. data/lib/spec/runner/spec_parser.rb +73 -0
  167. data/lib/spec/version.rb +15 -0
  168. data/resources/rake/examples.rake +7 -0
  169. data/resources/rake/examples_with_rcov.rake +9 -0
  170. data/resources/rake/failing_examples_with_html.rake +9 -0
  171. data/resources/rake/verify_rcov.rake +7 -0
  172. data/resources/spec/example_group_with_should_methods.rb +12 -0
  173. data/resources/spec/simple_spec.rb +8 -0
  174. data/resources/test/spec_and_test_together.rb +57 -0
  175. data/resources/test/spec_including_test_but_not_unit.rb +11 -0
  176. data/resources/test/test_case_with_should_methods.rb +30 -0
  177. data/spec/README.jruby +15 -0
  178. data/spec/autotest/autotest_helper.rb +6 -0
  179. data/spec/autotest/autotest_matchers.rb +47 -0
  180. data/spec/autotest/discover_spec.rb +8 -0
  181. data/spec/autotest/failed_results_re_spec.rb +24 -0
  182. data/spec/autotest/rspec_spec.rb +114 -0
  183. data/spec/rspec_suite.rb +6 -0
  184. data/spec/ruby_forker.rb +13 -0
  185. data/spec/spec.opts +6 -0
  186. data/spec/spec/dsl/main_spec.rb +88 -0
  187. data/spec/spec/example/example_group_class_definition_spec.rb +49 -0
  188. data/spec/spec/example/example_group_factory_spec.rb +224 -0
  189. data/spec/spec/example/example_group_methods_spec.rb +653 -0
  190. data/spec/spec/example/example_group_spec.rb +661 -0
  191. data/spec/spec/example/example_matcher_spec.rb +79 -0
  192. data/spec/spec/example/example_methods_spec.rb +204 -0
  193. data/spec/spec/example/helper_method_spec.rb +24 -0
  194. data/spec/spec/example/nested_example_group_spec.rb +71 -0
  195. data/spec/spec/example/pending_module_spec.rb +139 -0
  196. data/spec/spec/example/predicate_matcher_spec.rb +21 -0
  197. data/spec/spec/example/shared_example_group_spec.rb +257 -0
  198. data/spec/spec/example/subclassing_example_group_spec.rb +25 -0
  199. data/spec/spec/expectations/differs/default_spec.rb +127 -0
  200. data/spec/spec/expectations/extensions/object_spec.rb +45 -0
  201. data/spec/spec/expectations/fail_with_spec.rb +71 -0
  202. data/spec/spec/expectations/wrap_expectation_spec.rb +30 -0
  203. data/spec/spec/interop/test/unit/resources/spec_that_fails.rb +10 -0
  204. data/spec/spec/interop/test/unit/resources/spec_that_passes.rb +10 -0
  205. data/spec/spec/interop/test/unit/resources/spec_with_errors.rb +10 -0
  206. data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +13 -0
  207. data/spec/spec/interop/test/unit/resources/test_case_that_fails.rb +10 -0
  208. data/spec/spec/interop/test/unit/resources/test_case_that_passes.rb +10 -0
  209. data/spec/spec/interop/test/unit/resources/test_case_with_errors.rb +10 -0
  210. data/spec/spec/interop/test/unit/resources/testsuite_adapter_spec_with_test_unit.rb +38 -0
  211. data/spec/spec/interop/test/unit/spec_spec.rb +48 -0
  212. data/spec/spec/interop/test/unit/test_unit_spec_helper.rb +18 -0
  213. data/spec/spec/interop/test/unit/testcase_spec.rb +49 -0
  214. data/spec/spec/interop/test/unit/testsuite_adapter_spec.rb +9 -0
  215. data/spec/spec/matchers/be_close_spec.rb +41 -0
  216. data/spec/spec/matchers/be_spec.rb +303 -0
  217. data/spec/spec/matchers/change_spec.rb +329 -0
  218. data/spec/spec/matchers/description_generation_spec.rb +172 -0
  219. data/spec/spec/matchers/eql_spec.rb +29 -0
  220. data/spec/spec/matchers/equal_spec.rb +29 -0
  221. data/spec/spec/matchers/exist_spec.rb +57 -0
  222. data/spec/spec/matchers/handler_spec.rb +111 -0
  223. data/spec/spec/matchers/has_spec.rb +63 -0
  224. data/spec/spec/matchers/have_spec.rb +399 -0
  225. data/spec/spec/matchers/include_spec.rb +88 -0
  226. data/spec/spec/matchers/match_array_spec.rb +83 -0
  227. data/spec/spec/matchers/match_spec.rb +37 -0
  228. data/spec/spec/matchers/matcher_methods_spec.rb +66 -0
  229. data/spec/spec/matchers/operator_matcher_spec.rb +191 -0
  230. data/spec/spec/matchers/raise_error_spec.rb +333 -0
  231. data/spec/spec/matchers/respond_to_spec.rb +116 -0
  232. data/spec/spec/matchers/satisfy_spec.rb +36 -0
  233. data/spec/spec/matchers/simple_matcher_spec.rb +93 -0
  234. data/spec/spec/matchers/throw_symbol_spec.rb +96 -0
  235. data/spec/spec/mocks/any_number_of_times_spec.rb +36 -0
  236. data/spec/spec/mocks/argument_expectation_spec.rb +23 -0
  237. data/spec/spec/mocks/at_least_spec.rb +97 -0
  238. data/spec/spec/mocks/at_most_spec.rb +93 -0
  239. data/spec/spec/mocks/bug_report_10260_spec.rb +8 -0
  240. data/spec/spec/mocks/bug_report_10263_spec.rb +24 -0
  241. data/spec/spec/mocks/bug_report_11545_spec.rb +32 -0
  242. data/spec/spec/mocks/bug_report_15719_spec.rb +30 -0
  243. data/spec/spec/mocks/bug_report_496.rb +19 -0
  244. data/spec/spec/mocks/bug_report_600_spec.rb +22 -0
  245. data/spec/spec/mocks/bug_report_7611_spec.rb +19 -0
  246. data/spec/spec/mocks/bug_report_7805_spec.rb +22 -0
  247. data/spec/spec/mocks/bug_report_8165_spec.rb +31 -0
  248. data/spec/spec/mocks/bug_report_8302_spec.rb +26 -0
  249. data/spec/spec/mocks/failing_argument_matchers_spec.rb +95 -0
  250. data/spec/spec/mocks/hash_including_matcher_spec.rb +90 -0
  251. data/spec/spec/mocks/hash_not_including_matcher_spec.rb +67 -0
  252. data/spec/spec/mocks/mock_ordering_spec.rb +84 -0
  253. data/spec/spec/mocks/mock_space_spec.rb +54 -0
  254. data/spec/spec/mocks/mock_spec.rb +579 -0
  255. data/spec/spec/mocks/multiple_return_value_spec.rb +113 -0
  256. data/spec/spec/mocks/nil_expectation_warning_spec.rb +53 -0
  257. data/spec/spec/mocks/null_object_mock_spec.rb +54 -0
  258. data/spec/spec/mocks/once_counts_spec.rb +53 -0
  259. data/spec/spec/mocks/options_hash_spec.rb +35 -0
  260. data/spec/spec/mocks/partial_mock_spec.rb +149 -0
  261. data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +66 -0
  262. data/spec/spec/mocks/passing_argument_matchers_spec.rb +145 -0
  263. data/spec/spec/mocks/precise_counts_spec.rb +52 -0
  264. data/spec/spec/mocks/record_messages_spec.rb +26 -0
  265. data/spec/spec/mocks/stub_spec.rb +194 -0
  266. data/spec/spec/mocks/stubbed_message_expectations_spec.rb +14 -0
  267. data/spec/spec/mocks/twice_counts_spec.rb +67 -0
  268. data/spec/spec/package/bin_spec_spec.rb +22 -0
  269. data/spec/spec/runner/class_and_argument_parser_spec.rb +23 -0
  270. data/spec/spec/runner/command_line_spec.rb +141 -0
  271. data/spec/spec/runner/configuration_spec.rb +301 -0
  272. data/spec/spec/runner/drb_command_line_spec.rb +97 -0
  273. data/spec/spec/runner/empty_file.txt +0 -0
  274. data/spec/spec/runner/example_group_runner_spec.rb +33 -0
  275. data/spec/spec/runner/examples.txt +2 -0
  276. data/spec/spec/runner/failed.txt +3 -0
  277. data/spec/spec/runner/formatter/base_formatter_spec.rb +23 -0
  278. data/spec/spec/runner/formatter/base_text_formatter_spec.rb +23 -0
  279. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +45 -0
  280. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +33 -0
  281. data/spec/spec/runner/formatter/html_formatted-1.8.4.html +365 -0
  282. data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +387 -0
  283. data/spec/spec/runner/formatter/html_formatted-1.8.5.html +371 -0
  284. data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +381 -0
  285. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +379 -0
  286. data/spec/spec/runner/formatter/html_formatted-1.8.7.html +379 -0
  287. data/spec/spec/runner/formatter/html_formatted-1.9.1.html +379 -0
  288. data/spec/spec/runner/formatter/html_formatter_spec.rb +62 -0
  289. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +318 -0
  290. data/spec/spec/runner/formatter/profile_formatter_spec.rb +65 -0
  291. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +145 -0
  292. data/spec/spec/runner/formatter/snippet_extractor_spec.rb +18 -0
  293. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +104 -0
  294. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +159 -0
  295. data/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html +365 -0
  296. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +373 -0
  297. data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +373 -0
  298. data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +373 -0
  299. data/spec/spec/runner/heckle_runner_spec.rb +78 -0
  300. data/spec/spec/runner/heckler_spec.rb +20 -0
  301. data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +45 -0
  302. data/spec/spec/runner/option_parser_spec.rb +396 -0
  303. data/spec/spec/runner/options_spec.rb +469 -0
  304. data/spec/spec/runner/output_one_time_fixture.rb +7 -0
  305. data/spec/spec/runner/output_one_time_fixture_runner.rb +8 -0
  306. data/spec/spec/runner/output_one_time_spec.rb +16 -0
  307. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +62 -0
  308. data/spec/spec/runner/reporter_spec.rb +238 -0
  309. data/spec/spec/runner/resources/a_bar.rb +0 -0
  310. data/spec/spec/runner/resources/a_foo.rb +0 -0
  311. data/spec/spec/runner/resources/a_spec.rb +1 -0
  312. data/spec/spec/runner/resources/custom_example_group_runner.rb +14 -0
  313. data/spec/spec/runner/resources/utf8_encoded.rb +7 -0
  314. data/spec/spec/runner/spec.opts +2 -0
  315. data/spec/spec/runner/spec_drb.opts +1 -0
  316. data/spec/spec/runner/spec_parser/spec_parser_fixture.rb +70 -0
  317. data/spec/spec/runner/spec_parser_spec.rb +91 -0
  318. data/spec/spec/runner/spec_spaced.opts +2 -0
  319. data/spec/spec/runner_spec.rb +11 -0
  320. data/spec/spec/spec_classes.rb +133 -0
  321. data/spec/spec/spec_spec.rb +21 -0
  322. data/spec/spec_helper.rb +107 -0
  323. metadata +388 -0
@@ -0,0 +1,6 @@
1
+ if __FILE__ == $0
2
+ dir = File.dirname(__FILE__)
3
+ Dir["#{dir}/**/*_spec.rb"].reverse.each do |file|
4
+ require file
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ require 'rbconfig'
2
+
3
+ module RubyForker
4
+ # Forks a ruby interpreter with same type as ourself.
5
+ # juby will fork jruby, ruby will fork ruby etc.
6
+ def ruby(args, stderr=nil)
7
+ config = ::Config::CONFIG
8
+ interpreter = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
9
+ cmd = "#{interpreter} #{args}"
10
+ cmd << " 2> #{stderr}" unless stderr.nil?
11
+ `#{cmd}`
12
+ end
13
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ profile
4
+ --timeout
5
+ 20
6
+ --diff
@@ -0,0 +1,88 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ module Spec
4
+ module DSL
5
+ describe Main do
6
+ before(:each) do
7
+ @main = Class.new do; include Spec::DSL::Main; end
8
+ end
9
+
10
+ [:describe, :context].each do |method|
11
+ describe "##{method}" do
12
+ it "should delegate to Spec::Example::ExampleGroupFactory.create_example_group" do
13
+ block = lambda {}
14
+ Spec::Example::ExampleGroupFactory.should_receive(:create_example_group).with(
15
+ "The ExampleGroup", hash_including(:spec_path), &block
16
+ )
17
+ @main.__send__ method, "The ExampleGroup", &block
18
+ end
19
+ end
20
+ end
21
+
22
+ [:share_examples_for, :shared_examples_for].each do |method|
23
+ describe "##{method}" do
24
+ it "should create a shared ExampleGroup" do
25
+ block = lambda {}
26
+ Spec::Example::ExampleGroupFactory.should_receive(:create_shared_example_group).with(
27
+ "shared group", hash_including(:spec_path), &block
28
+ )
29
+ @main.__send__ method, "shared group", &block
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#describe; with RUBY_VERSION = 1.9" do
35
+ it "includes an enclosing module into the block's scope" do
36
+ Spec::Ruby.stub!(:version).and_return("1.9")
37
+
38
+ module Foo; module Bar; end; end
39
+
40
+ Foo::Bar.should_receive(:included).with do |*args|
41
+ included_by = args.last
42
+ included_by.description.should == "this example group"
43
+ end
44
+
45
+ module Foo
46
+ module Bar
47
+ describe("this example group") do; end
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+ describe "#share_as" do
55
+ def self.next_group_name
56
+ @group_number ||= 0
57
+ @group_number += 1
58
+ "Group#{@group_number}"
59
+ end
60
+
61
+ def group_name
62
+ @group_name ||= self.class.next_group_name
63
+ end
64
+
65
+ it "registers a shared ExampleGroup" do
66
+ block = lambda {}
67
+ Spec::Example::ExampleGroupFactory.should_receive(:create_shared_example_group).with(
68
+ group_name, hash_including(:spec_path), &block
69
+ )
70
+ @main.share_as group_name, &block
71
+ end
72
+
73
+ it "creates a constant that points to a Module" do
74
+ group = @main.share_as group_name do end
75
+ Object.const_get(group_name).should equal(group)
76
+ end
77
+
78
+ it "complains if you pass it a not-constantizable name" do
79
+ lambda do
80
+ @group = @main.share_as "Non Constant" do end
81
+ end.should raise_error(NameError, /The first argument to share_as must be a legal name for a constant/)
82
+ end
83
+
84
+ end
85
+ end
86
+ end
87
+ end
88
+
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Spec
4
+ module Example
5
+ class ExampleGroupSubclass < ExampleGroup
6
+ class << self
7
+ attr_accessor :examples_ran
8
+ end
9
+
10
+ @@class_variable = :class_variable
11
+ CONSTANT = :constant
12
+
13
+ before(:each) do
14
+ @instance_variable = :instance_variable
15
+ end
16
+
17
+ after(:all) do
18
+ self.class.examples_ran = true
19
+ end
20
+
21
+ def a_method
22
+ 22
23
+ end
24
+
25
+ it "can access instance variables defined before(:each)" do
26
+ @instance_variable.should == :instance_variable
27
+ end
28
+
29
+ it "can access class variables" do
30
+ @@class_variable.should == :class_variable
31
+ end
32
+
33
+ it "can access constants" do
34
+ CONSTANT.should == :constant
35
+ end
36
+
37
+ it "can access methods defined in the Example Group" do
38
+ a_method.should == 22
39
+ end
40
+
41
+ end
42
+
43
+ describe ExampleGroupSubclass do
44
+ it "should run" do
45
+ ExampleGroupSubclass.examples_ran.should be_true
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,224 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ module Spec
4
+ module Example
5
+ describe ExampleGroupFactory do
6
+ describe "#get" do
7
+ attr_reader :example_group
8
+ before(:each) do
9
+ @example_group_class = Class.new(ExampleGroupDouble)
10
+ ExampleGroupFactory.register(:registered_type, @example_group_class)
11
+ end
12
+
13
+ after(:each) do
14
+ ExampleGroupFactory.reset
15
+ end
16
+
17
+ it "should return the default ExampleGroup type for nil" do
18
+ ExampleGroupFactory.get(nil).should == ExampleGroup
19
+ end
20
+
21
+ it "should return the default ExampleGroup for an unregistered non-nil value" do
22
+ ExampleGroupFactory.get(:does_not_exist).should == ExampleGroup
23
+ end
24
+
25
+ it "should return custom type if registered" do
26
+ ExampleGroupFactory.get(:registered_type).should == @example_group_class
27
+ end
28
+
29
+ it "should return the actual type when that is what is submitted" do
30
+ ExampleGroupFactory.get(@example_group_class).should == @example_group_class
31
+ end
32
+
33
+ it "should get the custom type after setting the default" do
34
+ @alternate_example_group_class = Class.new(ExampleGroupDouble)
35
+ ExampleGroupFactory.default(@alternate_example_group_class)
36
+ ExampleGroupFactory.get(:registered_type).should == @example_group_class
37
+ end
38
+ end
39
+
40
+ describe "#create_example_group" do
41
+ attr_reader :parent_example_group
42
+ before do
43
+ @parent_example_group = Class.new(ExampleGroupDouble) do
44
+ def initialize(*args, &block)
45
+ ;
46
+ end
47
+ end
48
+ end
49
+
50
+ it "should create a uniquely named class" do
51
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group("example_group") {}
52
+ example_group.name.should =~ /Spec::Example::ExampleGroup::Subclass_\d+/
53
+ end
54
+
55
+ it "should create a Spec::Example::Example subclass by default" do
56
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group("example_group") {}
57
+ example_group.superclass.should == Spec::Example::ExampleGroup
58
+ end
59
+
60
+ it "should raise when no description is given" do
61
+ lambda {
62
+ Spec::Example::ExampleGroupFactory.create_example_group do; end
63
+ }.should raise_error(ArgumentError)
64
+ end
65
+
66
+ it "should raise when no block is given" do
67
+ lambda { Spec::Example::ExampleGroupFactory.create_example_group "foo" }.should raise_error(ArgumentError)
68
+ end
69
+
70
+ it "should run registered ExampleGroups" do
71
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group "The ExampleGroup" do end
72
+ Spec::Runner.options.example_groups.should include(example_group)
73
+ end
74
+
75
+ it "should not run unregistered ExampleGroups" do
76
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group "The ExampleGroup" do Spec::Runner.options.remove_example_group self; end
77
+ Spec::Runner.options.example_groups.should_not include(example_group)
78
+ end
79
+
80
+ describe "with :type => :default" do
81
+ it "should create a Spec::Example::ExampleGroup" do
82
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group(
83
+ "example_group", :type => :default
84
+ ) {}
85
+ example_group.superclass.should == Spec::Example::ExampleGroup
86
+ end
87
+ end
88
+
89
+ describe "with :type => :something_other_than_default" do
90
+ it "should create the specified type" do
91
+ Spec::Example::ExampleGroupFactory.register(:something_other_than_default, parent_example_group)
92
+ non_default_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
93
+ "example_group", :type => :something_other_than_default
94
+ ) {}
95
+ non_default_example_group.superclass.should == parent_example_group
96
+ end
97
+ end
98
+
99
+ it "should create a type indicated by :spec_path" do
100
+ Spec::Example::ExampleGroupFactory.register(:something_other_than_default, parent_example_group)
101
+ custom_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
102
+ "example_group", :spec_path => "./spec/something_other_than_default/some_spec.rb"
103
+ ) {}
104
+ custom_example_group.superclass.should == parent_example_group
105
+ end
106
+
107
+ it "should create a type indicated by :spec_path (with spec_path generated by caller on windows)" do
108
+ Spec::Example::ExampleGroupFactory.register(:something_other_than_default, parent_example_group)
109
+ custom_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
110
+ "example_group",
111
+ :spec_path => "./spec\\something_other_than_default\\some_spec.rb"
112
+ ) {}
113
+ custom_example_group.superclass.should == parent_example_group
114
+ end
115
+
116
+ it "should create a type indicated by spec_path for a path-like key" do
117
+ Spec::Example::ExampleGroupFactory.register('path/to/custom/', parent_example_group)
118
+ custom_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
119
+ "example_group", :spec_path => "./spec/path/to/custom/some_spec.rb"
120
+ ) {}
121
+ custom_example_group.superclass.should == parent_example_group
122
+ end
123
+
124
+ it "should use the longest key that matches when creating a type indicated by spec_path" do
125
+ longer = Class.new parent_example_group
126
+ Spec::Example::ExampleGroupFactory.register(:longer, longer)
127
+ long = Class.new parent_example_group
128
+ Spec::Example::ExampleGroupFactory.register(:long, long)
129
+ custom_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
130
+ "example_group", :spec_path => "./spec/longer/some_spec.rb"
131
+ ) {}
132
+ custom_example_group.superclass.should == longer
133
+ end
134
+
135
+ it "sets the spec_path from the caller" do
136
+ options = {}
137
+ shared_example_group = Spec::Example::ExampleGroupFactory.create_example_group("foo", options) {}
138
+ options[:spec_path].should =~ /#{__FILE__}:#{__LINE__ - 1}/
139
+ end
140
+
141
+ describe "with :shared => true" do
142
+ def shared_example_group
143
+ @shared_example_group ||= Spec::Example::ExampleGroupFactory.create_example_group(
144
+ "name", :spec_path => '/blah/spec/models/blah.rb', :type => :controller, :shared => true
145
+ ) {}
146
+ end
147
+
148
+ it "should create and register a Spec::Example::SharedExampleGroup" do
149
+ shared_example_group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
150
+ SharedExampleGroup.should include(shared_example_group)
151
+ end
152
+ end
153
+
154
+ it "should favor the :type over the :spec_path" do
155
+ Spec::Example::ExampleGroupFactory.register(:something_other_than_default, parent_example_group)
156
+ custom_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
157
+ "name", :spec_path => '/blah/spec/models/blah.rb', :type => :something_other_than_default
158
+ ) {}
159
+ custom_example_group.superclass.should == parent_example_group
160
+ end
161
+
162
+ it "should register ExampleGroup by default" do
163
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
164
+ end
165
+ Spec::Runner.options.example_groups.should include(example_group)
166
+ end
167
+
168
+ it "should enable unregistering of ExampleGroups" do
169
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
170
+ Spec::Runner.options.remove_example_group self
171
+ end
172
+ Spec::Runner.options.example_groups.should_not include(example_group)
173
+ end
174
+
175
+ after(:each) do
176
+ Spec::Example::ExampleGroupFactory.reset
177
+ end
178
+ end
179
+
180
+ describe "#create_shared_example_group" do
181
+ it "registers a new shared example group" do
182
+ shared_example_group = Spec::Example::ExampleGroupFactory.create_shared_example_group("something shared") {}
183
+ shared_example_group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
184
+ SharedExampleGroup.should include(shared_example_group)
185
+ end
186
+
187
+ it "sets the spec_path from the caller" do
188
+ options = {}
189
+ shared_example_group = Spec::Example::ExampleGroupFactory.create_shared_example_group("foo", options) {}
190
+ options[:spec_path].should =~ /#{__FILE__}:#{__LINE__ - 1}/
191
+ end
192
+ end
193
+
194
+ describe "#registered_or_ancestor_of_registered?" do
195
+ before(:each) do
196
+ @unregistered_parent = Class.new(ExampleGroupDouble)
197
+ @registered_child = Class.new(@unregistered_parent)
198
+ @unregistered_grandchild = Class.new(@registered_child)
199
+ Spec::Example::ExampleGroupFactory.register :registered_child, @registered_child
200
+ end
201
+
202
+ it "should return true for empty list" do
203
+ Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([]).should be_true
204
+ end
205
+
206
+ it "should return true for a registered example group class" do
207
+ Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([@registered_child]).should be_true
208
+ end
209
+
210
+ it "should return true for an ancestor of a registered example_group_classes" do
211
+ Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([@unregistered_parent]).should be_true
212
+ end
213
+
214
+ it "should return false for a subclass of a registered example_group_class" do
215
+ Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([@unregistered_grandchild]).should be_false
216
+ end
217
+
218
+ after(:each) do
219
+ Spec::Example::ExampleGroupFactory.reset
220
+ end
221
+ end
222
+ end
223
+ end
224
+ end
@@ -0,0 +1,653 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Spec
4
+ module Example
5
+ describe 'ExampleGroupMethods' do
6
+ with_sandboxed_options do
7
+ attr_reader :example_group, :result, :reporter
8
+ before(:each) do
9
+ # See http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/525-arity-changed-on-partial-mocks#ticket-525-2
10
+ method_with_three_args = lambda { |arg1, arg2, arg3| }
11
+ options.formatters << mock("formatter", :null_object => true, :example_pending => method_with_three_args)
12
+ options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
13
+ @reporter = FakeReporter.new(@options)
14
+ options.reporter = reporter
15
+ @example_group = Class.new(ExampleGroupDouble) do
16
+ describe("ExampleGroup")
17
+ it "does nothing"
18
+ end
19
+ end
20
+
21
+ after(:each) do
22
+ ExampleGroup.reset
23
+ end
24
+
25
+ ["describe","context"].each do |method|
26
+ describe "##{method}" do
27
+ describe "when creating an ExampleGroup" do
28
+ before(:each) do
29
+ @parent_example_group = Class.new(ExampleGroupDouble) do
30
+ example "first example" do; end
31
+ end
32
+ @child_example_group = @parent_example_group.__send__ method, "Child" do
33
+ example "second example" do; end
34
+ end
35
+ end
36
+
37
+ it "should create a subclass of the ExampleGroup when passed a block" do
38
+ @child_example_group.superclass.should == @parent_example_group
39
+ options.example_groups.should include(@child_example_group)
40
+ end
41
+
42
+ it "should not inherit examples" do
43
+ @child_example_group.should have(1).examples
44
+ end
45
+
46
+ it "records the spec path" do
47
+ @child_example_group.spec_path.should =~ /#{__FILE__}:#{__LINE__ - 15}/
48
+ end
49
+ end
50
+
51
+ describe "when creating a SharedExampleGroup" do
52
+ before(:each) do
53
+ @shared_example_group = @example_group.__send__ method, "A Shared ExampleGroup", :shared => true do; end
54
+ end
55
+
56
+ after(:each) do
57
+ SharedExampleGroup.instance_eval{@shared_example_groups}.delete @shared_example_group
58
+ end
59
+
60
+ it "should create a SharedExampleGroup" do
61
+ @shared_example_group.should_not be_nil
62
+ SharedExampleGroup.find("A Shared ExampleGroup").should == @shared_example_group
63
+ end
64
+ end
65
+
66
+ end
67
+ end
68
+
69
+ [:specify, :it].each do |method|
70
+ describe "##{method.to_s}" do
71
+ it "should should create an example" do
72
+ lambda {
73
+ @example_group.__send__(method, "")
74
+ }.should change { @example_group.examples.length }.by(1)
75
+ end
76
+ end
77
+ end
78
+
79
+ [:xit, :xspecify].each do |method|
80
+ describe "##{method.to_s}" do
81
+ before(:each) do
82
+ Kernel.stub!(:warn)
83
+ end
84
+
85
+ it "should NOT create an example" do
86
+ lambda {
87
+ @example_group.__send__(method,"")
88
+ }.should_not change(@example_group.examples, :length)
89
+ end
90
+
91
+ it "should warn that the example is disabled" do
92
+ Kernel.should_receive(:warn).with("Example disabled: foo")
93
+ @example_group.__send__(method,"foo")
94
+ end
95
+ end
96
+ end
97
+
98
+
99
+ describe "#examples" do
100
+ it "should have Examples" do
101
+ example_group = Class.new(ExampleGroupDouble) do
102
+ it "should exist" do; end
103
+ end
104
+ example_group.examples.length.should == 1
105
+ example_group.examples.first.description.should == "should exist"
106
+ end
107
+
108
+ it "should not include methods that begin with test (only when TU interop is loaded)" do
109
+ example_group = Class.new(ExampleGroupDouble) do
110
+ def test_any_args(*args)
111
+ true.should be_true
112
+ end
113
+ def test_something
114
+ 1.should == 1
115
+ end
116
+ def test
117
+ raise "This is not a real test"
118
+ end
119
+ def testify
120
+ raise "This is not a real test"
121
+ end
122
+ def should_something
123
+ # forces the run
124
+ end
125
+ end
126
+ example_group.examples.length.should == 1
127
+ example_group.run(options).should be_true
128
+ end
129
+
130
+ it "should include methods that begin with should and has an arity of 0 in suite" do
131
+ example_group = Class.new(ExampleGroupDouble) do
132
+ def shouldCamelCase
133
+ true.should be_true
134
+ end
135
+ def should_any_args(*args)
136
+ true.should be_true
137
+ end
138
+ def should_something
139
+ 1.should == 1
140
+ end
141
+ def should_not_something
142
+ 1.should_not == 2
143
+ end
144
+ def should
145
+ raise "This is not a real example"
146
+ end
147
+ def should_not
148
+ raise "This is not a real example"
149
+ end
150
+ end
151
+ example_group.should have(4).examples
152
+ descriptions = example_group.examples.collect {|example| example.description.to_s}
153
+ descriptions.should include(
154
+ "shouldCamelCase",
155
+ "should_any_args",
156
+ "should_something",
157
+ "should_not_something")
158
+ descriptions.should_not include(
159
+ "should",
160
+ "should_not"
161
+ )
162
+ end
163
+
164
+ it "should not include methods that begin with test_ and has an arity > 0 in suite" do
165
+ example_group = Class.new(ExampleGroupDouble) do
166
+ def test_invalid(foo)
167
+ 1.should == 1
168
+ end
169
+ def testInvalidCamelCase(foo)
170
+ 1.should == 1
171
+ end
172
+ end
173
+ example_group.should have(:no).examples
174
+ end
175
+
176
+ it "should not include methods that begin with should_ and has an arity > 0 in suite" do
177
+ example_group = Class.new(ExampleGroupDouble) do
178
+ def should_invalid(foo)
179
+ 1.should == 2
180
+ end
181
+ def shouldInvalidCamelCase(foo)
182
+ 1.should == 3
183
+ end
184
+ def should_not_invalid(foo)
185
+ 1.should == 4
186
+ end
187
+ def should_valid
188
+ 1.should == 1
189
+ end
190
+ end
191
+ example_group.should have(1).examples
192
+ example_group.run(options).should be_true
193
+ end
194
+
195
+ it "should run should_methods" do
196
+ example_group = Class.new(ExampleGroupDouble) do
197
+ def should_valid
198
+ 1.should == 2
199
+ end
200
+ end
201
+ example_group.should have(1).examples
202
+ example_group.run(options).should be_false
203
+ end
204
+ end
205
+
206
+ describe "#set_description" do
207
+ attr_reader :example_group
208
+ before do
209
+ class << example_group
210
+ public :set_description
211
+ end
212
+ end
213
+
214
+ describe "given a String" do
215
+ before(:each) do
216
+ example_group.set_description("abc")
217
+ end
218
+
219
+ specify ".description should return the String passed into .set_description" do
220
+ example_group.description.should == "abc"
221
+ end
222
+
223
+ specify ".described_type should provide nil as its type" do
224
+ example_group.described_type.should be_nil
225
+ end
226
+ end
227
+
228
+ describe "given a Class" do
229
+ before(:each) do
230
+ example_group.set_description(ExampleGroup)
231
+ end
232
+
233
+ specify ".description should return a String representation of that type (fully qualified) as its name" do
234
+ example_group.description.should == "Spec::Example::ExampleGroup"
235
+ end
236
+
237
+ specify ".described_type should return the passed in type" do
238
+ example_group.described_type.should == Spec::Example::ExampleGroup
239
+ end
240
+ end
241
+
242
+ describe "given a String and a Class" do
243
+ before(:each) do
244
+ example_group.set_description("behaving", ExampleGroup)
245
+ end
246
+
247
+ specify ".description should return String then space then Type" do
248
+ example_group.description.should == "behaving Spec::Example::ExampleGroup"
249
+ end
250
+
251
+ specify ".described_type should return the passed in type" do
252
+ example_group.described_type.should == Spec::Example::ExampleGroup
253
+ end
254
+ end
255
+
256
+ describe "given a Class and a String (starting with an alpha char)" do
257
+ before(:each) do
258
+ example_group.set_description(ExampleGroup, "behaving")
259
+ end
260
+
261
+ specify ".description should return the Type then space then String" do
262
+ example_group.description.should == "Spec::Example::ExampleGroup behaving"
263
+ end
264
+ end
265
+
266
+ describe "given a Class and a String (starting with a '.')" do
267
+ before(:each) do
268
+ example_group.set_description(ExampleGroup, ".behaving")
269
+ end
270
+
271
+ specify ".description should return the Type then String" do
272
+ example_group.description.should == "Spec::Example::ExampleGroup.behaving"
273
+ end
274
+ end
275
+
276
+ describe "#set_description(Class, String starting with #)" do
277
+ before(:each) do
278
+ example_group.set_description(ExampleGroup, "#behaving")
279
+ end
280
+
281
+ specify "should return the Class then String" do
282
+ example_group.description.should == "Spec::Example::ExampleGroup#behaving"
283
+ end
284
+ end
285
+
286
+ describe "#set_description(Class, String containing .)" do
287
+ before(:each) do
288
+ example_group.set_description(ExampleGroup, "calling a.b")
289
+ end
290
+
291
+ specify ".description should return the Type then space then String" do
292
+ example_group.description.should == "Spec::Example::ExampleGroup calling a.b"
293
+ end
294
+ end
295
+
296
+ describe "#set_description(Class, String containing #)" do
297
+ before(:each) do
298
+ example_group.set_description(ExampleGroup, "is #1")
299
+ end
300
+
301
+ specify ".description should return the Type then space then String" do
302
+ example_group.description.should == "Spec::Example::ExampleGroup is #1"
303
+ end
304
+ end
305
+
306
+ describe "#set_description(String, Type, String)" do
307
+ before(:each) do
308
+ example_group.set_description("A", Hash, "with one entry")
309
+ end
310
+
311
+ specify ".description should return the first String then space then Type then second String" do
312
+ example_group.description.should == "A Hash with one entry"
313
+ end
314
+ end
315
+
316
+ describe "#set_description(Hash representing options)" do
317
+ before(:each) do
318
+ example_group.set_description(:a => "b", :spec_path => "blah")
319
+ end
320
+
321
+ it ".spec_path should expand the passed in :spec_path option passed into the constructor" do
322
+ example_group.spec_path.should == File.expand_path("blah")
323
+ end
324
+
325
+ it ".description_options should return all the options passed in" do
326
+ example_group.description_options.should == {:a => "b", :spec_path => "blah"}
327
+ end
328
+
329
+ end
330
+ end
331
+
332
+ describe "#description" do
333
+ it "should return the same description instance for each call" do
334
+ example_group.description.should eql(example_group.description)
335
+ end
336
+
337
+ it "should not add a space when description_text begins with #" do
338
+ child_example_group = Class.new(example_group) do
339
+ describe("#foobar", "Does something")
340
+ end
341
+ child_example_group.description.should == "ExampleGroup#foobar Does something"
342
+ end
343
+
344
+ it "should not add a space when description_text begins with ." do
345
+ child_example_group = Class.new(example_group) do
346
+ describe(".foobar", "Does something")
347
+ end
348
+ child_example_group.description.should == "ExampleGroup.foobar Does something"
349
+ end
350
+
351
+ it "should return the class name if nil" do
352
+ example_group.set_description(nil)
353
+ example_group.description.should =~ /Class:/
354
+ end
355
+
356
+ it "should return the class name if nil" do
357
+ example_group.set_description("")
358
+ example_group.description.should =~ /Class:/
359
+ end
360
+
361
+ it "is cached" do
362
+ example_group.set_description("describe me")
363
+ example_group.description.should be(example_group.description)
364
+ end
365
+ end
366
+
367
+ describe "#description_parts" do
368
+ it "should return an Array of the current class description args" do
369
+ example_group.description_parts.should == [example_group.description]
370
+ end
371
+
372
+ it "should return an Array of the description args from each class in the hierarchy" do
373
+ parent_example_group = Class.new(ExampleGroupDouble) do
374
+ describe("Parent")
375
+ end
376
+
377
+ child_example_group = Class.new(parent_example_group)
378
+ child_example_group.describe("Child", ExampleGroup)
379
+ child_example_group.description.should_not be_empty
380
+
381
+ grand_child_example_group = Class.new(child_example_group)
382
+ grand_child_example_group.describe("GrandChild", ExampleGroup)
383
+ grand_child_example_group.description.should_not be_empty
384
+
385
+ grand_child_example_group.description_parts.should == [
386
+ "Parent",
387
+ "Child",
388
+ Spec::Example::ExampleGroup,
389
+ "GrandChild",
390
+ Spec::Example::ExampleGroup
391
+ ]
392
+ end
393
+
394
+ it "caches the description parts" do
395
+ example_group.description_parts.should equal(example_group.description_parts)
396
+ end
397
+ end
398
+
399
+ describe "#described_type" do
400
+ it "should return passed in type" do
401
+ child_example_group = Class.new(example_group) do
402
+ describe Object
403
+ end
404
+ child_example_group.described_type.should == Object
405
+ end
406
+
407
+ it "should return #described_type of superclass when no passed in type" do
408
+ parent_example_group = Class.new(ExampleGroupDouble) do
409
+ describe Object, "#foobar"
410
+ end
411
+ child_example_group = Class.new(parent_example_group) do
412
+ describe "not a type"
413
+ end
414
+ child_example_group.described_type.should == Object
415
+ end
416
+
417
+ it "is cached per example group" do
418
+ klass = Class.new
419
+ group = Class.new(ExampleGroupDouble) do
420
+ describe(klass)
421
+ end
422
+ group.should_receive(:description_parts).once.and_return([klass])
423
+ group.described_type
424
+ group.described_type
425
+ end
426
+ end
427
+
428
+ describe "#remove_after" do
429
+ it "should unregister a given after(:each) block" do
430
+ after_all_ran = false
431
+ proc = Proc.new { after_all_ran = true }
432
+
433
+ example_group = Class.new(ExampleGroupDouble) do
434
+ specify("example") {}
435
+ after(:each, &proc)
436
+ end
437
+
438
+ example_group.run(options)
439
+ after_all_ran.should be_true
440
+
441
+ after_all_ran = false
442
+ example_group.remove_after(:each, &proc)
443
+ example_group.run(options)
444
+ after_all_ran.should be_false
445
+ end
446
+ end
447
+
448
+ describe "#include" do
449
+ it "should have accessible class methods from included module" do
450
+ mod_method_called = false
451
+ mod = Module.new do
452
+ class_methods = Module.new do
453
+ define_method :mod_method do
454
+ mod_method_called = true
455
+ end
456
+ end
457
+
458
+ self.class.class_eval do
459
+ define_method(:included) do |receiver|
460
+ receiver.extend class_methods
461
+ end
462
+ end
463
+ end
464
+
465
+ @example_group.__send__ :include, mod
466
+
467
+ @example_group.mod_method
468
+ mod_method_called.should be_true
469
+ end
470
+ end
471
+
472
+ describe "#number_of_examples" do
473
+ it "should count number of examples" do
474
+ proc do
475
+ @example_group.it("one") {}
476
+ @example_group.it("two") {}
477
+ @example_group.it("three") {}
478
+ @example_group.it("four") {}
479
+ end.should change {@example_group.number_of_examples}.by(4)
480
+ end
481
+ end
482
+
483
+ describe "#class_eval" do
484
+ it "should allow constants to be defined" do
485
+ example_group = Class.new(ExampleGroupDouble) do
486
+ FOO = 1
487
+ it "should reference FOO" do
488
+ FOO.should == 1
489
+ end
490
+ end
491
+ success = example_group.run(options)
492
+ success.should be_true
493
+ Object.const_defined?(:FOO).should == false
494
+ end
495
+ end
496
+
497
+ describe '#register' do
498
+ after(:each) do
499
+ Spec::Runner.options.remove_example_group example_group
500
+ end
501
+ it "should add ExampleGroup to set of ExampleGroups to be run" do
502
+ Spec::Runner.options.add_example_group example_group
503
+ options.example_groups.should include(example_group)
504
+ end
505
+ end
506
+
507
+ describe '#remove_example_group' do
508
+ before(:each) do
509
+ Spec::Runner.options.add_example_group example_group
510
+ end
511
+ it "should remove ExampleGroup from set of ExampleGroups to be run" do
512
+ Spec::Runner.options.remove_example_group example_group
513
+ options.example_groups.should_not include(example_group)
514
+ end
515
+ end
516
+
517
+ describe "#run" do
518
+ describe "given an example group with at least one example" do
519
+ it "should call add_example_group" do
520
+ example_group = Class.new(ExampleGroupDouble) do
521
+ example("anything") {}
522
+ end
523
+ reporter.should_receive(:add_example_group)
524
+ example_group.run(options)
525
+ end
526
+ end
527
+
528
+ describe "given an example group with no examples" do
529
+ it "should NOT call add_example_group" do
530
+ example_group = Class.new(ExampleGroupDouble) do end
531
+ reporter.should_not_receive(:add_example_group)
532
+ example_group.run(options)
533
+ end
534
+ end
535
+ end
536
+
537
+ describe "#matcher_class=" do
538
+ it "should call new and matches? on the class used for matching examples" do
539
+ example_group = Class.new(ExampleGroupDouble) do
540
+ it "should do something" do end
541
+ def self.specified_examples
542
+ ["something"]
543
+ end
544
+ def self.to_s
545
+ "TestMatcher"
546
+ end
547
+ end
548
+
549
+ matcher = mock("matcher")
550
+ matcher.should_receive(:matches?).with(["something"]).any_number_of_times
551
+
552
+ matcher_class = Class.new
553
+ matcher_class.should_receive(:new).with("TestMatcher", "should do something").and_return(matcher)
554
+
555
+ begin
556
+ ExampleGroupMethods.matcher_class = matcher_class
557
+
558
+ example_group.run(options)
559
+ ensure
560
+ ExampleGroupMethods.matcher_class = ExampleMatcher
561
+ end
562
+ end
563
+ end
564
+
565
+ describe "#options" do
566
+ it "should expose the options hash" do
567
+ group = describe("group", :this => 'hash') {}
568
+ group.options[:this].should == 'hash'
569
+ end
570
+ end
571
+
572
+ describe "#backtrace" do
573
+ it "returns the backtrace from where the example group was defined" do
574
+ example_group = Class.new(ExampleGroupDouble).describe("foo") do
575
+ example "bar" do; end
576
+ end
577
+ example_group.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-3}")
578
+ end
579
+ end
580
+
581
+ describe "#example_group_backtrace (deprecated)" do
582
+ before(:each) do
583
+ Kernel.stub!(:warn)
584
+ end
585
+ it "sends a deprecation warning" do
586
+ example_group = Class.new(ExampleGroupDouble) {}
587
+ Kernel.should_receive(:warn).with(/#example_group_backtrace.*deprecated.*#backtrace instead/m)
588
+ example_group.example_group_backtrace
589
+ end
590
+
591
+ it "returns the backtrace from where the example group was defined" do
592
+ example_group = Class.new(ExampleGroupDouble).describe("foo") do
593
+ example "bar" do; end
594
+ end
595
+ example_group.example_group_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-3}")
596
+ end
597
+ end
598
+
599
+ describe "#before" do
600
+ it "stores before(:each) blocks" do
601
+ example_group = Class.new(ExampleGroupDouble) {}
602
+ block = lambda {}
603
+ example_group.before(:each, &block)
604
+ example_group.before_each_parts.should include(block)
605
+ end
606
+
607
+ it "stores before(:all) blocks" do
608
+ example_group = Class.new(ExampleGroupDouble) {}
609
+ block = lambda {}
610
+ example_group.before(:all, &block)
611
+ example_group.before_all_parts.should include(block)
612
+ end
613
+
614
+ it "stores before(:suite) blocks" do
615
+ example_group = Class.new(ExampleGroupDouble) {}
616
+ parts = []
617
+ ExampleGroupMethods.stub!(:before_suite_parts).and_return(parts)
618
+ block = lambda {}
619
+ example_group.before(:suite, &block)
620
+ example_group.before_suite_parts.should include(block)
621
+ end
622
+ end
623
+
624
+
625
+ describe "#after" do
626
+ it "stores after(:each) blocks" do
627
+ example_group = Class.new(ExampleGroupDouble) {}
628
+ block = lambda {}
629
+ example_group.after(:each, &block)
630
+ example_group.after_each_parts.should include(block)
631
+ end
632
+
633
+ it "stores after(:all) blocks" do
634
+ example_group = Class.new(ExampleGroupDouble) {}
635
+ block = lambda {}
636
+ example_group.after(:all, &block)
637
+ example_group.after_all_parts.should include(block)
638
+ end
639
+
640
+ it "stores after(:suite) blocks" do
641
+ example_group = Class.new(ExampleGroupDouble) {}
642
+ parts = []
643
+ ExampleGroupMethods.stub!(:after_suite_parts).and_return(parts)
644
+ block = lambda {}
645
+ example_group.after(:suite, &block)
646
+ example_group.after_suite_parts.should include(block)
647
+ end
648
+ end
649
+
650
+ end
651
+ end
652
+ end
653
+ end