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
@@ -1,21 +1,21 @@
1
1
  module Spec
2
2
  module Mocks
3
3
 
4
- # ArgumentConstraints are messages that you can include in message
4
+ # ArgumentMatchers are messages that you can include in message
5
5
  # expectations to match arguments against a broader check than simple
6
6
  # equality.
7
7
  #
8
- # With the exception of any_args() and no_args(), the constraints
8
+ # With the exception of any_args() and no_args(), the matchers
9
9
  # are all positional - they match against the arg in the given position.
10
- module ArgumentConstraints
10
+ module ArgumentMatchers
11
11
 
12
- class AnyArgsConstraint
12
+ class AnyArgsMatcher
13
13
  def description
14
14
  "any args"
15
15
  end
16
16
  end
17
17
 
18
- class AnyArgConstraint
18
+ class AnyArgMatcher
19
19
  def initialize(ignore)
20
20
  end
21
21
 
@@ -24,17 +24,13 @@ module Spec
24
24
  end
25
25
  end
26
26
 
27
- class NoArgsConstraint
27
+ class NoArgsMatcher
28
28
  def description
29
29
  "no args"
30
30
  end
31
-
32
- def ==(args)
33
- args == []
34
- end
35
31
  end
36
32
 
37
- class RegexpConstraint
33
+ class RegexpMatcher
38
34
  def initialize(regexp)
39
35
  @regexp = regexp
40
36
  end
@@ -45,7 +41,7 @@ module Spec
45
41
  end
46
42
  end
47
43
 
48
- class BooleanConstraint
44
+ class BooleanMatcher
49
45
  def initialize(ignore)
50
46
  end
51
47
 
@@ -54,7 +50,7 @@ module Spec
54
50
  end
55
51
  end
56
52
 
57
- class HashIncludingConstraint
53
+ class HashIncludingMatcher
58
54
  def initialize(expected)
59
55
  @expected = expected
60
56
  end
@@ -73,7 +69,7 @@ module Spec
73
69
  end
74
70
  end
75
71
 
76
- class HashNotIncludingConstraint
72
+ class HashNotIncludingMatcher
77
73
  def initialize(expected)
78
74
  @expected = expected
79
75
  end
@@ -92,7 +88,7 @@ module Spec
92
88
  end
93
89
  end
94
90
 
95
- class DuckTypeConstraint
91
+ class DuckTypeMatcher
96
92
  def initialize(*methods_to_respond_to)
97
93
  @methods_to_respond_to = methods_to_respond_to
98
94
  end
@@ -102,7 +98,7 @@ module Spec
102
98
  end
103
99
  end
104
100
 
105
- class MatcherConstraint
101
+ class MatcherMatcher
106
102
  def initialize(matcher)
107
103
  @matcher = matcher
108
104
  end
@@ -148,7 +144,7 @@ module Spec
148
144
  # Passes if object receives :message with any args at all. This is
149
145
  # really a more explicit variation of object.should_receive(:message)
150
146
  def any_args
151
- AnyArgsConstraint.new
147
+ AnyArgsMatcher.new
152
148
  end
153
149
 
154
150
  # :call-seq:
@@ -156,7 +152,7 @@ module Spec
156
152
  #
157
153
  # Passes as long as there is an argument.
158
154
  def anything
159
- AnyArgConstraint.new(nil)
155
+ AnyArgMatcher.new(nil)
160
156
  end
161
157
 
162
158
  # :call-seq:
@@ -164,7 +160,7 @@ module Spec
164
160
  #
165
161
  # Passes if no arguments are passed along with the message
166
162
  def no_args
167
- NoArgsConstraint.new
163
+ NoArgsMatcher.new
168
164
  end
169
165
 
170
166
  # :call-seq:
@@ -180,7 +176,7 @@ module Spec
180
176
  # display.should_receive(:present_names).with(duck_type(:length, :each))
181
177
  # => passes
182
178
  def duck_type(*args)
183
- DuckTypeConstraint.new(*args)
179
+ DuckTypeMatcher.new(*args)
184
180
  end
185
181
 
186
182
  # :call-seq:
@@ -188,7 +184,7 @@ module Spec
188
184
  #
189
185
  # Passes if the argument is boolean.
190
186
  def boolean
191
- BooleanConstraint.new(nil)
187
+ BooleanMatcher.new(nil)
192
188
  end
193
189
 
194
190
  # :call-seq:
@@ -198,7 +194,7 @@ module Spec
198
194
  # Passes if the argument is a hash that includes the specified key(s) or key/value
199
195
  # pairs. If the hash includes other keys, it will still pass.
200
196
  def hash_including(*args)
201
- HashIncludingConstraint.new(anythingize_lonely_keys(*args))
197
+ HashIncludingMatcher.new(anythingize_lonely_keys(*args))
202
198
  end
