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
@@ -7,9 +7,7 @@ module Spec
7
7
 
8
8
  module Foo
9
9
  module Bar
10
- def self.loaded?
11
- true
12
- end
10
+ def self.loaded?; true; end
13
11
  end
14
12
  end
15
13
  include Foo
@@ -18,11 +16,23 @@ module Spec
18
16
  Bar.should be_loaded
19
17
  end
20
18
 
21
- @@foo = 1
19
+ @@class_variable = "a class variable"
22
20
 
23
- it "should allow class variables to be defined" do
24
- @@foo.should == 1
21
+ it "can access class variables in examples in Ruby 1.8" do
22
+ with_ruby 1.8 do
23
+ @@class_variable.should == "a class variable"
24
+ end
25
+ end
26
+
27
+ it "can NOT access class variables in examples in Ruby 1.9" do
28
+ with_ruby 1.9 do
29
+ lambda do
30
+ @@class_variable.should == "a class variable"
31
+ end.should raise_error(NameError)
32
+ end
25
33
  end
34
+
35
+
26
36
  end
27
37
 
28
38
  class ExampleClassVariablePollutionSpec < ExampleGroup
@@ -30,7 +40,7 @@ module Spec
30
40
 
31
41
  it "should not retain class variables from other Example classes" do
32
42
  proc do
33
- @@foo
43
+ @@class_variable
34
44
  end.should raise_error
35
45
  end
36
46
  end
@@ -74,7 +84,7 @@ module Spec
74
84
  options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
75
85
  @reporter = FakeReporter.new(options)
76
86
  options.reporter = reporter
77
- @example_group = Class.new(ExampleGroup) do
87
+ @example_group = Class.new(ExampleGroupDouble) do
78
88
  describe("example")
79
89
  it "does nothing" do
80
90
  end
@@ -89,7 +99,7 @@ module Spec
89
99
  end
90
100
 
91
101
  it "should not run when there are no examples" do
92
- example_group = Class.new(ExampleGroup) do
102
+ example_group = Class.new(ExampleGroupDouble) do
93
103
  describe("Foobar")
94
104
  end
95
105
  example_group.examples.should be_empty
@@ -164,7 +174,7 @@ module Spec
164
174
  describe "when specified_examples matches entire ExampleGroup" do
165
175
  before do
166
176
  examples_that_were_run = @examples_that_were_run
167
- @example_group = Class.new(ExampleGroup) do
177
+ @example_group = Class.new(ExampleGroupDouble) do
168
178
  describe("the ExampleGroup")
169
179
  it("should be run") do
170
180
  examples_that_were_run << 'should be run'
@@ -186,7 +196,7 @@ module Spec
186
196
  describe ExampleGroup, "#run when specified_examples matches only Example description" do
187
197
  before do
188
198
  examples_that_were_run = @examples_that_were_run
189
- @example_group = Class.new(ExampleGroup) do
199
+ @example_group = Class.new(ExampleGroupDouble) do
190
200
  describe("example")
191
201
  it("should be run") do
192
202
  examples_that_were_run << 'should be run'
@@ -204,7 +214,7 @@ module Spec
204
214
  describe ExampleGroup, "#run when specified_examples does not match an Example description" do
205
215
  before do
206
216
  examples_that_were_run = @examples_that_were_run
207
- @example_group = Class.new(ExampleGroup) do
217
+ @example_group = Class.new(ExampleGroupDouble) do
208
218
  describe("example")
209
219
  it("should be something else") do
210
220
  examples_that_were_run << 'should be something else'
@@ -222,7 +232,7 @@ module Spec
222
232
  describe ExampleGroup, "#run when specified_examples matches an Example description" do
223
233
  before do
224
234
  examples_that_were_run = @examples_that_were_run
225
- @example_group = Class.new(ExampleGroup) do
235
+ @example_group = Class.new(ExampleGroupDouble) do
226
236
  describe("example")
227
237
  it("should be run") do
228
238
  examples_that_were_run << 'should be run'
@@ -234,22 +244,18 @@ module Spec
234
244
  options.parse_example "should be run"
