rspec 1.1.12 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. data/.autotest +2 -1
  2. data/.document +7 -0
  3. data/History.txt +58 -0
  4. data/License.txt +1 -1
  5. data/Manifest.txt +45 -82
  6. data/README.txt +3 -6
  7. data/Rakefile +33 -13
  8. data/Ruby1.9.markdown +32 -0
  9. data/TODO.txt +10 -4
  10. data/Upgrade.markdown +63 -0
  11. data/bin/spec +1 -1
  12. data/cucumber.yml +3 -0
  13. data/examples/failing/{failing_autogenerated_docstrings_example.rb → failing_implicit_docstrings_example.rb} +0 -0
  14. data/examples/failing/pending_example.rb +9 -0
  15. data/examples/failing/spec_helper.rb +1 -1
  16. data/examples/passing/{custom_expectation_matchers.rb → custom_matchers.rb} +0 -0
  17. data/examples/passing/filtered_formatter.rb +18 -0
  18. data/examples/passing/filtered_formatter_example.rb +31 -0
  19. data/examples/passing/implicit_docstrings_example.rb +18 -0
  20. data/examples/passing/spec_helper.rb +1 -1
  21. data/examples/ruby1.9.compatibility/access_to_constants_spec.rb +17 -18
  22. data/features/before_and_after_blocks/before_and_after_blocks.feature +4 -4
  23. data/features/example_groups/example_group_with_should_methods.feature +1 -1
  24. data/features/example_groups/{autogenerated_docstrings.feature → implicit_docstrings.feature} +7 -9
  25. data/features/example_groups/nested_groups.feature +1 -1
  26. data/features/heckle/heckle.feature +56 -0
  27. data/features/interop/examples_and_tests_together.feature +1 -1
  28. data/features/interop/test_but_not_test_unit.feature +1 -1
  29. data/features/interop/test_case_with_should_methods.feature +1 -1
  30. data/features/matchers/create_matcher.feature +115 -0
  31. data/features/mock_framework_integration/use_flexmock.feature +22 -4
  32. data/features/mock_framework_integration/use_mocha.feature +27 -0
  33. data/features/mock_framework_integration/use_rr.feature +27 -0
  34. data/features/mocks/mix_stubs_and_mocks.feature +22 -0
  35. data/features/pending/pending_examples.feature +81 -0
  36. data/features/step_definitions/running_rspec.rb +5 -3
  37. data/features/support/env.rb +1 -1
  38. data/features/support/matchers/smart_match.rb +2 -2
  39. data/lib/autotest/rspec.rb +1 -1
  40. data/lib/spec.rb +1 -1
  41. data/lib/{adapters → spec/adapters}/mock_frameworks/flexmock.rb +0 -0
  42. data/lib/{adapters → spec/adapters}/mock_frameworks/mocha.rb +0 -0
  43. data/lib/{adapters → spec/adapters}/mock_frameworks/rr.rb +0 -0
  44. data/lib/{adapters → spec/adapters}/mock_frameworks/rspec.rb +0 -1
  45. data/lib/spec/autorun.rb +3 -0
  46. data/lib/spec/dsl.rb +3 -1
  47. data/lib/spec/dsl/matchers.rb +13 -0
  48. data/lib/spec/example.rb +4 -0
  49. data/lib/spec/example/before_and_after_hooks.rb +5 -20
  50. data/lib/spec/example/errors.rb +3 -3
  51. data/lib/spec/example/example_description.rb +15 -0
  52. data/lib/spec/example/example_group.rb +0 -15
  53. data/lib/spec/example/example_group_factory.rb +34 -46
  54. data/lib/spec/example/example_group_hierarchy.rb +53 -0
  55. data/lib/spec/example/example_group_methods.rb +101 -211
  56. data/lib/spec/example/example_methods.rb +61 -81
  57. data/lib/spec/example/module_reopening_fix.rb +23 -1
  58. data/lib/spec/example/pending.rb +3 -2
  59. data/lib/spec/example/predicate_matchers.rb +47 -0
  60. data/lib/spec/example/subject.rb +91 -0
  61. data/lib/spec/expectations.rb +1 -1
  62. data/lib/spec/expectations/differs/default.rb +0 -1
  63. data/lib/spec/expectations/extensions.rb +0 -1
  64. data/lib/spec/expectations/handler.rb +13 -6
  65. data/lib/spec/interop/test.rb +5 -0
  66. data/lib/spec/interop/test/unit/testcase.rb +5 -22
  67. data/lib/spec/matchers.rb +22 -8
  68. data/lib/spec/matchers/be.rb +4 -9
  69. data/lib/spec/matchers/be_close.rb +20 -5
  70. data/lib/spec/matchers/be_instance_of.rb +45 -0
  71. data/lib/spec/matchers/be_kind_of.rb +45 -0
  72. data/lib/spec/matchers/change.rb +8 -6
  73. data/lib/spec/matchers/compatibility.rb +14 -0
  74. data/lib/spec/matchers/eql.rb +24 -6
  75. data/lib/spec/matchers/equal.rb +24 -6
  76. data/lib/spec/matchers/exist.rb +21 -5
  77. data/lib/spec/matchers/extensions/instance_exec.rb +25 -0
  78. data/lib/spec/matchers/generated_descriptions.rb +2 -2
  79. data/lib/spec/matchers/has.rb +28 -11
  80. data/lib/spec/matchers/have.rb +2 -2
  81. data/lib/spec/matchers/include.rb +2 -2
  82. data/lib/spec/matchers/match.rb +25 -7
  83. data/lib/spec/matchers/match_array.rb +3 -3
  84. data/lib/spec/matchers/matcher.rb +51 -0
  85. data/lib/spec/matchers/method_missing.rb +2 -2
  86. data/lib/spec/matchers/operator_matcher.rb +12 -5
  87. data/lib/spec/matchers/raise_error.rb +3 -3
  88. data/lib/spec/matchers/respond_to.rb +3 -3
  89. data/lib/spec/matchers/satisfy.rb +7 -7
  90. data/lib/spec/matchers/throw_symbol.rb +3 -5
  91. data/lib/spec/mocks.rb +3 -3
  92. data/lib/spec/mocks/argument_expectation.rb +15 -15
  93. data/lib/spec/mocks/{argument_constraints.rb → argument_matchers.rb} +19 -23
  94. data/lib/spec/mocks/error_generator.rb +5 -8
  95. data/lib/spec/mocks/framework.rb +1 -1
  96. data/lib/spec/mocks/message_expectation.rb +5 -13
  97. data/lib/spec/mocks/mock.rb +4 -5
  98. data/lib/spec/mocks/proxy.rb +9 -5
  99. data/lib/spec/mocks/spec_methods.rb +10 -1
  100. data/lib/spec/rake/spectask.rb +0 -1
  101. data/lib/spec/runner.rb +6 -28
  102. data/lib/spec/runner/configuration.rb +3 -3
  103. data/lib/spec/runner/drb_command_line.rb +2 -1
  104. data/lib/spec/runner/example_group_runner.rb +3 -2
  105. data/lib/spec/runner/formatter/base_text_formatter.rb +34 -19
  106. data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +3 -5
  107. data/lib/spec/runner/formatter/html_formatter.rb +2 -3
  108. data/lib/spec/runner/formatter/nested_text_formatter.rb +7 -25
  109. data/lib/spec/runner/formatter/progress_bar_formatter.rb +1 -1
  110. data/lib/spec/runner/formatter/snippet_extractor.rb +1 -1
  111. data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -7
  112. data/lib/spec/runner/heckle_runner.rb +3 -6
  113. data/lib/spec/runner/heckle_runner_unsupported.rb +1 -1
  114. data/lib/spec/runner/option_parser.rb +19 -21
  115. data/lib/spec/runner/options.rb +32 -27
  116. data/lib/spec/runner/reporter.rb +8 -9
  117. data/lib/spec/test/unit.rb +10 -0
  118. data/lib/spec/version.rb +2 -2
  119. data/{features/support → resources}/helpers/cmdline.rb +2 -2
  120. data/resources/rake/verify_rcov.rake +1 -1
  121. data/resources/spec/example_group_with_should_methods.rb +1 -1
  122. data/resources/spec/simple_spec.rb +1 -1
  123. data/resources/test/spec_and_test_together.rb +2 -3
  124. data/resources/test/spec_including_test_but_not_unit.rb +1 -1
  125. data/resources/test/test_case_with_should_methods.rb +2 -3
  126. data/spec/autotest/autotest_helper.rb +0 -1
  127. data/spec/autotest/rspec_spec.rb +95 -98
  128. data/spec/spec/dsl/main_spec.rb +3 -3
  129. data/spec/spec/dsl/matchers_spec.rb +25 -0
  130. data/spec/spec/example/example_group_class_definition_spec.rb +14 -15
  131. data/spec/spec/example/example_group_factory_spec.rb +31 -44
  132. data/spec/spec/example/example_group_methods_spec.rb +86 -52
  133. data/spec/spec/example/example_group_spec.rb +32 -79
  134. data/spec/spec/example/example_matcher_spec.rb +10 -10
  135. data/spec/spec/example/example_methods_spec.rb +108 -242
  136. data/spec/spec/example/nested_example_group_spec.rb +2 -2
  137. data/spec/spec/example/pending_module_spec.rb +66 -41
  138. data/spec/spec/example/shared_example_group_spec.rb +4 -4
  139. data/spec/spec/{matchers → expectations}/handler_spec.rb +52 -4
  140. data/spec/spec/interop/test/unit/resources/spec_that_fails.rb +2 -2
  141. data/spec/spec/interop/test/unit/resources/spec_that_passes.rb +2 -2
  142. data/spec/spec/interop/test/unit/resources/spec_with_errors.rb +2 -2
  143. data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +2 -2
  144. data/spec/spec/interop/test/unit/resources/test_case_that_fails.rb +2 -2
  145. data/spec/spec/interop/test/unit/resources/test_case_that_passes.rb +2 -2
  146. data/spec/spec/interop/test/unit/resources/test_case_with_errors.rb +2 -2
  147. data/spec/spec/interop/test/unit/resources/testsuite_adapter_spec_with_test_unit.rb +2 -2
  148. data/spec/spec/interop/test/unit/testcase_spec.rb +0 -4
  149. data/spec/spec/matchers/be_close_spec.rb +1 -1
  150. data/spec/spec/matchers/be_instance_of_spec.rb +29 -0
  151. data/spec/spec/matchers/be_kind_of_spec.rb +29 -0
  152. data/spec/spec/matchers/change_spec.rb +20 -0
  153. data/spec/spec/matchers/compatibility_spec.rb +34 -0
  154. data/spec/spec/matchers/description_generation_spec.rb +0 -12
  155. data/spec/spec/matchers/eql_spec.rb +2 -2
  156. data/spec/spec/matchers/equal_spec.rb +2 -2
  157. data/spec/spec/matchers/exist_spec.rb +8 -4
  158. data/spec/spec/matchers/have_spec.rb +4 -4
  159. data/spec/spec/matchers/match_spec.rb +2 -2
  160. data/spec/spec/matchers/matcher_methods_spec.rb +1 -1
  161. data/spec/spec/matchers/matcher_spec.rb +97 -0
  162. data/spec/spec/matchers/throw_symbol_spec.rb +8 -8
  163. data/spec/spec/mocks/{bug_report_496.rb → bug_report_496_spec.rb} +0 -0
  164. data/spec/spec/mocks/{failing_mock_argument_constraints_spec.rb → failing_argument_matchers_spec.rb} +2 -2
  165. data/spec/spec/mocks/hash_including_matcher_spec.rb +4 -4
  166. data/spec/spec/mocks/hash_not_including_matcher_spec.rb +3 -3
  167. data/spec/spec/mocks/mock_spec.rb +27 -2
  168. data/spec/spec/mocks/nil_expectation_warning_spec.rb +1 -1
  169. data/spec/spec/mocks/partial_mock_spec.rb +18 -3
  170. data/spec/spec/mocks/{passing_mock_argument_constraints_spec.rb → passing_argument_matchers_spec.rb} +6 -6
  171. data/spec/spec/mocks/stubbed_message_expectations_spec.rb +13 -1
  172. data/spec/spec/package/bin_spec_spec.rb +2 -2
  173. data/spec/spec/runner/configuration_spec.rb +12 -12
  174. data/spec/spec/runner/drb_command_line_spec.rb +71 -73
  175. data/spec/spec/runner/formatter/base_text_formatter_spec.rb +82 -1
  176. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +8 -8
  177. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +4 -4
  178. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +8 -8
  179. data/spec/spec/runner/formatter/html_formatted-1.8.7.html +38 -26
  180. data/spec/spec/runner/formatter/html_formatted-1.9.1.html +61 -53
  181. data/spec/spec/runner/formatter/html_formatter_spec.rb +100 -48
  182. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +20 -34
  183. data/spec/spec/runner/formatter/profile_formatter_spec.rb +2 -1
  184. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +9 -6
  185. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +6 -6
  186. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +20 -20
  187. data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +38 -26
  188. data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +55 -47
  189. data/spec/spec/runner/formatter/{spec_mate_formatter_spec.rb → text_mate_formatter_spec.rb} +11 -9
  190. data/spec/spec/runner/heckle_runner_spec.rb +1 -1
  191. data/spec/spec/runner/heckler_spec.rb +1 -1
  192. data/spec/spec/runner/option_parser_spec.rb +28 -11
  193. data/spec/spec/runner/options_spec.rb +34 -0
  194. data/spec/spec/runner/reporter_spec.rb +66 -62
  195. data/spec/spec/runner/resources/utf8_encoded.rb +1 -0
  196. data/spec/spec/runner/spec_drb.opts +1 -0
  197. data/spec/spec/runner_spec.rb +7 -5
  198. data/spec/spec_helper.rb +24 -2
  199. metadata +49 -90
  200. data/examples/passing/autogenerated_docstrings_example.rb +0 -25
  201. data/examples/passing/before_and_after_example.rb +0 -40
  202. data/examples/passing/behave_as_example.rb +0 -45
  203. data/examples/passing/legacy_spec.rb +0 -11
  204. data/examples/passing/priority.txt +0 -1
  205. data/features/support/helpers/story_helper.rb +0 -16
  206. data/lib/spec/expectations/extensions/string_and_symbol.rb +0 -17
  207. data/lib/spec/runner/formatter/story/html_formatter.rb +0 -174
  208. data/lib/spec/runner/formatter/story/plain_text_formatter.rb +0 -194
  209. data/lib/spec/runner/formatter/story/progress_bar_formatter.rb +0 -42
  210. data/lib/spec/story.rb +0 -10
  211. data/lib/spec/story/extensions.rb +0 -3
  212. data/lib/spec/story/extensions/main.rb +0 -86
  213. data/lib/spec/story/extensions/regexp.rb +0 -9
  214. data/lib/spec/story/extensions/string.rb +0 -9
  215. data/lib/spec/story/given_scenario.rb +0 -14
  216. data/lib/spec/story/runner.rb +0 -57
  217. data/lib/spec/story/runner/plain_text_story_runner.rb +0 -48
  218. data/lib/spec/story/runner/scenario_collector.rb +0 -18
  219. data/lib/spec/story/runner/scenario_runner.rb +0 -54
  220. data/lib/spec/story/runner/story_mediator.rb +0 -137
  221. data/lib/spec/story/runner/story_parser.rb +0 -247
  222. data/lib/spec/story/runner/story_runner.rb +0 -74
  223. data/lib/spec/story/scenario.rb +0 -14
  224. data/lib/spec/story/step.rb +0 -70
  225. data/lib/spec/story/step_group.rb +0 -89
  226. data/lib/spec/story/step_mother.rb +0 -38
  227. data/lib/spec/story/story.rb +0 -39
  228. data/lib/spec/story/world.rb +0 -124
  229. data/resources/spec/spec_with_flexmock.rb +0 -19
  230. data/rspec.gemspec +0 -32
  231. data/spec/spec/matchers/mock_constraint_matchers_spec.rb +0 -24
  232. data/spec/spec/runner/formatter/story/html_formatter_spec.rb +0 -135
  233. data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +0 -600
  234. data/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb +0 -82
  235. data/spec/spec/spec_spec.rb +0 -21
  236. data/spec/spec/story/builders.rb +0 -46
  237. data/spec/spec/story/extensions/main_spec.rb +0 -161
  238. data/spec/spec/story/extensions_spec.rb +0 -14
  239. data/spec/spec/story/given_scenario_spec.rb +0 -27
  240. data/spec/spec/story/runner/plain_text_story_runner_spec.rb +0 -90
  241. data/spec/spec/story/runner/scenario_collector_spec.rb +0 -27
  242. data/spec/spec/story/runner/scenario_runner_spec.rb +0 -214
  243. data/spec/spec/story/runner/story_mediator_spec.rb +0 -143
  244. data/spec/spec/story/runner/story_parser_spec.rb +0 -401
  245. data/spec/spec/story/runner/story_runner_spec.rb +0 -294
  246. data/spec/spec/story/runner_spec.rb +0 -93
  247. data/spec/spec/story/scenario_spec.rb +0 -18
  248. data/spec/spec/story/step_group_spec.rb +0 -157
  249. data/spec/spec/story/step_mother_spec.rb +0 -84
  250. data/spec/spec/story/step_spec.rb +0 -272
  251. data/spec/spec/story/story_helper.rb +0 -2
  252. data/spec/spec/story/story_spec.rb +0 -84
  253. data/spec/spec/story/world_spec.rb +0 -423
  254. data/story_server/prototype/javascripts/builder.js +0 -136
  255. data/story_server/prototype/javascripts/controls.js +0 -972
  256. data/story_server/prototype/javascripts/dragdrop.js +0 -976
  257. data/story_server/prototype/javascripts/effects.js +0 -1117
  258. data/story_server/prototype/javascripts/prototype.js +0 -4140
  259. data/story_server/prototype/javascripts/rspec.js +0 -149
  260. data/story_server/prototype/javascripts/scriptaculous.js +0 -58
  261. data/story_server/prototype/javascripts/slider.js +0 -276
  262. data/story_server/prototype/javascripts/sound.js +0 -55
  263. data/story_server/prototype/javascripts/unittest.js +0 -568
  264. data/story_server/prototype/lib/server.rb +0 -24
  265. data/story_server/prototype/stories.html +0 -176
  266. data/story_server/prototype/stylesheets/rspec.css +0 -136
  267. data/story_server/prototype/stylesheets/test.css +0 -90