203
199
 
204
200
  # :call-seq:
@@ -208,7 +204,7 @@ module Spec
208
204
  #
209
205
  # Passes if the argument is a hash that doesn't include the specified key(s) or key/value
210
206
  def hash_not_including(*args)
211
- HashNotIncludingConstraint.new(anythingize_lonely_keys(*args))
207
+ HashNotIncludingMatcher.new(anythingize_lonely_keys(*args))
212
208
  end
213
209
 
214
210
  # Passes if arg.instance_of?(klass)
@@ -42,9 +42,10 @@ module Spec
42
42
  __raise "#{intro} yielded |#{arg_list(*args_to_yield)}| to block with arity of #{arity}"
43
43
  end
44
44
 
45
- private
45
+ private
46
+
46
47
  def intro
47
- @name ? "Mock '#{@name}'" : @target.class == Class ? "<#{@target.inspect} (class)>" : (@target.nil? ? "nil" : @target.to_s)
48
+ @name ? "Mock '#{@name}'" : @target.class == Class ? "<#{@target.inspect} (class)>" : (@target.nil? ? "nil" : @target)
48
49
  end
49
50
 
50
51
  def __raise(message)
@@ -57,15 +58,11 @@ module Spec
57
58
  end
58
59
 
59
60
  def format_args(*args)
60
- return "(no args)" if args.empty? || args == [:no_args]
61
- return "(any args)" if args == [:any_args]
62
- "(" + arg_list(*args) + ")"
61
+ args.empty? ? "(no args)" : "(" + arg_list(*args) + ")"
63
62
  end
64
63
 
65
64
  def arg_list(*args)
66
- args.collect do |arg|
67
- arg.respond_to?(:description) ? arg.description : arg.inspect
68
- end.join(", ")
65
+ args.collect {|arg| arg.respond_to?(:description) ? arg.description : arg.inspect}.join(", ")
69
66
  end
70
67
 
71
68
  def count_message(count)
@@ -3,7 +3,7 @@
3
3
  # object in the system.
4
4
 
5
5
  require 'spec/mocks/methods'
6
- require 'spec/mocks/argument_constraints'
6
+ require 'spec/mocks/argument_matchers'
7
7
  require 'spec/mocks/spec_methods'
8
8
  require 'spec/mocks/proxy'
9
9
  require 'spec/mocks/mock'
@@ -17,7 +17,7 @@ module Spec
17
17
  @return_block = nil
18
18
  @actual_received_count = 0
19
19
  @expected_received_count = expected_received_count
20
- @args_expectation = ArgumentExpectation.new([ArgumentConstraints::AnyArgsConstraint.new])
20
+ @args_expectation = ArgumentExpectation.new([ArgumentMatchers::AnyArgsMatcher.new])
21
21
  @consecutive = false
22
22
  @exception_to_raise = nil
23
23
  @symbol_to_throw = nil
@@ -56,8 +56,6 @@ module Spec
56
56
  @expected_received_count < values.size
57
57
  end
58
58
  @return_block = block_given? ? return_block : lambda { value }
59
- # Ruby 1.9 - see where this is used below
60
- @ignore_args = !block_given?
61
59
  end
62
60
 
63
61
  # :call-seq:
@@ -157,9 +155,7 @@ module Spec
157
155
  end
158
156
 
159
157
  def invoke_consecutive_return_block(args, block)
160
- args << block unless block.nil?
161
- value = @return_block.call(*args)
162
-
158
+ value = invoke_return_block(args, block)
163
159
  index = [@actual_received_count, value.size-1].min
164
160
  value[index]
165
161
  end
@@ -169,13 +165,9 @@ module Spec
169
165
  # Ruby 1.9 - when we set @return_block to return values
170
166
  # regardless of arguments, any arguments will result in
171
167
  # a "wrong number of arguments" error
172
- if @ignore_args
173
- @return_block.call()
174
- else
175
- @return_block.call(*args)
176
- end
168
+ @return_block.arity > 0 ? @return_block.call(*args) : @return_block.call()
177
169
  end
178
-
170
+
179
171
  def clone_args_to_yield(args)
180
172
  @args_to_yield = args.clone
181
173
  @args_to_yield_were_cloned = true
@@ -234,7 +226,7 @@ module Spec
234
226
  if similar_messages.empty?
235
227
  @error_generator.raise_expectation_error(@sym, @expected_received_count, @actual_received_count, *@args_expectation.args)
236
228
  else
237
- @error_generator.raise_unexpected_message_args_error(self, *@similar_messages.first)
229
+ @error_generator.raise_unexpected_message_args_error(self, *@similar_messages)
238
230
  end
239
231
  end
240
232
 