235
245
  end
236
246
 
237
- it "should run only the example, when there is only one" do
247
+ it "should run only the example" do
238
248
  example_group.run(options)
239
249
  examples_that_were_run.should == ["should be run"]
240
250
  end
241
-
242
- it "should run only the one example" do
243
- example_group.run(options)
244
- examples_that_were_run.should == ["should be run"] end
245
251
  end
246
252
  end
247
253
 
248
254
  describe ExampleGroup, "#run with success" do
249
255
  before do
250
- @special_example_group = Class.new(ExampleGroup)
256
+ @special_example_group = Class.new(ExampleGroupDouble)
251
257
  ExampleGroupFactory.register(:special, @special_example_group)
252
- @not_special_example_group = Class.new(ExampleGroup)
258
+ @not_special_example_group = Class.new(ExampleGroupDouble)
253
259
  ExampleGroupFactory.register(:not_special, @not_special_example_group)
254
260
  end
255
261
 
@@ -317,7 +323,7 @@ module Spec
317
323
  @special_example_group.before(:all) { fiddle << "Example.before(:all, :type => :special)" }
318
324
  @special_example_group.prepend_before(:all) { fiddle << "Example.prepend_before(:all, :type => :special)" }
319
325
 
320
- example_group = Class.new(ExampleGroup) do
326
+ example_group = Class.new(ExampleGroupDouble) do
321
327
  describe("I'm not special", :type => :not_special)
322
328
  it "does nothing"
323
329
  end
@@ -434,47 +440,6 @@ module Spec
434
440
  example_group.included_modules.should_not include(mod3)
435
441
  end
436
442
 
437
- it "should include any predicate_matchers included using configuration" do
438
- $included_predicate_matcher_found = false
439
- Spec::Runner.configuration.predicate_matchers[:do_something] = :does_something?
440
- example_group = Class.new(ExampleGroup) do
441
- describe('example')
442
- it "should respond to do_something" do
443
- $included_predicate_matcher_found = respond_to?(:do_something)
444
- end
445
- end
446
- example_group.run(options)
447
- $included_predicate_matcher_found.should be(true)
448
- end
449
-
450
- it "should use a mock framework set up in config" do
451
- mod = Module.new do
452
- def self.included(mod)
453
- $included_module = mod
454
- end
455
-
456
- def teardown_mocks_for_rspec
457
- $torn_down = true
458
- end
459
- end
460
-
461
- begin
462
- $included_module = nil
463
- $torn_down = true
464
- Spec::Runner.configuration.mock_with mod
465
-
466
- example_group = Class.new(ExampleGroup) do
467
- describe('example')
468
- it "does nothing"
469
- end
470
- example_group.run(options)
471
-
472
- $included_module.should_not be_nil
473
- $torn_down.should == true
474
- ensure
475
- Spec::Runner.configuration.mock_with :rspec
476
- end
477
- end
478
443
  end
479
444
 
480
445
  describe ExampleGroup, "#run with pending example that has a failing assertion" do
@@ -534,7 +499,7 @@ module Spec
534
499
  end
535
500
 
536
501
  it "should supply before(:all) as description" do
537
- @reporter.should_receive(:failure) do |example, error|
502
+ @reporter.should_receive(:example_failed) do |example, error|
538
503
  example.description.should eql("before(:all)")
539
504
  error.message.should eql("before(:all) failure")
540
505
  end
@@ -647,28 +612,16 @@ module Spec
647
612
  end
648
613
  end
649
614
 
650
- class ExampleSubclass < ExampleGroup
651
- end
652
-
653
615
  describe ExampleGroup, "subclasses" do
654
- after do
655
- ExampleGroupFactory.reset
656
- end
657
-
658
616
  it "should have access to the described_type" do
659
- example_group = Class.new(ExampleSubclass) do
660
- describe(Array)
661
- end
617
+ example_group = Class.new(ExampleGroupDouble).describe(Array)
662
618
  example_group.__send__(:described_type).should == Array
663
619
  end
664
620
 
665
621
  it "should concat descriptions when nested" do