@@ -6,7 +6,7 @@ module Spec
6
6
  describe "#get" do
7
7
  attr_reader :example_group
8
8
  before(:each) do
9
- @example_group_class = Class.new(ExampleGroup)
9
+ @example_group_class = Class.new(ExampleGroupDouble)
10
10
  ExampleGroupFactory.register(:registered_type, @example_group_class)
11
11
  end
12
12
 
@@ -15,32 +15,28 @@ module Spec
15
15
  end
16
16
 
17
17
  it "should return the default ExampleGroup type for nil" do
18
- ExampleGroupFactory.get(nil).should == ExampleGroup
18
+ ExampleGroupFactory[nil].should == ExampleGroup
19
19
  end
20
20
 
21
21
  it "should return the default ExampleGroup for an unregistered non-nil value" do
22
- ExampleGroupFactory.get(:does_not_exist).should == ExampleGroup
22
+ ExampleGroupFactory[:does_not_exist].should == ExampleGroup
23
23
  end
24
24
 
25
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
26
+ ExampleGroupFactory[:registered_type].should == @example_group_class
31
27
  end
32
28
 
33
29
  it "should get the custom type after setting the default" do
34
- @alternate_example_group_class = Class.new(ExampleGroup)
30
+ @alternate_example_group_class = Class.new(ExampleGroupDouble)
35
31
  ExampleGroupFactory.default(@alternate_example_group_class)
