newbamboo-rspec 1.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (324) 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/dsl/main.rb +87 -0
  77. data/lib/spec/dsl.rb +1 -0
  78. data/lib/spec/example/before_and_after_hooks.rb +99 -0
  79. data/lib/spec/example/errors.rb +30 -0
  80. data/lib/spec/example/example_group.rb +26 -0
  81. data/lib/spec/example/example_group_factory.rb +98 -0
  82. data/lib/spec/example/example_group_methods.rb +376 -0
  83. data/lib/spec/example/example_matcher.rb +44 -0
  84. data/lib/spec/example/example_methods.rb +137 -0
  85. data/lib/spec/example/module_reopening_fix.rb +21 -0
  86. data/lib/spec/example/pending.rb +18 -0
  87. data/lib/spec/example/shared_example_group.rb +59 -0
  88. data/lib/spec/example.rb +187 -0
  89. data/lib/spec/expectations/differs/default.rb +66 -0
  90. data/lib/spec/expectations/errors.rb +12 -0
  91. data/lib/spec/expectations/extensions/object.rb +63 -0
  92. data/lib/spec/expectations/extensions/string_and_symbol.rb +17 -0
  93. data/lib/spec/expectations/extensions.rb +2 -0
  94. data/lib/spec/expectations/handler.rb +32 -0
  95. data/lib/spec/expectations.rb +60 -0
  96. data/lib/spec/interop/test/unit/autorunner.rb +6 -0
  97. data/lib/spec/interop/test/unit/testcase.rb +73 -0
  98. data/lib/spec/interop/test/unit/testresult.rb +6 -0
  99. data/lib/spec/interop/test/unit/testsuite_adapter.rb +34 -0
  100. data/lib/spec/interop/test/unit/ui/console/testrunner.rb +61 -0
  101. data/lib/spec/interop/test.rb +12 -0
  102. data/lib/spec/matchers/be.rb +208 -0
  103. data/lib/spec/matchers/be_close.rb +21 -0
  104. data/lib/spec/matchers/change.rb +148 -0
  105. data/lib/spec/matchers/eql.rb +25 -0
  106. data/lib/spec/matchers/equal.rb +25 -0
  107. data/lib/spec/matchers/errors.rb +5 -0
  108. data/lib/spec/matchers/exist.rb +16 -0
  109. data/lib/spec/matchers/generated_descriptions.rb +48 -0
  110. data/lib/spec/matchers/has.rb +15 -0
  111. data/lib/spec/matchers/have.rb +150 -0
  112. data/lib/spec/matchers/include.rb +80 -0
  113. data/lib/spec/matchers/match.rb +22 -0
  114. data/lib/spec/matchers/match_array.rb +79 -0
  115. data/lib/spec/matchers/method_missing.rb +9 -0
  116. data/lib/spec/matchers/operator_matcher.rb +70 -0
  117. data/lib/spec/matchers/raise_error.rb +128 -0
  118. data/lib/spec/matchers/respond_to.rb +71 -0
  119. data/lib/spec/matchers/satisfy.rb +47 -0
  120. data/lib/spec/matchers/simple_matcher.rb +132 -0
  121. data/lib/spec/matchers/throw_symbol.rb +106 -0
  122. data/lib/spec/matchers/wrap_expectation.rb +55 -0
  123. data/lib/spec/matchers.rb +141 -0
  124. data/lib/spec/mocks/argument_expectation.rb +49 -0
  125. data/lib/spec/mocks/argument_matchers.rb +237 -0
  126. data/lib/spec/mocks/error_generator.rb +82 -0
  127. data/lib/spec/mocks/errors.rb +10 -0
  128. data/lib/spec/mocks/extensions/object.rb +3 -0
  129. data/lib/spec/mocks/extensions.rb +1 -0
  130. data/lib/spec/mocks/framework.rb +15 -0
  131. data/lib/spec/mocks/message_expectation.rb +331 -0
  132. data/lib/spec/mocks/methods.rb +51 -0
  133. data/lib/spec/mocks/mock.rb +55 -0
  134. data/lib/spec/mocks/order_group.rb +29 -0
  135. data/lib/spec/mocks/proxy.rb +230 -0
  136. data/lib/spec/mocks/space.rb +28 -0
  137. data/lib/spec/mocks/spec_methods.rb +55 -0
  138. data/lib/spec/mocks.rb +200 -0
  139. data/lib/spec/rake/spectask.rb +225 -0
  140. data/lib/spec/rake/verify_rcov.rb +52 -0
  141. data/lib/spec/ruby.rb +9 -0
  142. data/lib/spec/runner/backtrace_tweaker.rb +58 -0
  143. data/lib/spec/runner/class_and_arguments_parser.rb +14 -0
  144. data/lib/spec/runner/command_line.rb +35 -0
  145. data/lib/spec/runner/configuration.rb +166 -0
  146. data/lib/spec/runner/drb_command_line.rb +20 -0
  147. data/lib/spec/runner/example_group_runner.rb +70 -0
  148. data/lib/spec/runner/formatter/base_formatter.rb +79 -0
  149. data/lib/spec/runner/formatter/base_text_formatter.rb +127 -0
  150. data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +27 -0
  151. data/lib/spec/runner/formatter/failing_examples_formatter.rb +20 -0
  152. data/lib/spec/runner/formatter/html_formatter.rb +340 -0
  153. data/lib/spec/runner/formatter/nested_text_formatter.rb +65 -0
  154. data/lib/spec/runner/formatter/profile_formatter.rb +51 -0
  155. data/lib/spec/runner/formatter/progress_bar_formatter.rb +34 -0
  156. data/lib/spec/runner/formatter/snippet_extractor.rb +52 -0
  157. data/lib/spec/runner/formatter/specdoc_formatter.rb +39 -0
  158. data/lib/spec/runner/formatter/text_mate_formatter.rb +16 -0
  159. data/lib/spec/runner/heckle_runner.rb +74 -0
  160. data/lib/spec/runner/heckle_runner_unsupported.rb +10 -0
  161. data/lib/spec/runner/option_parser.rb +204 -0
  162. data/lib/spec/runner/options.rb +320 -0
  163. data/lib/spec/runner/reporter.rb +167 -0
  164. data/lib/spec/runner/spec_parser.rb +73 -0
  165. data/lib/spec/runner.rb +88 -0
  166. data/lib/spec/version.rb +15 -0
  167. data/lib/spec.rb +7 -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/rspec.gemspec +32 -0
  178. data/spec/README.jruby +15 -0
  179. data/spec/autotest/autotest_helper.rb +6 -0
  180. data/spec/autotest/autotest_matchers.rb +47 -0
  181. data/spec/autotest/discover_spec.rb +8 -0
  182. data/spec/autotest/failed_results_re_spec.rb +24 -0
  183. data/spec/autotest/rspec_spec.rb +114 -0
  184. data/spec/rspec_suite.rb +6 -0
  185. data/spec/ruby_forker.rb +13 -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.opts +6 -0
  323. data/spec/spec_helper.rb +107 -0
  324. metadata +388 -0