666
- example_group = Class.new(ExampleSubclass) do
667
- describe(Array)
668
- $nested_group = describe("when empty") do
669
- end
670
- end
671
- $nested_group.description.to_s.should == "Array when empty"
622
+ example_group = Class.new(ExampleGroupDouble).describe(Array)
623
+ nested_group = example_group.describe("when empty") do; end
624
+ nested_group.description.to_s.should == "Array when empty"
672
625
  end
673
626
  end
674
627
  end
@@ -3,52 +3,52 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
3
3
  module Spec
4
4
  module Example
5
5
  describe ExampleMatcher, "#matches?" do
6
- def match_description(description)
6
+ def match_examples(examples)
7
7
  simple_matcher do |actual, matcher|
8
8
  matcher.failure_message = "expected matcher.matches?(#{description.inspect}) to return true, got false"
9
9
  matcher.negative_failure_message = "expected matcher.matches?(#{description.inspect}) to return false, got true"
10
- actual.matches?(description)
10
+ actual.matches?(examples)
11
11
  end
12
12
  end
13
13
 
14
14
  it "should match correct example_group and example" do
15
15
  matcher = ExampleMatcher.new("example_group", "example")
16
- matcher.should match_description("example_group example")
16
+ matcher.should match_examples(["example_group example"])
17
17
  end
18
18
 
19
19
  it "should not match wrong example" do
20
20
  matcher = ExampleMatcher.new("example_group", "other example")
21
- matcher.should_not match_description("example_group example")
21
+ matcher.should_not match_examples(["example_group example"])
22
22
  end
23
23
 
24
24
  it "should not match wrong example_group" do
25
25
  matcher = ExampleMatcher.new("other example_group", "example")
26
- matcher.should_not match_description("example_group example")
26
+ matcher.should_not match_examples(["example_group example"])
27
27
  end
28
28
 
29
29
  it "should match example only" do
30
30
  matcher = ExampleMatcher.new("example_group", "example")
31
- matcher.should match_description("example")
31
+ matcher.should match_examples(["example"])
32
32
  end
33
33
 
34
34
  it "should match example_group only" do
35
35
  matcher = ExampleMatcher.new("example_group", "example")
36
- matcher.should match_description("example_group")
36
+ matcher.should match_examples(["example_group"])
37
37
  end
38
38
 
39
39
  it "should match example_group ending with before(:all)" do
40
40
  matcher = ExampleMatcher.new("example_group", "example")
41
- matcher.should match_description("example_group before(:all)")
41
+ matcher.should match_examples(["example_group before(:all)"])
42
42
  end
43
43
 
44
44
  it "should escape regexp chars" do
45
45
  matcher = ExampleMatcher.new("(con|text)", "[example]")
46
- matcher.should_not match_description("con p")
46
+ matcher.should_not match_examples(["con p"])
47
47
  end
48
48
 
49
49
  it "should match when example_group is modularized" do
50
50
  matcher = ExampleMatcher.new("MyModule::MyClass", "example")
51
- matcher.should match_description("MyClass example")
51
+ matcher.should match_examples(["MyClass example"])
52
52
  end
53
53
  end
54
54
 
@@ -1,288 +1,154 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
+ class Thing
4
+ attr_reader :arg
5
+ def initialize(arg=nil)
6
+ @arg = arg || :default
7
+ end
8
+ def ==(other)
9
+ @arg == other.arg
10
+ end
11
+ def eql?(other)
12
+ @arg == other.arg
13
+ end
14
+ end
15
+
3
16
  module Spec
4
17
  module Example
5
- module ModuleThatIsReopened
6
- end
7
-
8
- module ExampleMethods
9
- include ModuleThatIsReopened
10
- end
18
+ describe ExampleMethods do
19
+ module ModuleThatIsReopened; end
11
20
 
12
- module ModuleThatIsReopened
13
- def module_that_is_reopened_method
21
+ module Spec::Example::ExampleMethods
22
+ include ModuleThatIsReopened
14
23
  end
15
- end
16
24
 
17
- describe ExampleMethods do
25
+ module ModuleThatIsReopened
26
+ def module_that_is_reopened_method; end
27
+ end
28
+
18
29
  describe "with an included module that is reopened" do