36
- ExampleGroupFactory.get(:registered_type).should == @example_group_class
32
+ ExampleGroupFactory[:registered_type].should == @example_group_class
37
33
  end
38
34
  end
39
35
 
40
36
  describe "#create_example_group" do
41
37
  attr_reader :parent_example_group
42
38
  before do
43
- @parent_example_group = Class.new(ExampleGroup) do
39
+ @parent_example_group = Class.new(ExampleGroupDouble) do
44
40
  def initialize(*args, &block)
45
41
  ;
46
42
  end
@@ -62,7 +58,7 @@ module Spec
62
58
  Spec::Example::ExampleGroupFactory.create_example_group do; end
63
59
  }.should raise_error(ArgumentError)
64
60
  end
65
-
61
+
66
62
  it "should raise when no block is given" do
67
63
  lambda { Spec::Example::ExampleGroupFactory.create_example_group "foo" }.should raise_error(ArgumentError)
68
64
  end
@@ -112,7 +108,26 @@ module Spec
112
108
  ) {}
113
109
  custom_example_group.superclass.should == parent_example_group
114
110
  end
115
-
111
+
112
+ it "should create a type indicated by spec_path for a path-like key" do
113
+ Spec::Example::ExampleGroupFactory.register('path/to/custom/', parent_example_group)
114
+ custom_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
115
+ "example_group", :spec_path => "./spec/path/to/custom/some_spec.rb"
116
+ ) {}
117
+ custom_example_group.superclass.should == parent_example_group
118
+ end
119
+
120
+ it "should use the longest key that matches when creating a type indicated by spec_path" do
121
+ longer = Class.new parent_example_group
122
+ Spec::Example::ExampleGroupFactory.register(:longer, longer)
123
+ long = Class.new parent_example_group
124
+ Spec::Example::ExampleGroupFactory.register(:long, long)
125
+ custom_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
126
+ "example_group", :spec_path => "./spec/longer/some_spec.rb"
127
+ ) {}
128
+ custom_example_group.superclass.should == longer
129
+ end
130
+
116
131
  it "sets the spec_path from the caller" do