@@ -14,16 +14,15 @@ module Spec
14
14
  end
15
15
 
16
16
  # This allows for comparing the mock to other objects that proxy such as
17
- # ActiveRecords belongs_to proxy objects By making the other object run
18
- # the comparison, we're sure the call gets delegated to the proxy target
19
- # This is an unfortunate side effect from ActiveRecord, but this should
20
- # be safe unless the RHS redefines == in a nonsensical manner
17
+ # ActiveRecords belongs_to proxy objects. By making the other object run
18
+ # the comparison, we're sure the call gets delegated to the proxy
19
+ # target.
21
20
  def ==(other)
22
21
  other == __mock_proxy
23
22
  end
24
23
 
25
24
  def method_missing(sym, *args, &block)
26
- __mock_proxy.instance_eval {@messages_received << [sym, args, block]}
25
+ __mock_proxy.record_message_received(sym, args, block)
27
26
  begin
28
27
  return self if __mock_proxy.null_object?
29
28
  super(sym, *args, &block)
@@ -82,6 +82,10 @@ module Spec
82
82
  def has_negative_expectation?(sym)
83
83
  @expectations.detect {|expectation| expectation.negative_expectation_for?(sym)}
84
84
  end
85
+
86
+ def record_message_received(sym, args, block)
87
+ @messages_received << [sym, args, block]
88
+ end
85
89
 
86
90
  def message_received(sym, *args, &block)
87
91
  expectation = find_matching_expectation(sym, *args)
@@ -118,7 +122,7 @@ module Spec
118
122
  end
119
123
 
120
124
  def warn_if_nil_class(sym)
121
- if proxy_for_nil_class? && @@warn_about_expectations_on_nil
125
+ if proxy_for_nil_class? & @@warn_about_expectations_on_nil
122
126
  Kernel.warn("An expectation of :#{sym} was set on nil. Called from #{caller[2]}. Use allow_message_expectations_on_nil to disable warnings.")
123
127
  end
124
128
  end
@@ -129,7 +133,7 @@ module Spec
129
133
  if target_responds_to?(sym)
130
134
  munged_sym = munge(sym)
131
135
  target_metaclass.instance_eval do
132
- alias_method munged_sym, sym if method_defined?(sym.to_s)
136
+ alias_method munged_sym, sym if method_defined?(sym)
133
137
  end
134
138
  @proxied_methods << sym
135
139
  end
@@ -162,7 +166,7 @@ module Spec
162
166
  end
163
167
 
164
168
  def munge(sym)
165
- "proxied_by_rspec__#{sym.to_s}".to_sym
169
+ "proxied_by_rspec__#{sym}"
166
170
  end
167
171
 
168
172
  def clear_expectations
@@ -191,9 +195,9 @@ module Spec
191
195
  @proxied_methods.each do |sym|
192
196
  munged_sym = munge(sym)
193
197
  target_metaclass.instance_eval do
194
- if method_defined?(munged_sym.to_s)
198
+ if method_defined?(munged_sym)
195
199
  alias_method sym, munged_sym
196
- undef_method munged_sym
200
+ remove_method munged_sym
197
201
  else
198
202
  remove_method sym
199
203
  end
@@ -1,7 +1,7 @@
1
1
  module Spec
2
2
  module Mocks
3
3
  module ExampleMethods
4
- include Spec::Mocks::ArgumentConstraints
4
+ include Spec::Mocks::ArgumentMatchers
5
5
 
6
6
  # Shortcut for creating an instance of Spec::Mocks::Mock.
7
7
  #
@@ -26,10 +26,19 @@ module Spec
26
26
 
27
27
  alias :stub :mock
28
28
 
29
+ # DEPRECATED - use mock('name').as_null_object instead
30
+ #
29
31
  # Shortcut for creating a mock object that will return itself in response
30
32
  # to any message it receives that it hasn't been explicitly instructed
31
33
  # to respond to.
32
34
  def stub_everything(name = 'stub')
35
+ Kernel.warn(<<-WARNING)
36
+
37
+ DEPRECATION: stub_everything('#{name}') is deprecated and will be removed
38
+ from a future version of rspec. Please use mock('#{name}').as_null_object
39
+ or stub('#{name}').as_null_object instead.
40
+
41
+ WARNING
33
42
  mock(name, :null_object => true)
34
43
  end
35
44
 
@@ -48,7 +48,6 @@ module Spec
48
48
  # This task can also be used to run existing Test::Unit tests and get RSpec
49
49
  # output, for example like this:
50
50
  #
51
- # require 'rubygems'
52
51
  # require 'spec/rake/spectask'
53
52
  # Spec::Rake::SpecTask.new do |t|
54
53
  # t.ruby_opts = ['-rtest/unit']