19
30
  it "should have repoened methods" do
20
31
  method(:module_that_is_reopened_method).should_not be_nil
21
32
  end
22
33
  end
23
34
 
24
- describe "lifecycle" do
25
- with_sandboxed_options do
26
- with_sandboxed_config do
27
- before do
28
- @options.formatters << mock("formatter", :null_object => true)
29
- @options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
30
- @reporter = FakeReporter.new(@options)
31
- @options.reporter = @reporter
32
-
33
- ExampleGroup.before_all_parts.should == []
34
- ExampleGroup.before_each_parts.should == []
35
- ExampleGroup.after_each_parts.should == []
36
- ExampleGroup.after_all_parts.should == []
37
- def ExampleGroup.count
38
- @count ||= 0
39
- @count = @count + 1
40
- @count
41
- end
42
- end
43
- end
44
-
45
- after do
46
- ExampleGroup.instance_variable_set("@before_all_parts", [])
47
- ExampleGroup.instance_variable_set("@before_each_parts", [])
48
- ExampleGroup.instance_variable_set("@after_each_parts", [])
49
- ExampleGroup.instance_variable_set("@after_all_parts", [])
50
- end
51
-
52
- describe "eval_block" do
53
- before(:each) do
54
- @example_group = Class.new(ExampleGroup)
55
- end
56
-
57
- describe "with a given description" do
58
- it "should provide the given description" do
59
- @example = @example_group.it("given description") { 2.should == 2 }
60
- @example.eval_block
61
- @example.description.should == "given description"
62
- end
63
- end
64
-
65
- describe "with no given description" do
66
- it "should provide the generated description" do
67
- @example = @example_group.it { 2.should == 2 }
68
- @example.eval_block
69
- @example.description.should == "should == 2"
70
- end
71
- end
72
-
73
- describe "with no implementation" do
74
- it "should raise an NotYetImplementedError" do
75
- lambda {
76
- @example = @example_group.it
77
- @example.eval_block
78
- }.should raise_error(Spec::Example::NotYetImplementedError, "Not Yet Implemented")
79
- end
80
-
81
- def extract_error(&blk)
82
- begin
83
- blk.call
84
- rescue Exception => e
85
- return e
86
- end
87
-
88
- nil
89
- end
90
-
91
- it "should use the proper file and line number for the NotYetImplementedError" do
92
- file = __FILE__
93
- line_number = __LINE__ + 3
94
-
95
- error = extract_error do
96
- @example = @example_group.it
97
- @example.eval_block
98
- end
99
-
100
- error.pending_caller.should =~ /#{file}:#{line_number}/
101
- end
102
- end
103
- end
104
- end
105
- end
106
-
107
35
  describe "#backtrace" do
108
- with_sandboxed_options do
109
- it "returns the backtrace from where the example was defined" do
110
- example_group = Class.new(ExampleGroup) do
111
- example "of something" do; end
112
- end
113
-
114
- example = example_group.examples.first
115
- example.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-4}")
116
- end
36
+ it "returns the backtrace from where the example was defined" do
37
+ example = ExampleGroup.dup.new "name"
38
+ example.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-1}")
117
39
  end
118
40
  end
119
41
 
120
42
  describe "#implementation_backtrace (deprecated)" do
121
- with_sandboxed_options do
122
- before(:each) do
123
- Kernel.stub!(:warn)
124
- end
125
-
126
- it "sends a deprecation warning" do
127
- example_group = Class.new(ExampleGroup) {}
128
- example = example_group.example("") {}
129
- Kernel.should_receive(:warn).with(/#implementation_backtrace.*deprecated.*#backtrace instead/m)
130
- example.implementation_backtrace
131
- end
132
-
133
- it "returns the backtrace from where the example was defined" do
134
- example_group = Class.new(ExampleGroup) do
135
- example "of something" do; end
136
- end
137
-
138
- example = example_group.examples.first
139
- example.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-4}")
140
- end
43
+ before(:each) do
44
+ Kernel.stub!(:warn)
141
45
  end