117
132
  options = {}
118
133
  shared_example_group = Spec::Example::ExampleGroupFactory.create_example_group("foo", options) {}
@@ -152,19 +167,19 @@ module Spec
152
167
  end
153
168
  Spec::Runner.options.example_groups.should_not include(example_group)
154
169
  end
155
-
170
+
156
171
  after(:each) do
157
172
  Spec::Example::ExampleGroupFactory.reset
158
173
  end
159
174
  end
160
-
175
+
161
176
  describe "#create_shared_example_group" do
162
177
  it "registers a new shared example group" do
163
178
  shared_example_group = Spec::Example::ExampleGroupFactory.create_shared_example_group("something shared") {}
164
179
  shared_example_group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
165
180
  SharedExampleGroup.should include(shared_example_group)
166
181
  end
167
-
182
+
168
183
  it "sets the spec_path from the caller" do
169
184
  options = {}
170
185
  shared_example_group = Spec::Example::ExampleGroupFactory.create_shared_example_group("foo", options) {}
@@ -172,34 +187,6 @@ module Spec
172
187
  end
173
188
  end
174
189
 
175
- describe "#registered_or_ancestor_of_registered?" do
176
- before(:each) do
177
- @unregistered_parent = Class.new(ExampleGroup)
178
- @registered_child = Class.new(@unregistered_parent)
179
- @unregistered_grandchild = Class.new(@registered_child)
180
- Spec::Example::ExampleGroupFactory.register :registered_child, @registered_child
181
- end
182
-
183
- it "should return true for empty list" do
184
- Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([]).should be_true
185
- end
186
-
187
- it "should return true for a registered example group class" do
188
- Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([@registered_child]).should be_true
189
- end
190
-
191
- it "should return true for an ancestor of a registered example_group_classes" do
192
- Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([@unregistered_parent]).should be_true
193
- end
194
-
195
- it "should return false for a subclass of a registered example_group_class" do
196
- Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([@unregistered_grandchild]).should be_false
197
- end
198
-
199
- after(:each) do
200
- Spec::Example::ExampleGroupFactory.reset
201
- end
202
- end
203
190
  end
