rspec 1.0.8 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. data/CHANGES +122 -2
  2. data/README +10 -9
  3. data/Rakefile +22 -49
  4. data/TODO +2 -0
  5. data/bin/spec +1 -1
  6. data/bin/spec_translator +8 -8
  7. data/examples/{auto_spec_description_example.rb → pure/autogenerated_docstrings_example.rb} +0 -0
  8. data/examples/{before_and_after_example.rb → pure/before_and_after_example.rb} +1 -0
  9. data/examples/{behave_as_example.rb → pure/behave_as_example.rb} +0 -0
  10. data/examples/{custom_expectation_matchers.rb → pure/custom_expectation_matchers.rb} +0 -0
  11. data/examples/{custom_formatter.rb → pure/custom_formatter.rb} +1 -0
  12. data/examples/{dynamic_spec.rb → pure/dynamic_spec.rb} +0 -0
  13. data/examples/{file_accessor.rb → pure/file_accessor.rb} +1 -0
  14. data/examples/{file_accessor_spec.rb → pure/file_accessor_spec.rb} +0 -0
  15. data/examples/{greeter_spec.rb → pure/greeter_spec.rb} +1 -0
  16. data/examples/{helper_method_example.rb → pure/helper_method_example.rb} +0 -0
  17. data/examples/{io_processor.rb → pure/io_processor.rb} +0 -0
  18. data/examples/{io_processor_spec.rb → pure/io_processor_spec.rb} +0 -0
  19. data/examples/{legacy_spec.rb → pure/legacy_spec.rb} +1 -0
  20. data/examples/{mocking_example.rb → pure/mocking_example.rb} +0 -0
  21. data/examples/pure/multi_threaded_behaviour_runner.rb +28 -0
  22. data/examples/pure/nested_classes_example.rb +36 -0
  23. data/examples/{partial_mock_example.rb → pure/partial_mock_example.rb} +0 -0
  24. data/examples/{pending_example.rb → pure/pending_example.rb} +0 -0
  25. data/examples/{predicate_example.rb → pure/predicate_example.rb} +0 -0
  26. data/examples/{priority.txt → pure/priority.txt} +0 -0
  27. data/examples/pure/shared_example_group_example.rb +66 -0
  28. data/examples/pure/shared_stack_examples.rb +38 -0
  29. data/examples/pure/spec_helper.rb +3 -0
  30. data/examples/{stack.rb → pure/stack.rb} +0 -0
  31. data/examples/{stack_spec.rb → pure/stack_spec.rb} +1 -35
  32. data/examples/pure/stack_spec_with_nested_example_groups.rb +67 -0
  33. data/examples/{stubbing_example.rb → pure/stubbing_example.rb} +0 -0
  34. data/examples/stories/adder.rb +13 -0
  35. data/examples/stories/addition +34 -0
  36. data/examples/stories/addition.rb +9 -0
  37. data/examples/stories/calculator.rb +65 -0
  38. data/examples/stories/game-of-life/README.txt +21 -0
  39. data/examples/stories/game-of-life/behaviour/everything.rb +6 -0
  40. data/examples/stories/game-of-life/behaviour/examples/examples.rb +3 -0
  41. data/examples/stories/game-of-life/behaviour/examples/game_behaviour.rb +35 -0
  42. data/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb +66 -0
  43. data/examples/stories/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story +21 -0
  44. data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +21 -0
  45. data/examples/stories/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story +42 -0
  46. data/examples/stories/game-of-life/behaviour/stories/ICanCreateACell.story +42 -0
  47. data/examples/stories/game-of-life/behaviour/stories/ICanKillACell.story +17 -0
  48. data/examples/stories/game-of-life/behaviour/stories/TheGridWraps.story +53 -0
  49. data/examples/stories/game-of-life/behaviour/stories/create_a_cell.rb +52 -0
  50. data/examples/stories/game-of-life/behaviour/stories/helper.rb +6 -0
  51. data/examples/stories/game-of-life/behaviour/stories/kill_a_cell.rb +26 -0
  52. data/examples/stories/game-of-life/behaviour/stories/steps.rb +5 -0
  53. data/examples/stories/game-of-life/behaviour/stories/stories.rb +3 -0
  54. data/examples/stories/game-of-life/behaviour/stories/stories.txt +22 -0
  55. data/examples/stories/game-of-life/life.rb +3 -0
  56. data/examples/stories/game-of-life/life/game.rb +23 -0
  57. data/examples/stories/game-of-life/life/grid.rb +43 -0
  58. data/examples/stories/helper.rb +9 -0
  59. data/examples/stories/steps/addition_steps.rb +18 -0
  60. data/lib/autotest/rspec.rb +1 -2
  61. data/lib/spec.rb +30 -6
  62. data/lib/spec/example.rb +12 -0
  63. data/lib/spec/{dsl → example}/configuration.rb +48 -39
  64. data/lib/spec/{dsl → example}/errors.rb +2 -2
  65. data/lib/spec/example/example_group.rb +16 -0
  66. data/lib/spec/example/example_group_factory.rb +62 -0
  67. data/lib/spec/example/example_group_methods.rb +412 -0
  68. data/lib/spec/example/example_matcher.rb +42 -0
  69. data/lib/spec/example/example_methods.rb +101 -0
  70. data/lib/spec/example/module_reopening_fix.rb +21 -0
  71. data/lib/spec/example/pending.rb +18 -0
  72. data/lib/spec/example/shared_example_group.rb +58 -0
  73. data/lib/spec/expectations/differs/default.rb +15 -10
  74. data/lib/spec/expectations/errors.rb +7 -1
  75. data/lib/spec/expectations/extensions/object.rb +12 -7
  76. data/lib/spec/expectations/handler.rb +13 -4
  77. data/lib/spec/extensions.rb +2 -0
  78. data/lib/spec/extensions/class.rb +24 -0
  79. data/lib/spec/extensions/main.rb +54 -0
  80. data/lib/spec/extensions/object.rb +5 -1
  81. data/lib/spec/interop/test.rb +10 -0
  82. data/lib/spec/interop/test/unit/autorunner.rb +6 -0
  83. data/lib/spec/interop/test/unit/testcase.rb +61 -0
  84. data/lib/spec/interop/test/unit/testresult.rb +6 -0
  85. data/lib/spec/interop/test/unit/testsuite_adapter.rb +34 -0
  86. data/lib/spec/interop/test/unit/ui/console/testrunner.rb +60 -0
  87. data/lib/spec/matchers.rb +11 -15
  88. data/lib/spec/matchers/be.rb +23 -6
  89. data/lib/spec/matchers/change.rb +25 -1
  90. data/lib/spec/matchers/exist.rb +17 -0
  91. data/lib/spec/matchers/operator_matcher.rb +1 -0
  92. data/lib/spec/matchers/simple_matcher.rb +29 -0
  93. data/lib/spec/matchers/throw_symbol.rb +2 -0
  94. data/lib/spec/mocks.rb +5 -2
  95. data/lib/spec/mocks/argument_expectation.rb +1 -1
  96. data/lib/spec/mocks/message_expectation.rb +62 -44
  97. data/lib/spec/mocks/methods.rb +2 -2
  98. data/lib/spec/mocks/mock.rb +24 -3
  99. data/lib/spec/mocks/proxy.rb +26 -23
  100. data/lib/spec/mocks/space.rb +1 -1
  101. data/lib/spec/mocks/spec_methods.rb +20 -12
  102. data/lib/spec/rake/spectask.rb +19 -1
  103. data/lib/spec/rake/verify_rcov.rb +1 -1
  104. data/lib/spec/runner.rb +33 -10
  105. data/lib/spec/runner/backtrace_tweaker.rb +3 -3
  106. data/lib/spec/runner/class_and_arguments_parser.rb +16 -0
  107. data/lib/spec/runner/command_line.rb +18 -12
  108. data/lib/spec/runner/drb_command_line.rb +4 -5
  109. data/lib/spec/runner/example_group_runner.rb +59 -0
  110. data/lib/spec/runner/formatter/base_formatter.rb +10 -8
  111. data/lib/spec/runner/formatter/base_text_formatter.rb +18 -18
  112. data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +31 -0
  113. data/lib/spec/runner/formatter/failing_examples_formatter.rb +3 -5
  114. data/lib/spec/runner/formatter/html_formatter.rb +37 -27
  115. data/lib/spec/runner/formatter/profile_formatter.rb +47 -0
  116. data/lib/spec/runner/formatter/progress_bar_formatter.rb +3 -4
  117. data/lib/spec/runner/formatter/specdoc_formatter.rb +27 -13
  118. data/lib/spec/runner/formatter/story/html_formatter.rb +124 -0
  119. data/lib/spec/runner/formatter/story/plain_text_formatter.rb +123 -0
  120. data/lib/spec/runner/formatter/text_mate_formatter.rb +16 -0
  121. data/lib/spec/runner/heckle_runner.rb +9 -9
  122. data/lib/spec/runner/option_parser.rb +140 -138
  123. data/lib/spec/runner/options.rb +168 -90
  124. data/lib/spec/runner/reporter.rb +58 -40
  125. data/lib/spec/runner/spec_parser.rb +11 -8
  126. data/lib/spec/story.rb +10 -0
  127. data/lib/spec/story/extensions.rb +1 -0
  128. data/lib/spec/story/extensions/main.rb +86 -0
  129. data/lib/spec/story/given_scenario.rb +14 -0
  130. data/lib/spec/story/runner.rb +58 -0
  131. data/lib/spec/story/runner/plain_text_story_runner.rb +48 -0
  132. data/lib/spec/story/runner/scenario_collector.rb +18 -0
  133. data/lib/spec/story/runner/scenario_runner.rb +46 -0
  134. data/lib/spec/story/runner/story_mediator.rb +123 -0
  135. data/lib/spec/story/runner/story_parser.rb +227 -0
  136. data/lib/spec/story/runner/story_runner.rb +67 -0
  137. data/lib/spec/story/scenario.rb +14 -0
  138. data/lib/spec/story/step.rb +48 -0
  139. data/lib/spec/story/step_group.rb +89 -0
  140. data/lib/spec/story/step_mother.rb +37 -0
  141. data/lib/spec/story/story.rb +42 -0
  142. data/lib/spec/story/world.rb +124 -0
  143. data/lib/spec/version.rb +4 -5
  144. data/plugins/mock_frameworks/rspec.rb +1 -1
  145. data/spec/autotest/rspec_spec.rb +13 -7
  146. data/spec/autotest_helper.rb +4 -3
  147. data/spec/rspec_suite.rb +7 -0
  148. data/spec/ruby_forker.rb +13 -0
  149. data/spec/spec/example/configuration_spec.rb +290 -0
  150. data/spec/spec/example/example_group_class_definition_spec.rb +48 -0
  151. data/spec/spec/example/example_group_factory_spec.rb +129 -0
  152. data/spec/spec/example/example_group_methods_spec.rb +465 -0
  153. data/spec/spec/example/example_group_spec.rb +711 -0
  154. data/spec/spec/{dsl → example}/example_matcher_spec.rb +23 -18
  155. data/spec/spec/example/example_methods_spec.rb +75 -0
  156. data/spec/spec/example/example_runner_spec.rb +194 -0
  157. data/spec/spec/example/example_spec.rb +53 -0
  158. data/spec/spec/example/nested_example_group_spec.rb +59 -0
  159. data/spec/spec/example/pending_module_spec.rb +31 -0
  160. data/spec/spec/{dsl → example}/predicate_matcher_spec.rb +1 -1
  161. data/spec/spec/example/shared_example_group_spec.rb +265 -0
  162. data/spec/spec/example/subclassing_example_group_spec.rb +25 -0
  163. data/spec/spec/expectations/differs/default_spec.rb +5 -3
  164. data/spec/spec/expectations/extensions/object_spec.rb +63 -2
  165. data/spec/spec/extensions/main_spec.rb +50 -0
  166. data/spec/spec/interop/test/unit/test_unit_spec_helper.rb +14 -0
  167. data/spec/spec/interop/test/unit/testcase_spec.rb +10 -0
  168. data/spec/spec/interop/test/unit/testcase_spec_with_test_unit.rb +20 -0
  169. data/spec/spec/interop/test/unit/testsuite_adapter_spec.rb +9 -0
  170. data/spec/spec/interop/test/unit/testsuite_adapter_spec_with_test_unit.rb +34 -0
  171. data/spec/spec/matchers/be_spec.rb +15 -0
  172. data/spec/spec/matchers/change_spec.rb +87 -0
  173. data/spec/spec/matchers/description_generation_spec.rb +31 -37
  174. data/spec/spec/matchers/exist_spec.rb +31 -22
  175. data/spec/spec/matchers/handler_spec.rb +42 -1
  176. data/spec/spec/matchers/have_spec.rb +1 -1
  177. data/spec/spec/matchers/mock_constraint_matchers_spec.rb +1 -1
  178. data/spec/spec/matchers/operator_matcher_spec.rb +1 -1
  179. data/spec/spec/matchers/simple_matcher_spec.rb +31 -0
  180. data/spec/spec/matchers/throw_symbol_spec.rb +4 -1
  181. data/spec/spec/mocks/bug_report_10263.rb +24 -0
  182. data/spec/spec/mocks/bug_report_15719_spec.rb +30 -0
  183. data/spec/spec/mocks/bug_report_8165_spec.rb +2 -2
  184. data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +1 -0
  185. data/spec/spec/mocks/mock_spec.rb +200 -102
  186. data/spec/spec/mocks/multiple_return_value_spec.rb +1 -1
  187. data/spec/spec/mocks/options_hash_spec.rb +19 -7
  188. data/spec/spec/mocks/partial_mock_spec.rb +31 -9
  189. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +6 -0
  190. data/spec/spec/mocks/stub_spec.rb +120 -98
  191. data/spec/spec/package/bin_spec_spec.rb +7 -5
  192. data/spec/spec/runner/class_and_argument_parser_spec.rb +23 -0
  193. data/spec/spec/runner/command_line_spec.rb +140 -27
  194. data/spec/spec/runner/drb_command_line_spec.rb +39 -31
  195. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +44 -0
  196. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +16 -11
  197. data/spec/spec/runner/formatter/html_formatter_spec.rb +60 -50
  198. data/spec/spec/runner/formatter/profile_formatter_spec.rb +65 -0
  199. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +29 -13
  200. data/spec/spec/runner/formatter/snippet_extractor_spec.rb +14 -7
  201. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +103 -0
  202. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +103 -39
  203. data/spec/spec/runner/formatter/story/html_formatter_spec.rb +56 -0
  204. data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +289 -0
  205. data/spec/spec/runner/heckle_runner_spec.rb +29 -14
  206. data/spec/spec/runner/heckler_spec.rb +4 -5
  207. data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +5 -5
  208. data/spec/spec/runner/option_parser_spec.rb +86 -58
  209. data/spec/spec/runner/options_spec.rb +239 -120
  210. data/spec/spec/runner/output_one_time_fixture.rb +7 -0
  211. data/spec/spec/runner/output_one_time_fixture_runner.rb +8 -0
  212. data/spec/spec/runner/output_one_time_spec.rb +16 -0
  213. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +6 -6
  214. data/spec/spec/runner/reporter_spec.rb +147 -163
  215. data/spec/spec/runner/spec_parser_spec.rb +31 -0
  216. data/spec/spec/runner_spec.rb +11 -0
  217. data/spec/spec/spec_classes.rb +12 -5
  218. data/spec/spec/story/builders.rb +46 -0
  219. data/spec/spec/story/extensions/main_spec.rb +161 -0
  220. data/spec/spec/story/extensions_spec.rb +14 -0
  221. data/spec/spec/story/given_scenario_spec.rb +27 -0
  222. data/spec/spec/story/runner/plain_text_story_runner_spec.rb +92 -0
  223. data/spec/spec/story/runner/scenario_collector_spec.rb +27 -0
  224. data/spec/spec/story/runner/scenario_runner_spec.rb +142 -0
  225. data/spec/spec/story/runner/story_mediator_spec.rb +133 -0
  226. data/spec/spec/story/runner/story_parser_spec.rb +384 -0
  227. data/spec/spec/story/runner/story_runner_spec.rb +219 -0
  228. data/spec/spec/story/runner_spec.rb +106 -0
  229. data/spec/spec/story/scenario_spec.rb +20 -0
  230. data/spec/spec/story/step_group_spec.rb +157 -0
  231. data/spec/spec/story/step_mother_spec.rb +72 -0
  232. data/spec/spec/story/step_spec.rb +147 -0
  233. data/spec/spec/story/story_helper.rb +2 -0
  234. data/spec/spec/story/story_spec.rb +86 -0
  235. data/spec/spec/story/world_spec.rb +416 -0
  236. data/spec/spec/translator_spec.rb +2 -1
  237. data/spec/spec_helper.rb +59 -2
  238. data/stories/all.rb +5 -0
  239. data/stories/example_groups/autogenerated_docstrings +26 -0
  240. data/stories/example_groups/example_group_with_should_methods +17 -0
  241. data/stories/example_groups/nested_groups +17 -0
  242. data/stories/example_groups/output +20 -0
  243. data/stories/example_groups/stories.rb +7 -0
  244. data/stories/helper.rb +6 -0
  245. data/stories/interop/examples_and_tests_together +30 -0
  246. data/stories/interop/stories.rb +7 -0
  247. data/stories/interop/test_case_with_should_methods +17 -0
  248. data/stories/pending_stories/README +3 -0
  249. data/stories/resources/helpers/cmdline.rb +9 -0
  250. data/stories/resources/helpers/story_helper.rb +16 -0
  251. data/stories/resources/matchers/smart_match.rb +37 -0
  252. data/stories/resources/spec/example_group_with_should_methods.rb +12 -0
  253. data/stories/resources/spec/simple_spec.rb +8 -0
  254. data/stories/resources/steps/running_rspec.rb +50 -0
  255. data/stories/resources/test/spec_and_test_together.rb +57 -0
  256. data/stories/resources/test/test_case_with_should_methods.rb +30 -0
  257. metadata +232 -106
  258. data/EXAMPLES.rd +0 -111
  259. data/examples/multi_threaded_behaviour_runner.rb +0 -25
  260. data/examples/shared_behaviours_example.rb +0 -39
  261. data/examples/spec_helper.rb +0 -1
  262. data/examples/test_case_adapter_example.rb +0 -26
  263. data/examples/test_case_spec.rb +0 -65
  264. data/lib/spec/dsl.rb +0 -11
  265. data/lib/spec/dsl/behaviour.rb +0 -220
  266. data/lib/spec/dsl/behaviour_callbacks.rb +0 -82
  267. data/lib/spec/dsl/behaviour_eval.rb +0 -231
  268. data/lib/spec/dsl/behaviour_factory.rb +0 -42
  269. data/lib/spec/dsl/composite_proc_builder.rb +0 -33
  270. data/lib/spec/dsl/description.rb +0 -76
  271. data/lib/spec/dsl/example.rb +0 -135
  272. data/lib/spec/dsl/example_matcher.rb +0 -40
  273. data/lib/spec/dsl/example_should_raise_handler.rb +0 -74
  274. data/lib/spec/runner/behaviour_runner.rb +0 -123
  275. data/lib/spec/runner/extensions/kernel.rb +0 -50
  276. data/lib/spec/runner/extensions/object.rb +0 -32
  277. data/lib/spec/runner/formatter.rb +0 -9
  278. data/lib/spec/runner/formatter/failing_behaviours_formatter.rb +0 -29
  279. data/lib/spec/runner/formatter/rdoc_formatter.rb +0 -24
  280. data/lib/spec/test_case_adapter.rb +0 -10
  281. data/spec/spec/dsl/behaviour_eval_spec.rb +0 -79
  282. data/spec/spec/dsl/behaviour_factory_spec.rb +0 -48
  283. data/spec/spec/dsl/behaviour_spec.rb +0 -661
  284. data/spec/spec/dsl/composite_proc_builder_spec.rb +0 -44
  285. data/spec/spec/dsl/configuration_spec.rb +0 -55
  286. data/spec/spec/dsl/description_spec.rb +0 -89
  287. data/spec/spec/dsl/example_class_spec.rb +0 -24
  288. data/spec/spec/dsl/example_instance_spec.rb +0 -160
  289. data/spec/spec/dsl/example_should_raise_spec.rb +0 -137
  290. data/spec/spec/dsl/shared_behaviour_spec.rb +0 -252
  291. data/spec/spec/runner/behaviour_runner_spec.rb +0 -229
  292. data/spec/spec/runner/context_matching_spec.rb +0 -27
  293. data/spec/spec/runner/extensions/bug_report_10577_spec.rb +0 -35
  294. data/spec/spec/runner/extensions/kernel_spec.rb +0 -36
  295. data/spec/spec/runner/formatter/failing_behaviours_formatter_spec.rb +0 -40
  296. data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +0 -20
  297. data/spec/spec/runner/formatter/progress_bar_formatter_failure_dump_spec.rb +0 -36
  298. data/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb +0 -19
  299. data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +0 -46
  300. data/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb +0 -21
  301. data/spec/spec/runner/object_ext_spec.rb +0 -11