142
- end
143
46
 
144
- describe "#full_description" do
145
- it "should return the full description of the ExampleGroup and Example" do
146
- example_group = Class.new(ExampleGroup).describe("An ExampleGroup") do
147
- it "should do something" do
148
- end
149
- end
150
- example = example_group.examples.first
151
- example.full_description.should == "An ExampleGroup should do something"
47
+ it "sends a deprecation warning" do
48
+ Kernel.should_receive(:warn).with(/#implementation_backtrace.*deprecated.*#backtrace instead/m)
49
+ example = ExampleGroup.dup.new "name"
50
+ example.implementation_backtrace
152
51
  end
153
- end
154
-
155
- describe "#subject" do
156
- with_sandboxed_options do
157
- it "should return an instance variable named after the described type" do
158
- example_group = Class.new(ExampleGroup).describe(Array) do
159
- example {}
160
- end
161
- example = example_group.examples.first
162
- example.subject.should == []
163
- end
164
-
165
- it "should not barf on a module (as opposed to a class)" do
166
- example_group = Class.new(ExampleGroup).describe(ObjectSpace) do
167
- example {}
168
- end
169
- example_group.examples.first.subject.should be_nil
170
- end
171
-
172
- it "should not barf on a string" do
173
- example_group = Class.new(ExampleGroup).describe('foo') do
174
- example {}
175
- end
176
- example_group.examples.first.subject.should be_nil
177
- end
178
-
179
- it "should interact with the same scope as the before block" do
180
- example_group = Class.new(ExampleGroup) do
181
- subject { @foo = 'foo'}
182
- example { should == @foo}
183
- it { should == 'foo'}
184
- end
185
- example_group.run(options).should be_true
186
- end
52
+
53
+ it "returns the backtrace from where the example was defined" do
54
+ example = ExampleGroup.dup.new "name"
55
+ example.implementation_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-1}")
187
56
  end
188
57
  end
189
58
 
190
- describe "#should" do
191
- with_sandboxed_options do
192
- class Thing
193
- def ==(other)
194
- true
195
- end
196
- end
197
-
198
- describe "in an ExampleGroup with the ivar defined in before" do
199
- attr_reader :example, :success
59
+ describe "#subject" do
60
+ before(:each) do
61
+ @example_group = ExampleGroupDouble
62
+ end
200
63
 
201
- before(:each) do
202
- example_group = describe(Thing, "1") do
203
- before(:each) { @spec_example_thing = 'expected' }
204
- it { should eql('expected') }
205
- end
206
- @example = example_group.examples.first
207
- @success = example_group.run(options)
208
- end
64
+ it "should return an instance of the described class" do
65
+ group = Class.new(ExampleGroupDouble).describe(Array)
66
+ example = group.new("")
67
+ example.subject.should == []
68
+ end
69
+
70
+ it "should return a Module" do
71
+ group = Class.new(ExampleGroupDouble).describe(Enumerable)
72
+ example = group.new("")
73
+ example.subject.should == Enumerable
74
+ end
209
75
 
210
- it "should create an example using the description from the matcher" do
211
- example.description.should == 'should eql "expected"'
212
- end
76
+ it "should return a string" do
77
+ group = Class.new(ExampleGroupDouble).describe('foo')
78
+ example = group.new("")
79
+ example.subject.should == 'foo'
80
+ end
213
81
 
214
- it "should test the matcher returned from the block" do
215
- success.should be_true
216
- end
217
- end
82
+ it "should return a number" do
83
+ group = Class.new(ExampleGroupDouble).describe(15)
84
+ example = group.new("")
85
+ example.subject.should == 15
86
+ end
87
+ end
218
88
 