204
191
  end
205
192
  end
@@ -12,21 +12,21 @@ module Spec
12
12
  options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
13
13
  @reporter = FakeReporter.new(@options)
14
14
  options.reporter = reporter
15
- @example_group = Class.new(ExampleGroup) do
15
+ @example_group = Class.new(ExampleGroupDouble) do
16
16
  describe("ExampleGroup")
17
17
  it "does nothing"
18
18
  end
19
19
  end
20
20
 
21
21
  after(:each) do
22
- ExampleGroup.reset
22
+ ExampleGroupDouble.reset
23
23
  end
24
24
 
25
25
  ["describe","context"].each do |method|
26
26
  describe "##{method}" do
27
27
  describe "when creating an ExampleGroup" do
28
28
  before(:each) do
29
- @parent_example_group = Class.new(ExampleGroup) do
29
+ @parent_example_group = Class.new(ExampleGroupDouble) do
30
30
  example "first example" do; end
31
31
  end
32
32
  @child_example_group = @parent_example_group.__send__ method, "Child" do
@@ -66,17 +66,36 @@ module Spec
66
66
  end
67
67
  end
68
68
 
69
- [:specify, :it].each do |method|
69
+ [:example, :specify, :it].each do |method|
70
70
  describe "##{method.to_s}" do