@@ -33,7 +33,7 @@ module ExampleExpectations
33
33
  end
34
34
 
35
35
  class PositiveOnlyMatcher < ArbitraryMatcher
36
- undef negative_failure_message
36
+ undef negative_failure_message rescue nil
37
37
  end
38
38
 
39
39
  def arbitrary_matcher(*args, &block)
@@ -55,6 +55,47 @@ module Spec
55
55
  matcher.should_receive(:matches?).with(actual).and_return(true)
56
56
  ExpectationMatcherHandler.handle_matcher(actual, matcher)
57
57
  end
58
+
59
+ it "should explain when the matcher parameter is not a matcher" do
60
+ begin
61
+ nonmatcher = mock("nonmatcher")
62
+ actual = Object.new
63
+ ExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
64
+ rescue Spec::Expectations::InvalidMatcherError => e
65
+ end
66
+
67
+ e.message.should =~ /^Expected a matcher, got /
68
+ end
69
+ end
70
+
71
+ describe NegativeExpectationMatcherHandler, ".handle_matcher" do
72
+ it "should explain when matcher does not support should_not" do
73
+ matcher = mock("matcher")
74
+ matcher.stub!(:matches?)
75
+ actual = Object.new
76
+ lambda {
77
+ NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
78
+ }.should fail_with(/Matcher does not support should_not.\n/)
79
+ end
80
+
81
+ it "should ask the matcher if it matches" do
82
+ matcher = mock("matcher")
83
+ actual = Object.new
84
+ matcher.stub!(:negative_failure_message)
85
+ matcher.should_receive(:matches?).with(actual).and_return(false)
86
+ NegativeExpectationMatcherHandler.handle_matcher(actual, matcher)
87
+ end
88
+
89
+ it "should explain when the matcher parameter is not a matcher" do
90
+ begin
91
+ nonmatcher = mock("nonmatcher")
92
+ actual = Object.new
93
+ NegativeExpectationMatcherHandler.handle_matcher(actual, nonmatcher)
94
+ rescue Spec::Expectations::InvalidMatcherError => e
95
+ end
96
+
97
+ e.message.should =~ /^Expected a matcher, got /
98
+ end
58
99
  end