219
- describe "in an ExampleGroup with the subject defined using #subject" do
220
- it "should create an example using the description from the matcher" do
221
- example_group = describe(Thing, "2") do
222
- subject {'this is the subject'}
223
- it { should eql('this is the subject') }
224
- end
225
- example = example_group.examples.first
226
- example_group.run(options)
227
- example.description.should =~ /should eql "this is the subject"/
228
- end
229
- end
230
-
231
- describe "in an ExampleGroup using an implicit ivar" do
232
- it "should create an example using the description from the matcher" do
233
- example_group = describe(Thing, "3") do
234
- it { should == Thing.new }
235
- end
236
- example = example_group.examples.first
237
- success = example_group.run(options)
238
- example.description.should =~ /should == #<Spec::Example::Thing/
239
- success.should be_true
240
- end
89
+ describe "#should" do
90
+ before(:each) do
91
+ @example_group = Class.new(ExampleGroupDouble)
92
+ @options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
93
+ end
94
+
95
+ context "in an ExampleGroup with an implicit subject" do
96
+ it "delegates matcher to the implied subject" do
97
+ @example_group.describe(::Thing)
98
+ @example_group.example { should == ::Thing.new(:default) }
99
+ @example_group.example { should eql(::Thing.new(:default)) }
100
+ @example_group.run(@options).should be_true
241
101
  end
242
-
243
- after(:each) do
244
- ExampleGroup.reset
102
+ end
103
+
104
+ context "in an ExampleGroup using an explicit subject" do
105
+ it "delegates matcher to the declared subject" do
106
+ @example_group.describe(::Thing)
107
+ @example_group.subject { ::Thing.new(:other) }
108
+ @example_group.example { should == ::Thing.new(:other) }
109
+ @example_group.example { should eql(::Thing.new(:other)) }
110
+ @example_group.run(@options).should be_true
245
111
  end
246
-
247
112
  end
248
113
  end
249
114
 
250
115
  describe "#should_not" do
251
- with_sandboxed_options do
252
-
253
- attr_reader :example_group, :example, :success
254
-
255
- before do
256
- @example_group = Class.new(ExampleGroup) do
257
- def subject; @actual; end
258
- before(:each) { @actual = 'expected' }
259
- it { should_not eql('unexpected') }
260
- end
261
- @example = @example_group.examples.first
262
-
263
- @success = example_group.run(options)
264
- end
265
-
266
- it "should create an example using the description from the matcher" do
267
- example.description.should == 'should not eql "unexpected"'
268
- end
116
+ before(:each) do
117
+ @example_group = Class.new(ExampleGroupDouble)
118
+ end
269
119
 
270
- it "should test the matcher returned from the block" do
271
- success.should be_true
120
+ context "in an ExampleGroup with an implicit subject" do
121
+ it "delegates matcher to the implied subject" do
122
+ @example_group.describe(::Thing)
123
+ @example_group.example { should_not == ::Thing.new(:other) }
124
+ @example_group.example { should_not eql(::Thing.new(:other)) }
125
+ @example_group.run(::Spec::Runner::Options.new(StringIO.new, StringIO.new)).should be_true
272
126
  end
273
-
274
- after do
275
- ExampleGroup.reset
127
+ end
128
+
129
+ context "in an ExampleGroup using an explicit subject" do
130
+ it "delegates matcher to the declared subject" do
131
+ @example_group.describe(::Thing)
132
+ @example_group.subject { ::Thing.new(:other) }
133
+ @example_group.example { should_not == ::Thing.new(:default) }
134
+ @example_group.example { should_not eql(::Thing.new(:default)) }
135
+ @example_group.run(::Spec::Runner::Options.new(StringIO.new, StringIO.new)).should be_true
276
136
  end
277
-
278
137
  end
279
138
  end
280
139
  end
281
140
 
282
141
  describe "#options" do
283
142
  it "should expose the options hash" do
284
- example_group = Class.new(ExampleGroup)
285
- example = example_group.example "name", :this => 'that' do; end
143
+ example = ExampleGroupDouble.new "name", :this => 'that' do; end
144
+ example.options[:this].should == 'that'
145
+ end
146
+ end
147
+
148
+ describe "#set_instance_variables_from_hash" do
149
+ it "preserves the options" do
150
+ example = ExampleGroupDouble.new "name", :this => 'that' do; end
151
+ example.set_instance_variables_from_hash({:@_options => {}})
286
152
  example.options[:this].should == 'that'
287
153
  end
288
154
  end