71
- it "should should create an example" do
71
+ it "should add an example" do
72
72
  lambda {
73
73
  @example_group.__send__(method, "")
74
74
  }.should change { @example_group.examples.length }.by(1)
75
75
  end
76
+
77
+ describe "creates an ExampleDescription" do
78
+ before(:all) do
79
+ @example_group = Class.new(ExampleGroupDouble).describe("bar")
80
+ @example_description = @example_group.__send__(method, "foo", {:this => :that}, "the backtrace") {}
81
+ end
82
+
83
+ specify "with a description" do
84
+ @example_description.description.should == "foo"
85
+ end
86
+
87
+ specify "with options" do
88
+ @example_description.options.should == {:this => :that}
89
+ end
90
+
91
+ specify "with a backtrace" do
92
+ @example_description.backtrace.should == "the backtrace"
93
+ end
94
+ end
76
95
  end
77
96
  end
78
97
 
79
- [:xit, :xspecify].each do |method|
98
+ [:xexample, :xit, :xspecify].each do |method|
80
99
  describe "##{method.to_s}" do
81
100
  before(:each) do
82
101
  Kernel.stub!(:warn)
@@ -95,10 +114,9 @@ module Spec
95
114
  end
96
115
  end
97
116
 
98
-
99
117
  describe "#examples" do
100
118
  it "should have Examples" do
101
- example_group = Class.new(ExampleGroup) do
119
+ example_group = Class.new(ExampleGroupDouble) do
102
120
  it "should exist" do; end
103
121
  end
104
122
  example_group.examples.length.should == 1
@@ -106,7 +124,7 @@ module Spec
106
124
  end
107
125
 
108
126
  it "should not include methods that begin with test (only when TU interop is loaded)" do
109
- example_group = Class.new(ExampleGroup) do
127
+ example_group = Class.new(ExampleGroupDouble) do
110
128
  def test_any_args(*args)
111
129
  true.should be_true
112
130
  end
@@ -123,12 +141,13 @@ module Spec
123
141
  # forces the run
124
142
  end
125
143
  end
144
+
126
145
  example_group.examples.length.should == 1
127
146
  example_group.run(options).should be_true
128
147
  end
129
148
 
130
149
  it "should include methods that begin with should and has an arity of 0 in suite" do
131
- example_group = Class.new(ExampleGroup) do
150
+ example_group = Class.new(ExampleGroupDouble) do
132
151
  def shouldCamelCase
133
152
  true.should be_true
134
153
  end
@@ -149,7 +168,7 @@ module Spec
149
168
  end
150
169
  end
151
170
  example_group.should have(4).examples