59
100
 
60
101
  describe ExpectationMatcherHandler do
@@ -250,7 +250,7 @@ describe "have(n).items where target IS a collection" do
250
250
  [1,2,3].should have(3).items
251
251
  end
252
252
 
253
- it "should reference the number of items IN the collection" do
253
+ it "should fail when the number of items IN the collection is not as expected" do
254
254
  lambda { [1,2,3].should have(7).items }.should fail_with("expected 7 items, got 3")
255
255
  end
256
256
  end
@@ -19,6 +19,6 @@ describe "The boolean() mock argument constraint matcher" do
19
19
  end
20
20
 
21
21
  describe "The an_instance_of() mock argument constraint matcher" do
22
- # NOTE - this is implemented as a predicate_matcher - see behaviour.rb
22
+ # NOTE - this is implemented as a predicate_matcher - see example_group_methods.rb
23
23
  specify { an_instance_of(String).should == "string" }
24
24
  end
@@ -48,7 +48,7 @@ describe "should ===" do
48
48
  Spec::Expectations.should_receive(:fail_with).with(%[expected: "orange",\n got: "apple" (using ===)], "orange", "apple")
49
49
  subject.should === "orange"
50
50
  end
51
-
51
+
52
52
  end
53
53
 
54
54
  describe "should_not ===" do
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Spec
4
+ module Matchers
5
+ describe SimpleMatcher do
6
+ it "should match pass match arg to block" do
7
+ actual = nil
8
+ matcher = simple_matcher("message") do |given| actual = given end
9
+ matcher.matches?("foo")
10
+ actual.should == "foo"
11
+ end
12
+
13
+ it "should provide a stock failure message" do
14
+ matcher = simple_matcher("thing") do end
15
+ matcher.matches?("other")
16
+ matcher.failure_message.should =~ /expected \"thing\" but got \"other\"/
17
+ end
18
+
19
+ it "should provide a stock negative failure message" do
20
+ matcher = simple_matcher("thing") do end
21
+ matcher.matches?("other")
22
+ matcher.negative_failure_message.should =~ /expected not to get \"thing\", but got \"other\"/
23
+ end
24
+
25
+ it "should provide a description" do
26
+ matcher = simple_matcher("thing") do end
27
+ matcher.description.should =="thing"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -27,7 +27,7 @@ module Spec
27
27
  it "should match if correct Symbol is thrown" do