@@ -15,11 +15,10 @@ module Spec
15
15
  class ExampleGroupCreationListener
16
16
  def register_example_group(klass)
17
17
  Spec::Runner.options.add_example_group klass
18
- Spec::Runner.register_at_exit_hook
19
18
  end
20
19
  end
21
20
 
22
- Spec::Example::ExampleGroupMethods.example_group_creation_listeners << ExampleGroupCreationListener.new
21
+ Spec::Example::ExampleGroupFactory.example_group_creation_listeners << ExampleGroupCreationListener.new
23
22
 
24
23
  class << self
25
24
  def configuration # :nodoc:
@@ -40,17 +39,9 @@ module Spec
40
39
  def configure
41
40
  yield configuration
42
41
  end
43
-
44
- def register_at_exit_hook # :nodoc:
45
- unless @already_registered_at_exit_hook
46
- at_exit do
47
- unless $! || run? || Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?(options.example_groups)
48
- success = run
49
- exit success if exit?
50
- end
51
- end
52
- @already_registered_at_exit_hook = true
53
- end
42
+
43
+ def autorun # :nodoc:
44
+ at_exit {exit run unless $!}
54
45
  end
55
46
 
56
47
  def options # :nodoc:
@@ -65,24 +56,11 @@ module Spec
65
56
  @options = options
66
57
  end
67
58
 
68
- def test_unit_defined?
69
- Object.const_defined?(:Test) && Test.const_defined?(:Unit) && Test::Unit.respond_to?(:run?)
70
- end
71
-
72
- def run?
73
- Runner.options.examples_run?
74
- end
75
-
76
59
  def run
77
- return true if run?
60
+ return true if options.examples_run?
78
61
  options.run_examples
79
62
  end
80
63
 
81
- def exit?
82
- !test_unit_defined? || Test::Unit.run?
83
- end
84
64
  end
85
65
  end
86
- end
87
-
88
- require 'spec/interop/test' if Spec::Runner::test_unit_defined?
66
+ end
@@ -143,14 +143,14 @@ module Spec
143
143
  [get_type_from_options(options)].flatten.each do |required_example_group|
144
144
  required_example_group = required_example_group.to_sym if required_example_group
145
145
  modules.each do |mod|
146
- Spec::Example::ExampleGroupFactory.get(required_example_group).__send__(action, mod)
146
+ Spec::Example::ExampleGroupFactory[required_example_group].__send__(action, mod)
147
147
  end
148
148
  end
149
149
  end
150
150
 
151
151
  def add_callback(sym, *args, &proc)
152
152
  scope, options = Spec::Example.scope_and_options(*args)
153
- example_group = Spec::Example::ExampleGroupFactory.get(get_type_from_options(options))
153
+ example_group = Spec::Example::ExampleGroupFactory[get_type_from_options(options)]
154
154
  example_group.__send__(sym, scope, &proc)
155
155
  end
156
156
 
@@ -159,7 +159,7 @@ module Spec
159
159
  end
160
160
 
161
161
  def mock_framework_path(framework_name)
162
- File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "adapters", "mock_frameworks", framework_name))
162
+ File.expand_path(File.join(File.dirname(__FILE__), "/../adapters/mock_frameworks/#{framework_name}"))
163
163
  end
164
164
  end
165
165
  end
@@ -8,7 +8,8 @@ module Spec
8
8
  # CommandLine - making it possible for clients to use both interchangeably.
9
9
  def self.run(options)
10
10
  begin
11
- DRb.start_service
11
+ # See http://redmine.ruby-lang.org/issues/show/496 as to why we specify localhost:0
12
+ DRb.start_service("druby://localhost:0")
12
13
  spec_server = DRbObject.new_with_uri("druby://127.0.0.1:8989")
13
14
  spec_server.run(options.argv, options.error_stream, options.output_stream)
14
15
  rescue DRb::DRbConnError => e
@@ -6,11 +6,11 @@ module Spec
6
6
  end
7
7
 
8
8
  def load_files(files)
9
+ $KCODE = 'u' if RUBY_VERSION.to_f < 1.9
9
10
  # It's important that loading files (or choosing not to) stays the
10
11
  # responsibility of the ExampleGroupRunner. Some implementations (like)
11
12
  # the one using DRb may choose *not* to load files, but instead tell
12
13
  # someone else to do it over the wire.
13
- $KCODE = 'u' if RUBY_VERSION < '1.9'
14
14
  files.each do |file|
15
15
  load file
16
16
  end
@@ -27,7 +27,8 @@ module Spec
27
27
  finish
28
28
  end
29
29
 
30
- protected
30
+ protected
31
+
31
32
  def prepare
32
33
  reporter.start(number_of_examples)
33
34
  example_groups.reverse! if reverse