@@ -0,0 +1,661 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Spec
4
+ module Example
5
+ class ExampleModuleScopingSpec < ExampleGroup
6
+ describe ExampleGroup, "via a class definition"
7
+
8
+ module Foo
9
+ module Bar
10
+ def self.loaded?; true; end
11
+ end
12
+ end
13
+ include Foo
14
+
15
+ it "should understand module scoping" do
16
+ Bar.should be_loaded
17
+ end
18
+
19
+ @@foo = 1
20
+
21
+ it "should allow class variables to be defined" do
22
+ @@foo.should == 1
23
+ end
24
+ end
25
+
26
+ class ExampleClassVariablePollutionSpec < ExampleGroup
27
+ describe ExampleGroup, "via a class definition without a class variable"
28
+
29
+ it "should not retain class variables from other Example classes" do
30
+ proc do
31
+ @@foo
32
+ end.should raise_error
33
+ end
34
+ end
35
+
36
+ describe ExampleGroup, "#pending" do
37
+ it "should raise a Pending error when its block fails" do
38
+ block_ran = false
39
+ lambda {
40
+ pending("something") do
41
+ block_ran = true
42
+ raise "something wrong with my example"
43
+ end
44
+ }.should raise_error(Spec::Example::ExamplePendingError, "something")
45
+ block_ran.should == true
46
+ end
47
+
48
+ it "should raise Spec::Example::PendingExampleFixedError when its block does not fail" do
49
+ block_ran = false
50
+ lambda {
51
+ pending("something") do
52
+ block_ran = true
53
+ end
54
+ }.should raise_error(Spec::Example::PendingExampleFixedError, "Expected pending 'something' to fail. No Error was raised.")
55
+ block_ran.should == true
56
+ end
57
+ end
58
+
59
+ describe ExampleGroup, "#run with failure in example", :shared => true do
60
+ it "should add an example failure to the TestResult" do
61
+ example_group.run(options).should be_false
62
+ end
63
+ end
64
+
65
+ describe ExampleGroup, "#run" do
66
+ with_sandboxed_options do
67
+ attr_reader :example_group, :formatter, :reporter
68
+ before :each do
69
+ method_with_three_args = lambda { |arg1, arg2, arg3| }
70
+ @formatter = mock("formatter", :null_object => true, :example_pending => method_with_three_args)
71
+ options.formatters << formatter
72
+ options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
73
+ @reporter = FakeReporter.new(options)
74
+ options.reporter = reporter
75
+ @example_group = Class.new(ExampleGroupDouble) do
76
+ describe("example")
77
+ it "does nothing" do
78
+ end
79
+ end
80
+ class << example_group
81
+ public :include
82
+ end
83
+ end
84
+
85
+ after :each do
86
+ ExampleGroup.reset
87
+ end
88
+
89
+ it "should not run when there are no examples" do
90
+ example_group = Class.new(ExampleGroupDouble) do
91
+ describe("Foobar")
92
+ end
93
+ example_group.examples.should be_empty
94
+
95
+ reporter = mock("Reporter")
96
+ reporter.should_not_receive(:add_example_group)
97
+ example_group.run(options)
98
+ end
99
+
100
+ describe "when before_each fails" do
101
+ before(:each) do
102
+ $example_ran = $after_each_ran = false
103
+ @example_group = describe("Foobar") do
104
+ before(:each) {raise}
105
+ it "should not be run" do
106
+ $example_ran = true
107
+ end
108
+ after(:each) do
109
+ $after_each_ran = true
110
+ end
111
+ end
112
+ end
113
+
114
+ it "should not run example block" do
115
+ example_group.run(options)
116
+ $example_ran.should be_false
117
+ end
118
+
119
+ it "should run after_each" do
120
+ example_group.run(options)
121
+ $after_each_ran.should be_true
122
+ end
123
+
124
+ it "should report failure location when in before_each" do
125
+ reporter.should_receive(:example_finished) do |example_group, error|
126
+ error.message.should eql("in before_each")
127
+ end
128
+ example_group.run(options)
129
+ end
130
+ end
131
+
132
+ describe ExampleGroup, "#run on dry run" do
133
+ before do
134
+ @options.dry_run = true
135
+ end
136
+
137
+ it "should not run before(:all) or after(:all)" do
138
+ before_all_ran = false
139
+ after_all_ran = false
140
+ ExampleGroup.before(:all) { before_all_ran = true }
141
+ ExampleGroup.after(:all) { after_all_ran = true }
142
+ example_group.it("should") {}
143
+ example_group.run(options)
144
+ before_all_ran.should be_false
145
+ after_all_ran.should be_false
146
+ end
147
+
148
+ it "should not run example" do
149
+ example_ran = false
150
+ example_group.it("should") {example_ran = true}
151
+ example_group.run(options)
152
+ example_ran.should be_false
153
+ end
154
+ end
155
+
156
+ describe ExampleGroup, "#run with specified examples" do
157
+ attr_reader :examples_that_were_run
158
+ before do
159
+ @examples_that_were_run = []
160
+ end
161
+
162
+ describe "when specified_examples matches entire ExampleGroup" do
163
+ before do
164
+ examples_that_were_run = @examples_that_were_run
165
+ @example_group = Class.new(ExampleGroupDouble) do
166
+ describe("the ExampleGroup")
167
+ it("should be run") do
168
+ examples_that_were_run << 'should be run'
169
+ end
170
+
171
+ it("should also be run") do
172
+ examples_that_were_run << 'should also be run'
173
+ end
174
+ end
175
+ options.parse_example "the ExampleGroup"
176
+ end
177
+
178
+ it "should not run the Examples in the ExampleGroup" do
179
+ example_group.run(options)
180
+ examples_that_were_run.should == ['should be run', 'should also be run']
181
+ end
182
+ end
183
+
184
+ describe ExampleGroup, "#run when specified_examples matches only Example description" do
185
+ before do
186
+ examples_that_were_run = @examples_that_were_run
187
+ @example_group = Class.new(ExampleGroupDouble) do
188
+ describe("example")
189
+ it("should be run") do
190
+ examples_that_were_run << 'should be run'
191
+ end
192
+ end
193
+ options.parse_example "should be run"
194
+ end
195
+
196
+ it "should not run the example" do
197
+ example_group.run(options)
198
+ examples_that_were_run.should == ['should be run']
199
+ end
200
+ end
201
+
202
+ describe ExampleGroup, "#run when specified_examples does not match an Example description" do
203
+ before do
204
+ examples_that_were_run = @examples_that_were_run
205
+ @example_group = Class.new(ExampleGroupDouble) do
206
+ describe("example")
207
+ it("should be something else") do
208
+ examples_that_were_run << 'should be something else'
209
+ end
210
+ end
211
+ options.parse_example "does not match anything"
212
+ end
213
+
214
+ it "should not run the example" do
215
+ example_group.run(options)
216
+ examples_that_were_run.should == []
217
+ end
218
+ end
219
+
220
+ describe ExampleGroup, "#run when specified_examples matches an Example description" do
221
+ before do
222
+ examples_that_were_run = @examples_that_were_run
223
+ @example_group = Class.new(ExampleGroupDouble) do
224
+ describe("example")
225
+ it("should be run") do
226
+ examples_that_were_run << 'should be run'
227
+ end
228
+ it("should not be run") do
229
+ examples_that_were_run << 'should not be run'
230
+ end
231
+ end
232
+ options.parse_example "should be run"
233
+ end
234
+
235
+ it "should run only the example, when there is only one" do
236
+ example_group.run(options)
237
+ examples_that_were_run.should == ["should be run"]
238
+ end
239
+
240
+ it "should run only the one example" do
241
+ example_group.run(options)
242
+ examples_that_were_run.should == ["should be run"] end
243
+ end
244
+ end
245
+
246
+ describe ExampleGroup, "#run with success" do
247
+ before do
248
+ @special_example_group = Class.new(ExampleGroupDouble)
249
+ ExampleGroupFactory.register(:special, @special_example_group)
250
+ @not_special_example_group = Class.new(ExampleGroupDouble)
251
+ ExampleGroupFactory.register(:not_special, @not_special_example_group)
252
+ end
253
+
254
+ after do
255
+ ExampleGroupFactory.reset
256
+ end
257
+
258
+ it "should send reporter add_example_group" do
259
+ example_group.run(options)
260
+ reporter.example_groups.should == [example_group]
261
+ end
262
+
263
+ it "should run example on run" do
264
+ example_ran = false
265
+ example_group.it("should") {example_ran = true}
266
+ example_group.run(options)
267
+ example_ran.should be_true
268
+ end
269
+
270
+ it "should run before(:all) block only once" do
271
+ before_all_run_count_run_count = 0
272
+ example_group.before(:all) {before_all_run_count_run_count += 1}
273
+ example_group.it("test") {true}
274
+ example_group.it("test2") {true}
275
+ example_group.run(options)
276
+ before_all_run_count_run_count.should == 1
277
+ end
278
+
279
+ it "should run after(:all) block only once" do
280
+ after_all_run_count = 0
281
+ example_group.after(:all) {after_all_run_count += 1}
282
+ example_group.it("test") {true}
283
+ example_group.it("test2") {true}
284
+ example_group.run(options)
285
+ after_all_run_count.should == 1
286
+ @reporter.rspec_verify
287
+ end
288
+
289
+ it "after(:all) should have access to all instance variables defined in before(:all)" do
290
+ context_instance_value_in = "Hello there"
291
+ context_instance_value_out = ""
292
+ example_group.before(:all) { @instance_var = context_instance_value_in }
293
+ example_group.after(:all) { context_instance_value_out = @instance_var }
294
+ example_group.it("test") {true}
295
+ example_group.run(options)
296
+ context_instance_value_in.should == context_instance_value_out
297
+ end
298
+
299
+ it "should copy instance variables from before(:all)'s execution context into spec's execution context" do
300
+ context_instance_value_in = "Hello there"
301
+ context_instance_value_out = ""
302
+ example_group.before(:all) { @instance_var = context_instance_value_in }
303
+ example_group.it("test") {context_instance_value_out = @instance_var}
304
+ example_group.run(options)
305
+ context_instance_value_in.should == context_instance_value_out
306
+ end
307
+
308
+ it "should not add global before callbacks for untargetted example_group" do
309
+ fiddle = []
310
+
311
+ ExampleGroup.before(:all) { fiddle << "Example.before(:all)" }
312
+ ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" }
313
+ @special_example_group.before(:each) { fiddle << "Example.before(:each, :type => :special)" }
314
+ @special_example_group.prepend_before(:each) { fiddle << "Example.prepend_before(:each, :type => :special)" }
315
+ @special_example_group.before(:all) { fiddle << "Example.before(:all, :type => :special)" }
316
+ @special_example_group.prepend_before(:all) { fiddle << "Example.prepend_before(:all, :type => :special)" }
317
+
318
+ example_group = Class.new(ExampleGroupDouble) do
319
+ describe("I'm not special", :type => :not_special)
320
+ it "does nothing"
321
+ end
322
+ example_group.run(options)
323
+ fiddle.should == [
324
+ 'Example.prepend_before(:all)',
325
+ 'Example.before(:all)',
326
+ ]
327
+ end
328
+
329
+ it "should add global before callbacks for targetted example_groups" do
330
+ fiddle = []
331
+
332
+ ExampleGroup.before(:all) { fiddle << "Example.before(:all)" }
333
+ ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" }
334
+ @special_example_group.before(:each) { fiddle << "special.before(:each, :type => :special)" }
335
+ @special_example_group.prepend_before(:each) { fiddle << "special.prepend_before(:each, :type => :special)" }
336
+ @special_example_group.before(:all) { fiddle << "special.before(:all, :type => :special)" }
337
+ @special_example_group.prepend_before(:all) { fiddle << "special.prepend_before(:all, :type => :special)" }
338
+ @special_example_group.append_before(:each) { fiddle << "special.append_before(:each, :type => :special)" }
339
+
340
+ example_group = Class.new(@special_example_group).describe("I'm a special example_group") {}
341
+ example_group.it("test") {true}
342
+ example_group.run(options)
343
+ fiddle.should == [
344
+ 'Example.prepend_before(:all)',
345
+ 'Example.before(:all)',
346
+ 'special.prepend_before(:all, :type => :special)',
347
+ 'special.before(:all, :type => :special)',
348
+ 'special.prepend_before(:each, :type => :special)',
349
+ 'special.before(:each, :type => :special)',
350
+ 'special.append_before(:each, :type => :special)',
351
+ ]
352
+ end
353
+
354
+ it "should order before callbacks from global to local" do
355
+ fiddle = []
356
+ ExampleGroup.prepend_before(:all) { fiddle << "Example.prepend_before(:all)" }
357
+ ExampleGroup.before(:all) { fiddle << "Example.before(:all)" }
358
+ example_group.prepend_before(:all) { fiddle << "prepend_before(:all)" }
359
+ example_group.before(:all) { fiddle << "before(:all)" }
360
+ example_group.prepend_before(:each) { fiddle << "prepend_before(:each)" }
361
+ example_group.before(:each) { fiddle << "before(:each)" }
362
+ example_group.run(options)
363
+ fiddle.should == [
364
+ 'Example.prepend_before(:all)',
365
+ 'Example.before(:all)',
366
+ 'prepend_before(:all)',
367
+ 'before(:all)',
368
+ 'prepend_before(:each)',
369
+ 'before(:each)'
370
+ ]
371
+ end
372
+
373
+ it "should order after callbacks from local to global" do
374
+ fiddle = []
375
+ example_group.after(:each) { fiddle << "after(:each)" }
376
+ example_group.append_after(:each) { fiddle << "append_after(:each)" }
377
+ example_group.after(:all) { fiddle << "after(:all)" }
378
+ example_group.append_after(:all) { fiddle << "append_after(:all)" }
379
+ ExampleGroup.after(:all) { fiddle << "Example.after(:all)" }
380
+ ExampleGroup.append_after(:all) { fiddle << "Example.append_after(:all)" }
381
+ example_group.run(options)
382
+ fiddle.should == [
383
+ 'after(:each)',
384
+ 'append_after(:each)',
385
+ 'after(:all)',
386
+ 'append_after(:all)',
387
+ 'Example.after(:all)',
388
+ 'Example.append_after(:all)'
389
+ ]
390
+ end
391
+
392
+ it "should have accessible instance methods from included module" do
393
+ mod1_method_called = false
394
+ mod1 = Module.new do
395
+ define_method :mod1_method do
396
+ mod1_method_called = true
397
+ end
398
+ end
399
+
400
+ mod2_method_called = false
401
+ mod2 = Module.new do
402
+ define_method :mod2_method do
403
+ mod2_method_called = true
404
+ end
405
+ end
406
+
407
+ example_group.include mod1, mod2
408
+
409
+ example_group.it("test") do
410
+ mod1_method
411
+ mod2_method
412
+ end
413
+ example_group.run(options)
414
+ mod1_method_called.should be_true
415
+ mod2_method_called.should be_true
416
+ end
417
+
418
+ it "should include targetted modules included using configuration" do
419
+ mod1 = Module.new
420
+ mod2 = Module.new
421
+ mod3 = Module.new
422
+ Spec::Runner.configuration.include(mod1, mod2)
423
+ Spec::Runner.configuration.include(mod3, :type => :not_special)
424
+
425
+ example_group = Class.new(@special_example_group).describe("I'm special", :type => :special) do
426
+ it "does nothing"
427
+ end
428
+ example_group.run(options)
429
+
430
+ example_group.included_modules.should include(mod1)
431
+ example_group.included_modules.should include(mod2)
432
+ example_group.included_modules.should_not include(mod3)
433
+ end
434
+
435
+ it "should include any predicate_matchers included using configuration" do
436
+ $included_predicate_matcher_found = false
437
+ Spec::Runner.configuration.predicate_matchers[:do_something] = :does_something?
438
+ example_group = Class.new(ExampleGroupDouble) do
439
+ describe('example')
440
+ it "should respond to do_something" do
441
+ $included_predicate_matcher_found = respond_to?(:do_something)
442
+ end
443
+ end
444
+ example_group.run(options)
445
+ $included_predicate_matcher_found.should be(true)
446
+ end
447
+
448
+ it "should use a mock framework set up in config" do
449
+ mod = Module.new do
450
+ def self.included(mod)
451
+ $included_module = mod
452
+ end
453
+
454
+ def teardown_mocks_for_rspec
455
+ $torn_down = true
456
+ end
457
+ end
458
+
459
+ begin
460
+ $included_module = nil
461
+ $torn_down = true
462
+ Spec::Runner.configuration.mock_with mod
463
+
464
+ example_group = Class.new(ExampleGroupDouble) do
465
+ describe('example')
466
+ it "does nothing"
467
+ end
468
+ example_group.run(options)
469
+
470
+ $included_module.should_not be_nil
471
+ $torn_down.should == true
472
+ ensure
473
+ Spec::Runner.configuration.mock_with :rspec
474
+ end
475
+ end
476
+ end
477
+
478
+ describe ExampleGroup, "#run with pending example that has a failing assertion" do
479
+ before do
480
+ example_group.it("should be pending") do
481
+ pending("Example fails") {false.should be_true}
482
+ end
483
+ end
484
+
485
+ it "should send example_pending to formatter" do
486
+ @formatter.should_receive(:example_pending).with("example", "should be pending", "Example fails")
487
+ example_group.run(options)
488
+ end
489
+ end
490
+
491
+ describe ExampleGroup, "#run with pending example that does not have a failing assertion" do
492
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
493
+
494
+ before do
495
+ example_group.it("should be pending") do
496
+ pending("Example passes") {true.should be_true}
497
+ end
498
+ end
499
+
500
+ it "should send example_pending to formatter" do
501
+ @formatter.should_receive(:example_pending).with("example", "should be pending", "Example passes")
502
+ example_group.run(options)
503
+ end
504
+ end
505
+
506
+ describe ExampleGroup, "#run when before(:all) fails" do
507
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
508
+
509
+ before do
510
+ ExampleGroup.before(:all) { raise NonStandardError, "before(:all) failure" }
511
+ end
512
+
513
+ it "should not run any example" do
514
+ spec_ran = false
515
+ example_group.it("test") {spec_ran = true}
516
+ example_group.run(options)
517
+ spec_ran.should be_false
518
+ end
519
+
520
+ it "should run ExampleGroup after(:all)" do
521
+ after_all_ran = false
522
+ ExampleGroup.after(:all) { after_all_ran = true }
523
+ example_group.run(options)
524
+ after_all_ran.should be_true
525
+ end
526
+
527
+ it "should run example_group after(:all)" do
528
+ after_all_ran = false
529
+ example_group.after(:all) { after_all_ran = true }
530
+ example_group.run(options)
531
+ after_all_ran.should be_true
532
+ end
533
+
534
+ it "should supply before(:all) as description" do
535
+ @reporter.should_receive(:failure) do |example, error|
536
+ example.description.should eql("before(:all)")
537
+ error.message.should eql("before(:all) failure")
538
+ end
539
+
540
+ example_group.it("test") {true}
541
+ example_group.run(options)
542
+ end
543
+ end
544
+
545
+ describe ExampleGroup, "#run when before(:each) fails" do
546
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
547
+
548
+ before do
549
+ ExampleGroup.before(:each) { raise NonStandardError }
550
+ end
551
+
552
+ it "should run after(:all)" do
553
+ after_all_ran = false
554
+ ExampleGroup.after(:all) { after_all_ran = true }
555
+ example_group.run(options)
556
+ after_all_ran.should be_true
557
+ end
558
+ end
559
+
560
+ describe ExampleGroup, "#run when any example fails" do
561
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
562
+
563
+ before do
564
+ example_group.it("should") { raise NonStandardError }
565
+ end
566
+
567
+ it "should run after(:all)" do
568
+ after_all_ran = false
569
+ ExampleGroup.after(:all) { after_all_ran = true }
570
+ example_group.run(options)
571
+ after_all_ran.should be_true
572
+ end
573
+ end
574
+
575
+ describe ExampleGroup, "#run when first after(:each) block fails" do
576
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
577
+
578
+ before do
579
+ class << example_group
580
+ attr_accessor :first_after_ran, :second_after_ran
581
+ end
582
+ example_group.first_after_ran = false
583
+ example_group.second_after_ran = false
584
+
585
+ example_group.after(:each) do
586
+ self.class.second_after_ran = true
587
+ end
588
+ example_group.after(:each) do
589
+ self.class.first_after_ran = true
590
+ raise "first"
591
+ end
592
+ end
593
+
594
+ it "should run second after(:each) block" do
595
+ reporter.should_receive(:example_finished) do |example, error|
596
+ example.should equal(example)
597
+ error.message.should eql("first")
598
+ end
599
+ example_group.run(options)
600
+ example_group.first_after_ran.should be_true
601
+ example_group.second_after_ran.should be_true
602
+ end
603
+ end
604
+
605
+ describe ExampleGroup, "#run when first before(:each) block fails" do
606
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
607
+
608
+ before do
609
+ class << example_group
610
+ attr_accessor :first_before_ran, :second_before_ran
611
+ end
612
+ example_group.first_before_ran = false
613
+ example_group.second_before_ran = false
614
+
615
+ example_group.before(:each) do
616
+ self.class.first_before_ran = true
617
+ raise "first"
618
+ end
619
+ example_group.before(:each) do
620
+ self.class.second_before_ran = true
621
+ end
622
+ end
623
+
624
+ it "should not run second before(:each)" do
625
+ reporter.should_receive(:example_finished) do |name, error|
626
+ error.message.should eql("first")
627
+ end
628
+ example_group.run(options)
629
+ example_group.first_before_ran.should be_true
630
+ example_group.second_before_ran.should be_false
631
+ end
632
+ end
633
+
634
+ describe ExampleGroup, "#run when failure in after(:all)" do
635
+ it_should_behave_like "Spec::Example::ExampleGroup#run with failure in example"
636
+
637
+ before do
638
+ ExampleGroup.after(:all) { raise NonStandardError, "in after(:all)" }
639
+ end
640
+
641
+ it "should return false" do
642
+ example_group.run(options).should be_false
643
+ end
644
+ end
645
+ end
646
+ end
647
+
648
+ describe ExampleGroup, "subclasses" do
649
+ it "should have access to the described_type" do
650
+ example_group = Class.new(ExampleGroupDouble).describe(Array)
651
+ example_group.__send__(:described_type).should == Array
652
+ end
653
+
654
+ it "should concat descriptions when nested" do
655
+ example_group = Class.new(ExampleGroupDouble).describe(Array)
656
+ nested_group = example_group.describe("when empty") do; end
657
+ nested_group.description.to_s.should == "Array when empty"
658
+ end
659
+ end
660
+ end
661
+ end