28
28
  @matcher.matches?(lambda{ throw :sym }).should be_true
29
29
  end
30
- it "should not match no Symbol is thrown" do
30
+ it "should not match if no Symbol is thrown" do
31
31
  @matcher.matches?(lambda{ }).should be_false
32
32
  end
33
33
  it "should not match if correct Symbol is thrown" do
@@ -46,6 +46,9 @@ module Spec
46
46
  @matcher.matches?(lambda{ throw :sym })
47
47
  @matcher.negative_failure_message.should == "expected :sym not to be thrown"
48
48
  end
49
+ it "should only match NameErrors raised by uncaught throws" do
50
+ @matcher.matches?(lambda{ sym }).should be_false
51
+ end
49
52
  end
50
53
  end
51
54
  end
@@ -0,0 +1,24 @@
1
+ describe "Mock" do
2
+ before do
3
+ @mock = mock("test mock")
4
+ end
5
+
6
+ specify "when one example has an expectation (non-mock) inside the block passed to the mock" do
7
+ @mock.should_receive(:msg) do |b|
8
+ b.should be_true #this call exposes the problem
9
+ end
10
+ @mock.msg(false) rescue nil
11
+ end
12
+
13
+ specify "then the next example should behave as expected instead of saying" do
14
+ @mock.should_receive(:foobar)
15
+ @mock.foobar
16
+ @mock.rspec_verify
17
+ begin
18
+ @mock.foobar
19
+ rescue => e
20
+ e.message.should == "Mock 'test mock' received unexpected message :foobar with (no args)"
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ module Spec
4
+ module Mocks
5
+ describe "mock failure" do
6
+
7
+ it "should tell you when it receives the right message with the wrong args" do
8
+ m = mock("foo")
9
+ m.should_receive(:bar).with("message")
10
+ lambda {
11
+ m.bar("different message")
12
+ }.should raise_error(Spec::Mocks::MockExpectationError, %Q{Mock 'foo' expected :bar with ("message") but received it with ("different message")})
13
+ m.bar("message") # allows the spec to pass
14
+ end
15
+
16
+ it "should tell you when it receives the right message with the wrong args if you stub the method" do
17
+ pending("fix bug 15719")
18
+ # NOTE - for whatever reason, if you use a the block style of pending here,
19
+ # rcov gets unhappy. Don't know why yet.
20
+ m = mock("foo")
21
+ m.stub!(:bar)
22
+ m.should_receive(:bar).with("message")
23
+ lambda {
24
+ m.bar("different message")
25
+ }.should raise_error(Spec::Mocks::MockExpectationError, %Q{Mock 'foo' expected :bar with ("message") but received it with ("different message")})
26
+ m.bar("message") # allows the spec to pass
27
+ end
28
+ end
29
+ end
30
+ end
@@ -12,7 +12,7 @@ describe "An object where respond_to? is true and does not have method" do
12
12
  # The fix was to keep track of whether :respond_to? had been proxied and, if