152
- descriptions = example_group.examples.collect {|example| example.description.to_s}
171
+ descriptions = example_group.examples.collect {|e| e.description}
153
172
  descriptions.should include(
154
173
  "shouldCamelCase",
155
174
  "should_any_args",
@@ -162,7 +181,7 @@ module Spec
162
181
  end
163
182
 
164
183
  it "should not include methods that begin with test_ and has an arity > 0 in suite" do
165
- example_group = Class.new(ExampleGroup) do
184
+ example_group = Class.new(ExampleGroupDouble) do
166
185
  def test_invalid(foo)
167
186
  1.should == 1
168
187
  end
@@ -174,7 +193,7 @@ module Spec
174
193
  end
175
194
 
176
195
  it "should not include methods that begin with should_ and has an arity > 0 in suite" do
177
- example_group = Class.new(ExampleGroup) do
196
+ example_group = Class.new(ExampleGroupDouble) do
178
197
  def should_invalid(foo)
179
198
  1.should == 2
180
199
  end
@@ -193,7 +212,7 @@ module Spec
193
212
  end
194
213
 
195
214
  it "should run should_methods" do
196
- example_group = Class.new(ExampleGroup) do
215
+ example_group = Class.new(ExampleGroupDouble) do
197
216
  def should_valid
198
217
  1.should == 2
199
218
  end
@@ -322,8 +341,8 @@ module Spec
322
341
  example_group.spec_path.should == File.expand_path("blah")
323
342
  end
324
343
 
325
- it ".description_options should return all the options passed in" do
326
- example_group.description_options.should == {:a => "b", :spec_path => "blah"}
344
+ it ".options should return all the options passed in" do
345
+ example_group.options.should == {:a => "b", :spec_path => "blah"}
327
346
  end
328
347
 
329
348
  end
@@ -334,14 +353,14 @@ module Spec
334
353
  example_group.description.should eql(example_group.description)
335
354
  end
336
355
 
337
- it "should not add a space when description_text begins with #" do
356
+ it "should not add a space when description begins with #" do
338
357
  child_example_group = Class.new(example_group) do
339
358
  describe("#foobar", "Does something")
340
359
  end
341
360
  child_example_group.description.should == "ExampleGroup#foobar Does something"
342
361
  end
343
362
 
344
- it "should not add a space when description_text begins with ." do
363
+ it "should not add a space when description begins with ." do
345
364
  child_example_group = Class.new(example_group) do
346
365
  describe(".foobar", "Does something")
347
366
  end
@@ -357,6 +376,11 @@ module Spec
357
376
  example_group.set_description("")
358
377
  example_group.description.should =~ /Class:/
359
378
  end
379
+
380
+ it "is cached" do
381
+ example_group.set_description("describe me")
382
+ example_group.description.should be(example_group.description)
383
+ end
360
384
  end
361
385
 
362
386
  describe "#description_parts" do
@@ -365,7 +389,7 @@ module Spec
365
389
  end
366
390
 
367
391
  it "should return an Array of the description args from each class in the hierarchy" do
368
- parent_example_group = Class.new(ExampleGroup) do
392
+ parent_example_group = Class.new(ExampleGroupDouble) do
369
393
  describe("Parent")
370
394
  end
371
395
 
@@ -385,6 +409,10 @@ module Spec
385
409
  Spec::Example::ExampleGroup
386
410
  ]
387
411
  end
412
+
413
+ it "caches the description parts" do
414
+ example_group.description_parts.should equal(example_group.description_parts)
415
+ end
388
416
  end
389
417
 
390
418
  describe "#described_type" do
@@ -396,7 +424,7 @@ module Spec
396
424
  end
397
425
 
398
426
  it "should return #described_type of superclass when no passed in type" do
399
- parent_example_group = Class.new(ExampleGroup) do
427
+ parent_example_group = Class.new(ExampleGroupDouble) do
400
428
  describe Object, "#foobar"
401
429
  end
402
430
  child_example_group = Class.new(parent_example_group) do
@@ -404,25 +432,15 @@ module Spec
404
432
  end
405
433
  child_example_group.described_type.should == Object
406
434
  end
407
- end
408
-
409
- describe "#remove_after" do
410
- it "should unregister a given after(:each) block" do
411
- after_all_ran = false
412
- proc = Proc.new { after_all_ran = true }
413
-
414
- example_group = Class.new(ExampleGroup) do
415
- specify("example") {}
416
- after(:each, &proc)
435
+
436
+ it "is cached per example group" do
437
+ klass = Class.new
438
+ group = Class.new(ExampleGroupDouble) do
439
+ describe(klass)
417
440
  end
418
-
419
- example_group.run(options)
420
- after_all_ran.should be_true
421
-
422
- after_all_ran = false
423
- example_group.remove_after(:each, &proc)
424
- example_group.run(options)
425
- after_all_ran.should be_false
441
+ group.should_receive(:description_parts).once.and_return([klass])
442
+ group.described_type
443
+ group.described_type
426
444
  end
427
445
  end
428
446
 
@@ -463,7 +481,7 @@ module Spec
463
481
 
464
482
  describe "#class_eval" do
465
483
  it "should allow constants to be defined" do
466
- example_group = Class.new(ExampleGroup) do
484
+ example_group = Class.new(ExampleGroupDouble) do
467
485
  FOO = 1
468
486
  it "should reference FOO" do
469
487
  FOO.should == 1
@@ -485,7 +503,7 @@ module Spec
485
503
  end
486
504
  end
487
505
 
488
- describe '#unregister' do
506
+ describe '#remove_example_group' do
489
507
  before(:each) do
490
508
  Spec::Runner.options.add_example_group example_group
491
509
  end
@@ -498,7 +516,7 @@ module Spec
498
516
  describe "#run" do
499
517
  describe "given an example group with at least one example" do
500
518
  it "should call add_example_group" do
501
- example_group = Class.new(ExampleGroup) do
519
+ example_group = Class.new(ExampleGroupDouble) do
502
520
  example("anything") {}
503
521
  end
504
522
  reporter.should_receive(:add_example_group)
@@ -508,7 +526,7 @@ module Spec
508
526
 
509
527
  describe "given an example group with no examples" do