13
13
  # so, call the munged copy of :respond_to? on the object.
14
14
 
15
- it "should not raise an exception" do
15
+ it "should not raise an exception for Object" do
16
16
  obj = Object.new
17
17
  obj.should_receive(:respond_to?).with(:foobar).and_return(true)
18
18
  obj.should_receive(:foobar).and_return(:baz)
@@ -20,7 +20,7 @@ describe "An object where respond_to? is true and does not have method" do
20
20
  obj.foobar.should == :baz
21
21
  end
22
22
 
23
- it "should not raise an exception" do
23
+ it "should not raise an exception for mock" do
24
24
  obj = mock("obj")
25
25
  obj.should_receive(:respond_to?).with(:foobar).and_return(true)
26
26
  obj.should_receive(:foobar).and_return(:baz)
@@ -81,6 +81,7 @@ module Spec
81
81
  before(:each) do
82
82
  @mock = mock("test mock")
83
83
  @reporter = Mock.new("reporter", :null_object => true)
84
+ Kernel.stub!(:warn)
84
85
  end
85
86
 
86
87
  after(:each) do
@@ -2,107 +2,96 @@ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  module Spec
4
4
  module Mocks
5
- describe "a Mock expectation" do
5
+ describe Mock do
6
6
 
7
- before do
7
+ before(:each) do
8
8
  @mock = mock("test mock")
9
9
  end
10
10
 
11
- after do
11
+ after(:each) do
12
12
  @mock.rspec_reset
13
13
  end
14
14
 
15
15
  it "should report line number of expectation of unreceived message" do
16
- @mock.should_receive(:wont_happen).with("x", 3)
17
- #NOTE - this test is quite ticklish because it specifies that
18
- #the above statement appears on line 12 of this file.
19
-
16
+ expected_error_line = __LINE__; @mock.should_receive(:wont_happen).with("x", 3)
20
17
  begin
21
18
  @mock.rspec_verify
22
19
  violated
23
20
  rescue MockExpectationError => e