510
528
  it "should NOT call add_example_group" do
511
- example_group = Class.new(ExampleGroup) do end
529
+ example_group = Class.new(ExampleGroupDouble) do end
512
530
  reporter.should_not_receive(:add_example_group)
513
531
  example_group.run(options)
514
532
  end
@@ -517,7 +535,7 @@ module Spec
517
535
 
518
536
  describe "#matcher_class=" do
519
537
  it "should call new and matches? on the class used for matching examples" do
520
- example_group = Class.new(ExampleGroup) do
538
+ example_group = Class.new(ExampleGroupDouble) do
521
539
  it "should do something" do end
522
540
  def self.specified_examples
523
541
  ["something"]
@@ -552,7 +570,7 @@ module Spec
552
570
 
553
571
  describe "#backtrace" do
554
572
  it "returns the backtrace from where the example group was defined" do
555
- example_group = Class.new(ExampleGroup).describe("foo") do
573
+ example_group = Class.new(ExampleGroupDouble).describe("foo") do
556
574
  example "bar" do; end
557
575
  end
558
576
  example_group.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-3}")
@@ -564,13 +582,13 @@ module Spec
564
582
  Kernel.stub!(:warn)
565
583
  end
566
584
  it "sends a deprecation warning" do
567
- example_group = Class.new(ExampleGroup) {}
585
+ example_group = Class.new(ExampleGroupDouble) {}
568
586
  Kernel.should_receive(:warn).with(/#example_group_backtrace.*deprecated.*#backtrace instead/m)
569
587
  example_group.example_group_backtrace
570
588
  end
571
589
 
572
590
  it "returns the backtrace from where the example group was defined" do
573
- example_group = Class.new(ExampleGroup).describe("foo") do
591
+ example_group = Class.new(ExampleGroupDouble).describe("foo") do
574
592
  example "bar" do; end
575
593
  end
576
594
  example_group.example_group_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-3}")
@@ -579,21 +597,21 @@ module Spec
579
597
 
580
598
  describe "#before" do
581
599
  it "stores before(:each) blocks" do
582
- example_group = Class.new(ExampleGroup) {}
600
+ example_group = Class.new(ExampleGroupDouble) {}
583
601
  block = lambda {}
584
602
  example_group.before(:each, &block)
585
603
  example_group.before_each_parts.should include(block)
586
604
  end
587
605
 
588
606
  it "stores before(:all) blocks" do
589
- example_group = Class.new(ExampleGroup) {}
607
+ example_group = Class.new(ExampleGroupDouble) {}
590
608
  block = lambda {}
591
609
  example_group.before(:all, &block)
592
610
  example_group.before_all_parts.should include(block)
593
611
  end
594
612
 
595
613
  it "stores before(:suite) blocks" do
596
- example_group = Class.new(ExampleGroup) {}
614
+ example_group = Class.new(ExampleGroupDouble) {}
597
615
  parts = []
598
616
  ExampleGroupMethods.stub!(:before_suite_parts).and_return(parts)
599
617
  block = lambda {}
@@ -605,21 +623,21 @@ module Spec
605
623
 
606
624
  describe "#after" do
607
625
  it "stores after(:each) blocks" do
608
- example_group = Class.new(ExampleGroup) {}
626
+ example_group = Class.new(ExampleGroupDouble) {}
609
627
  block = lambda {}
610
628
  example_group.after(:each, &block)
611
629
  example_group.after_each_parts.should include(block)
612
630
  end
613
631
 
614
632
  it "stores after(:all) blocks" do
615
- example_group = Class.new(ExampleGroup) {}
633
+ example_group = Class.new(ExampleGroupDouble) {}
616
634
  block = lambda {}
617
635
  example_group.after(:all, &block)
618
636
  example_group.after_all_parts.should include(block)
619
637
  end
620
638
 
621
639
  it "stores after(:suite) blocks" do
622
- example_group = Class.new(ExampleGroup) {}
640
+ example_group = Class.new(ExampleGroupDouble) {}
623
641
  parts = []
624
642
  ExampleGroupMethods.stub!(:after_suite_parts).and_return(parts)
625
643
  block = lambda {}
@@ -628,6 +646,22 @@ module Spec
628
646
  end
629
647
  end
630
648
 
649
+ describe "#run_before_all" do
650
+ it "does not create an instance if before_all_parts are empty" do
651
+ example_group = Class.new(ExampleGroupDouble) { example("one example") {} }
652
+ example_group.should_not_receive(:new)
653
+ example_group.__send__ :run_before_all, nil
654
+ end
655
+ end
656
+
657
+ describe "#run_after_all" do
658
+ it "does not create an instance if after_all_parts are empty" do
659
+ example_group = Class.new(ExampleGroupDouble) { example("one example") {} }
660
+ example_group.should_not_receive(:new)
661
+ example_group.__send__ :run_after_all, true, {}, nil
662
+ end
663
+ end
664
+
631
665
  end
632
666
  end
633
667
  end