24
- e.backtrace[0].should match(/mock_spec\.rb:16/)
21
+ # NOTE - this regexp ended w/ $, but jruby adds extra info at the end of the line
22
+ e.backtrace[0].should match(/#{File.basename(__FILE__)}:#{expected_error_line}/)
25
23
  end
26
-
27
24
  end
28
25
 
29
26
  it "should pass when not receiving message specified as not to be received" do
30
27
  @mock.should_not_receive(:not_expected)
31
28
  @mock.rspec_verify
32
29
  end
33
-
30
+
34
31
  it "should pass when receiving message specified as not to be received with different args" do
35
32
  @mock.should_not_receive(:message).with("unwanted text")
36
33
  @mock.should_receive(:message).with("other text")
37
34
  @mock.message "other text"
38
35
  @mock.rspec_verify
39
36
  end
40
-
37
+
41
38
  it "should fail when receiving message specified as not to be received" do
42
39
  @mock.should_not_receive(:not_expected)
43
40
  @mock.not_expected
44
- begin
41
+ lambda {
45
42
  @mock.rspec_verify
46
43
  violated
47
- rescue MockExpectationError => e
48
- e.message.should == "Mock 'test mock' expected :not_expected with (any args) 0 times, but received it once"
49
- end
44
+ }.should raise_error(MockExpectationError, "Mock 'test mock' expected :not_expected with (any args) 0 times, but received it once")
50
45
  end
51
-
46
+
52
47
  it "should fail when receiving message specified as not to be received with args" do
53
48
  @mock.should_not_receive(:not_expected).with("unexpected text")
54
49
  @mock.not_expected("unexpected text")
55
- begin
50
+ lambda {
56
51
  @mock.rspec_verify
57
52
  violated
58
- rescue MockExpectationError => e
59
- e.message.should == "Mock 'test mock' expected :not_expected with (\"unexpected text\") 0 times, but received it once"
60
- end
53
+ }.should raise_error(MockExpectationError, "Mock 'test mock' expected :not_expected with (\"unexpected text\") 0 times, but received it once")
61
54
  end
62
-
55
+
63
56
  it "should pass when receiving message specified as not to be received with wrong args" do
64
57
  @mock.should_not_receive(:not_expected).with("unexpected text")
65
58
  @mock.not_expected "really unexpected text"
66
59
  @mock.rspec_verify
67
60
  end
68
-
61
+
69
62
  it "should allow block to calculate return values" do
70
63
  @mock.should_receive(:something).with("a","b","c").and_return { |a,b,c| c+b+a }
71
64
  @mock.something("a","b","c").should == "cba"
72
65
  @mock.rspec_verify
73
66
  end
74
-
67
+
75
68
  it "should allow parameter as return value" do
76
69
  @mock.should_receive(:something).with("a","b","c").and_return("booh")
77
70
  @mock.something("a","b","c").should == "booh"
78
71
  @mock.rspec_verify
79
72
  end
80
-
73
+
81
74
  it "should return nil if no return value set" do
82
75
  @mock.should_receive(:something).with("a","b","c")
83
76
  @mock.something("a","b","c").should be_nil
84
77
  @mock.rspec_verify
85
78
  end
86
-
79
+
87
80
  it "should raise exception if args dont match when method called" do
88
81
  @mock.should_receive(:something).with("a","b","c").and_return("booh")
89
- begin
82
+ lambda {
90
83
  @mock.something("a","d","c")
91
84
  violated
92
- rescue MockExpectationError => e
93
- e.message.should == "Mock 'test mock' expected :something with (\"a\", \"b\", \"c\") but received it with (\"a\", \"d\", \"c\")"
94
- end
85
+ }.should raise_error(MockExpectationError, "Mock 'test mock' expected :something with (\"a\", \"b\", \"c\") but received it with (\"a\", \"d\", \"c\")")
95
86
  end
96
-
87
+
97
88
  it "should fail if unexpected method called" do
98
- begin
89
+ lambda {
99
90
  @mock.something("a","b","c")
100
91
  violated
101
- rescue MockExpectationError => e
102
- e.message.should == "Mock 'test mock' received unexpected message :something with (\"a\", \"b\", \"c\")"
103
- end
92
+ }.should raise_error(MockExpectationError, "Mock 'test mock' received unexpected message :something with (\"a\", \"b\", \"c\")")
104
93
  end
105
-
94
+
106
95
  it "should use block for expectation if provided" do
107
96
  @mock.should_receive(:something) do | a, b |
108
97
  a.should == "a"
@@ -112,71 +101,74 @@ module Spec
112
101
  @mock.something("a", "b").should == "booh"
113
102
  @mock.rspec_verify
114
103
  end
115
-
104
+
116
105
  it "should fail if expectation block fails" do
117
106
  @mock.should_receive(:something) {| bool | bool.should be_true}
118
- begin
107
+ lambda {
119
108
  @mock.something false
120
- rescue MockExpectationError => e
121
- e.message.should match(/Mock 'test mock' received :something but passed block failed with: expected true, got false/)
122
- end
109
+ }.should raise_error(MockExpectationError, /Mock 'test mock' received :something but passed block failed with: expected true, got false/)
123
110
  end
124
-
125
- it "should fail when method defined as never is received" do
111
+
112
+ it "should fail right away when method defined as never is received" do
113
+ pending "Used to pass (false positive). Which one is wrong, the spec or the actual behavior?"
114
+
126
115
  @mock.should_receive(:not_expected).never
127
- begin
116
+ lambda {
128
117
  @mock.not_expected
129
- rescue MockExpectationError => e
130
- e.message.should == "Mock 'test mock' expected :not_expected 0 times, but received it 1 times"
131
- end
118
+ }.should raise_error(MockExpectationError, "Mock 'test mock' expected :not_expected 0 times, but received it 1 times")
132
119
  end
133
120
 
121
+ it "should eventually fail when method defined as never is received" do
122
+ @mock.should_receive(:not_expected).never
123
+ @mock.not_expected
124
+
125
+ lambda {
126
+ @mock.rspec_verify
127
+ }.should raise_error(MockExpectationError, "Mock 'test mock' expected :not_expected with (any args) 0 times, but received it once")
128
+ end
129
+
134
130
  it "should raise when told to" do
135
131
  @mock.should_receive(:something).and_raise(RuntimeError)
136
132
  lambda do
137
133
  @mock.something
138
134
  end.should raise_error(RuntimeError)
139
135
  end
140
-
136
+
141
137
  it "should raise passed an Exception instance" do
142
138
  error = RuntimeError.new("error message")
143
139
  @mock.should_receive(:something).and_raise(error)
144
- begin
140
+ lambda {
145
141
  @mock.something
146
- rescue RuntimeError => e
147
- e.message.should eql("error message")
148
- end
142
+ }.should raise_error(RuntimeError, "error message")
149
143
  end
150
-
144
+
151
145
  it "should raise RuntimeError with passed message" do
152
146
  @mock.should_receive(:something).and_raise("error message")
153
- begin
147
+ lambda {
154
148
  @mock.something
155
- rescue RuntimeError => e
156
- e.message.should eql("error message")
157
- end
149
+ }.should raise_error(RuntimeError, "error message")
158
150
  end
159
-
151
+
160
152
  it "should not raise when told to if args dont match" do
161
153
  @mock.should_receive(:something).with(2).and_raise(RuntimeError)
162
- lambda do
154
+ lambda {
163
155
  @mock.something 1
164
- end.should raise_error(MockExpectationError)
156
+ }.should raise_error(MockExpectationError)
165
157
  end
166
-
158
+
167
159
  it "should throw when told to" do
168
160
  @mock.should_receive(:something).and_throw(:blech)
169
- lambda do
161
+ lambda {
170
162
  @mock.something
171
- end.should throw_symbol(:blech)
163
+ }.should throw_symbol(:blech)
172
164
  end
173
-
165
+
174
166
  it "should raise when explicit return and block constrained" do
175
- lambda do
167
+ lambda {
176
168
  @mock.should_receive(:fruit) do |colour|
177
169
  :strawberry
178
170
  end.and_return :apple
179
- end.should raise_error(AmbiguousReturnError)
171
+ }.should raise_error(AmbiguousReturnError)
180
172
  end
181
173
 
182
174
  it "should ignore args on any args" do
@@ -190,22 +182,18 @@ module Spec
190
182
 
191
183
  it "should fail on no args if any args received" do
192
184
  @mock.should_receive(:something).with(no_args())
193
- begin
185
+ lambda {
194
186
  @mock.something 1
195
- rescue MockExpectationError => e
196
- e.message.should == "Mock 'test mock' expected :something with (no args) but received it with (1)"
197
- end
187
+ }.should raise_error(MockExpectationError, "Mock 'test mock' expected :something with (no args) but received it with (1)")
198
188
  end
199
-
189
+
200
190
  it "should fail when args are expected but none are received" do
201
191
  @mock.should_receive(:something).with(1)
202
- begin
192
+ lambda {
203
193
  @mock.something
204
- rescue MockExpectationError => e
205
- e.message.should == "Mock 'test mock' expected :something with (1) but received it with (no args)"
206
- end
194
+ }.should raise_error(MockExpectationError, "Mock 'test mock' expected :something with (1) but received it with (no args)")
207
195
  end
208
-
196
+
209
197
  it "should yield 0 args to blocks that take a variable number of arguments" do
210
198
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield
211
199
  a = nil
@@ -213,7 +201,17 @@ module Spec
213
201
  a.should == []
214
202
  @mock.rspec_verify
215
203
  end
216
-
204
+
205
+ it "should yield 0 args multiple times to blocks that take a variable number of arguments" do
206
+ @mock.should_receive(:yield_back).once.with(no_args()).once.and_yield.
207
+ and_yield
208
+ a = nil
209
+ b = []
210
+ @mock.yield_back {|*a| b << a}
211
+ b.should == [ [], [] ]
212
+ @mock.rspec_verify
213
+ end
214
+
217
215
  it "should yield one arg to blocks that take a variable number of arguments" do
218
216
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield(99)
219
217
  a = nil
@@ -221,7 +219,18 @@ module Spec
221
219
  a.should == [99]
222
220
  @mock.rspec_verify
223
221
  end
224
-
222
+
223
+ it "should yield one arg 3 times consecutively to blocks that take a variable number of arguments" do
224
+ @mock.should_receive(:yield_back).once.with(no_args()).once.and_yield(99).
225
+ and_yield(43).
226
+ and_yield("something fruity")
227
+ a = nil
228
+ b = []
229
+ @mock.yield_back {|*a| b << a}
230
+ b.should == [[99], [43], ["something fruity"]]
231
+ @mock.rspec_verify
232
+ end
233
+
225
234
  it "should yield many args to blocks that take a variable number of arguments" do
226
235
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield(99, 27, "go")
227
236
  a = nil
@@ -230,6 +239,17 @@ module Spec
230
239
  @mock.rspec_verify
231
240
  end
232
241
 
242
+ it "should yield many args 3 times consecutively to blocks that take a variable number of arguments" do
243
+ @mock.should_receive(:yield_back).once.with(no_args()).once.and_yield(99, :green, "go").
244
+ and_yield("wait", :amber).
245
+ and_yield("stop", 12, :red)
246
+ a = nil
247
+ b = []
248
+ @mock.yield_back {|*a| b << a}
249
+ b.should == [[99, :green, "go"], ["wait", :amber], ["stop", 12, :red]]
250
+ @mock.rspec_verify
251
+ end
252
+
233
253
  it "should yield single value" do
234
254
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield(99)
235
255
  a = nil
@@ -237,7 +257,18 @@ module Spec
237
257
  a.should == 99
238
258
  @mock.rspec_verify
239
259
  end
240
-
260
+
261
+ it "should yield single value 3 times consecutively" do
262
+ @mock.should_receive(:yield_back).once.with(no_args()).once.and_yield(99).
263
+ and_yield(43).
264
+ and_yield("something fruity")
265
+ a = nil
266
+ b = []
267
+ @mock.yield_back {|a| b << a}
268
+ b.should == [99, 43, "something fruity"]
269
+ @mock.rspec_verify
270
+ end
271
+
241
272
  it "should yield two values" do
242
273
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
243
274
  a, b = nil
@@ -246,23 +277,41 @@ module Spec
246
277
  b.should == 'zup'
247
278
  @mock.rspec_verify
248
279
  end
249
-
280
+
281
+ it "should yield two values 3 times consecutively" do
282
+ @mock.should_receive(:yield_back).once.with(no_args()).once.and_yield('wha', 'zup').
283
+ and_yield('not', 'down').
284
+ and_yield(14, 65)
285
+ a, b = nil
286
+ c = []
287
+ @mock.yield_back {|a,b| c << [a, b]}
288
+ c.should == [['wha', 'zup'], ['not', 'down'], [14, 65]]
289
+ @mock.rspec_verify
290
+ end
291
+
250
292
  it "should fail when calling yielding method with wrong arity" do
251
293
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
252
- begin
294
+ lambda {
253
295
  @mock.yield_back {|a|}
254
- rescue MockExpectationError => e
255
- e.message.should == "Mock 'test mock' yielded |\"wha\", \"zup\"| to block with arity of 1"
256
- end
296
+ }.should raise_error(MockExpectationError, "Mock 'test mock' yielded |\"wha\", \"zup\"| to block with arity of 1")
257
297
  end
258
-
298
+
299
+ it "should fail when calling yielding method consecutively with wrong arity" do
300
+ @mock.should_receive(:yield_back).once.with(no_args()).once.and_yield('wha', 'zup').
301
+ and_yield('down').
302
+ and_yield(14, 65)
303
+ lambda {
304
+ a, b = nil
305
+ c = []
306
+ @mock.yield_back {|a,b| c << [a, b]}
307
+ }.should raise_error(MockExpectationError, "Mock 'test mock' yielded |\"down\"| to block with arity of 2")
308
+ end
309
+
259
310
  it "should fail when calling yielding method without block" do
260
311
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
261
- begin
312
+ lambda {
262
313
  @mock.yield_back
263
- rescue MockExpectationError => e
264
- e.message.should == "Mock 'test mock' asked to yield |\"wha\", \"zup\"| but no block was passed"
265
- end
314
+ }.should raise_error(MockExpectationError, "Mock 'test mock' asked to yield |[\"wha\", \"zup\"]| but no block was passed")
266
315
  end
267
316
 
268
317
  it "should be able to mock send" do
@@ -274,26 +323,23 @@ module Spec
274
323
  it "should be able to raise from method calling yielding mock" do
275
324
  @mock.should_receive(:yield_me).and_yield 44
276
325
 
277
- lambda do
326
+ lambda {
278
327
  @mock.yield_me do |x|
279
328
  raise "Bang"
280
329
  end
281
- end.should raise_error(StandardError)
282
-
330
+ }.should raise_error(StandardError, "Bang")
331
+
283
332
  @mock.rspec_verify
284
333
  end
285
334
 
286
- # TODO - this is failing, but not if you run the file w/ --reverse - weird!!!!!!
287
- # specify "should clear expectations after verify" do
288
- # @mock.should_receive(:foobar)
289
- # @mock.foobar
290
- # @mock.rspec_verify
291
- # begin
292
- # @mock.foobar
293
- # rescue MockExpectationError => e
294
- # e.message.should == "Mock 'test mock' received unexpected message :foobar with (no args)"
295
- # end
296
- # end
335
+ it "should clear expectations after verify" do
336
+ @mock.should_receive(:foobar)
337
+ @mock.foobar
338
+ @mock.rspec_verify
339
+ lambda {
340
+ @mock.foobar
341
+ }.should raise_error(MockExpectationError, "Mock 'test mock' received unexpected message :foobar with (no args)")
342
+ end
297
343
 
298
344
  it "should restore objects to their original state on rspec_reset" do
299
345
  mock = mock("this is a mock")
@@ -302,6 +348,58 @@ module Spec
302
348
  mock.rspec_verify #should throw if reset didn't work
303
349
  end
304
350
 
351
+ it "should work even after method_missing starts raising NameErrors instead of NoMethodErrors" do
352
+ # Object#method_missing throws either NameErrors or NoMethodErrors.
353
+ #
354
+ # On a fresh ruby program Object#method_missing:
355
+ # * raises a NoMethodError when called directly
356
+ # * raises a NameError when called indirectly
357
+ #
358
+ # Once Object#method_missing has been called at least once (on any object)
359
+ # it starts behaving differently:
360
+ # * raises a NameError when called directly
361
+ # * raises a NameError when called indirectly
362
+ #
363
+ # There was a bug in Mock#method_missing that relied on the fact
364
+ # that calling Object#method_missing directly raises a NoMethodError.
365
+ # This example tests that the bug doesn't exist anymore.
366
+
367
+
368
+ # Ensures that method_missing always raises NameErrors.
369
+ a_method_that_doesnt_exist rescue
370
+
371
+
372
+ @mock.should_receive(:foobar)
373
+ @mock.foobar
374
+ @mock.rspec_verify
375
+
376
+ lambda { @mock.foobar }.should_not raise_error(NameError)
377
+ lambda { @mock.foobar }.should raise_error(MockExpectationError)
378
+ end
379
+
380
+ it "should temporarily replace a method stub on a mock" do
381
+ @mock.stub!(:msg).and_return(:stub_value)
382
+ @mock.should_receive(:msg).with(:arg).and_return(:mock_value)
383
+ @mock.msg(:arg).should equal(:mock_value)
384
+ @mock.msg.should equal(:stub_value)
385
+ @mock.msg.should equal(:stub_value)
386
+ @mock.rspec_verify
387
+ end
388
+
389
+ it "should temporarily replace a method stub on a non-mock" do
390
+ non_mock = Object.new
391
+ non_mock.stub!(:msg).and_return(:stub_value)
392
+ non_mock.should_receive(:msg).with(:arg).and_return(:mock_value)
393
+ non_mock.msg(:arg).should equal(:mock_value)
394
+ non_mock.msg.should equal(:stub_value)
395
+ non_mock.msg.should equal(:stub_value)
396
+ non_mock.rspec_verify
397
+ end
398
+
399
+ it "should assign stub return values" do
400
+ mock = Mock.new('name', :message => :response)
401
+ mock.message.should == :response
402
+ end
305
403
  end
306
404
 
307
405
  describe "a mock message receiving a block" do