rspec 0.8.2 → 0.9.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 (245) hide show
  1. data/CHANGES +125 -9
  2. data/EXAMPLES.rd +50 -27
  3. data/README +14 -1
  4. data/Rakefile +95 -42
  5. data/UPGRADE +31 -0
  6. data/bin/spec +0 -1
  7. data/bin/spec_translator +6 -0
  8. data/examples/auto_spec_description_example.rb +19 -0
  9. data/examples/{setup_teardown_example.rb → before_and_after_example.rb} +6 -6
  10. data/examples/behave_as_example.rb +45 -0
  11. data/examples/custom_expectation_matchers.rb +13 -12
  12. data/examples/dynamic_spec.rb +2 -2
  13. data/examples/file_accessor_spec.rb +2 -2
  14. data/examples/greeter_spec.rb +3 -3
  15. data/examples/helper_method_example.rb +2 -2
  16. data/examples/io_processor_spec.rb +4 -4
  17. data/examples/legacy_spec.rb +10 -0
  18. data/examples/mocking_example.rb +5 -5
  19. data/examples/multi_threaded_behaviour_runner.rb +25 -0
  20. data/examples/partial_mock_example.rb +4 -4
  21. data/examples/predicate_example.rb +4 -4
  22. data/examples/priority.txt +1 -0
  23. data/examples/shared_behaviours_example.rb +31 -0
  24. data/examples/stack_spec.rb +52 -69
  25. data/examples/stubbing_example.rb +10 -10
  26. data/examples/test_case_adapter_example.rb +26 -0
  27. data/examples/test_case_spec.rb +6 -6
  28. data/lib/spec.rb +9 -4
  29. data/lib/spec/dsl.rb +10 -0
  30. data/lib/spec/dsl/behaviour.rb +189 -0
  31. data/lib/spec/dsl/behaviour_callbacks.rb +43 -0
  32. data/lib/spec/dsl/behaviour_eval.rb +170 -0
  33. data/lib/spec/dsl/behaviour_factory.rb +32 -0
  34. data/lib/spec/dsl/composite_proc_builder.rb +28 -0
  35. data/lib/spec/dsl/configuration.rb +38 -0
  36. data/lib/spec/dsl/description.rb +34 -0
  37. data/lib/spec/dsl/example.rb +114 -0
  38. data/lib/spec/dsl/example_matcher.rb +28 -0
  39. data/lib/spec/{runner/spec_should_raise_handler.rb → dsl/example_should_raise_handler.rb} +4 -4
  40. data/lib/spec/expectations.rb +0 -3
  41. data/lib/spec/expectations/differs/default.rb +0 -1
  42. data/lib/spec/expectations/extensions.rb +0 -1
  43. data/lib/spec/expectations/extensions/object.rb +10 -53
  44. data/lib/spec/expectations/handler.rb +14 -18
  45. data/lib/spec/extensions.rb +1 -0
  46. data/lib/spec/extensions/object.rb +6 -0
  47. data/lib/spec/matchers.rb +19 -21
  48. data/lib/spec/matchers/be.rb +40 -11
  49. data/lib/spec/matchers/be_close.rb +2 -2
  50. data/lib/spec/matchers/operator_matcher.rb +52 -0
  51. data/lib/spec/matchers/respond_to.rb +21 -11
  52. data/lib/spec/mocks.rb +5 -28
  53. data/lib/spec/mocks/argument_constraint_matchers.rb +12 -0
  54. data/lib/spec/mocks/argument_expectation.rb +7 -4
  55. data/lib/spec/mocks/methods.rb +11 -16
  56. data/lib/spec/mocks/mock.rb +6 -3
  57. data/lib/spec/mocks/{mock_handler.rb → proxy.rb} +4 -7
  58. data/lib/spec/mocks/space.rb +28 -0
  59. data/lib/spec/mocks/spec_methods.rb +30 -0
  60. data/lib/spec/rake/spectask.rb +23 -21
  61. data/lib/spec/rake/verify_rcov.rb +1 -0
  62. data/lib/spec/runner.rb +88 -35
  63. data/lib/spec/runner/backtrace_tweaker.rb +2 -1
  64. data/lib/spec/runner/behaviour_runner.rb +102 -0
  65. data/lib/spec/runner/command_line.rb +5 -17
  66. data/lib/spec/runner/drb_command_line.rb +2 -2
  67. data/lib/spec/runner/extensions/kernel.rb +22 -9
  68. data/lib/spec/runner/formatter.rb +4 -0
  69. data/lib/spec/runner/formatter/base_formatter.rb +63 -0
  70. data/lib/spec/runner/formatter/base_text_formatter.rb +22 -52
  71. data/lib/spec/runner/formatter/failing_behaviours_formatter.rb +25 -0
  72. data/lib/spec/runner/formatter/failing_examples_formatter.rb +22 -0
  73. data/lib/spec/runner/formatter/html_formatter.rb +74 -29
  74. data/lib/spec/runner/formatter/progress_bar_formatter.rb +6 -8
  75. data/lib/spec/runner/formatter/rdoc_formatter.rb +6 -6
  76. data/lib/spec/runner/formatter/snippet_extractor.rb +52 -0
  77. data/lib/spec/runner/formatter/specdoc_formatter.rb +6 -6
  78. data/lib/spec/runner/heckle_runner.rb +8 -7
  79. data/lib/spec/runner/option_parser.rb +136 -55
  80. data/lib/spec/runner/options.rb +26 -0
  81. data/lib/spec/runner/reporter.rb +38 -31
  82. data/lib/spec/runner/spec_parser.rb +22 -13
  83. data/lib/spec/test_case_adapter.rb +10 -0
  84. data/lib/spec/translator.rb +103 -86
  85. data/lib/spec/version.rb +7 -15
  86. data/plugins/mock_frameworks/flexmock.rb +27 -0
  87. data/plugins/mock_frameworks/mocha.rb +21 -0
  88. data/plugins/mock_frameworks/rspec.rb +18 -0
  89. data/spec/spec/dsl/behaviour_eval_spec.rb +49 -0
  90. data/spec/spec/dsl/behaviour_factory_spec.rb +30 -0
  91. data/spec/spec/dsl/behaviour_spec.rb +508 -0
  92. data/spec/spec/dsl/composite_proc_builder_spec.rb +57 -0
  93. data/spec/spec/dsl/configuration_spec.rb +43 -0
  94. data/spec/spec/dsl/description_spec.rb +51 -0
  95. data/spec/spec/dsl/example_class_spec.rb +24 -0
  96. data/spec/spec/dsl/example_instance_spec.rb +140 -0
  97. data/spec/spec/dsl/example_should_raise_spec.rb +137 -0
  98. data/spec/spec/dsl/predicate_matcher_spec.rb +21 -0
  99. data/spec/spec/dsl/shared_behaviour_spec.rb +186 -0
  100. data/spec/spec/expectations/differs/default_spec.rb +12 -12
  101. data/spec/spec/expectations/extensions/object_spec.rb +10 -10
  102. data/spec/spec/expectations/fail_with_spec.rb +20 -20
  103. data/spec/spec/matchers/be_close_spec.rb +37 -31
  104. data/spec/spec/matchers/be_spec.rb +50 -41
  105. data/spec/spec/matchers/change_spec.rb +54 -54
  106. data/spec/spec/matchers/description_generation_spec.rb +43 -31
  107. data/spec/spec/matchers/eql_spec.rb +24 -37
  108. data/spec/spec/matchers/equal_spec.rb +24 -37
  109. data/spec/spec/matchers/exist_spec.rb +48 -0
  110. data/spec/spec/matchers/handler_spec.rb +36 -23
  111. data/spec/spec/matchers/has_spec.rb +8 -8
  112. data/spec/spec/matchers/have_spec.rb +38 -38
  113. data/spec/spec/matchers/include_spec.rb +6 -6
  114. data/spec/spec/matchers/match_spec.rb +8 -8
  115. data/spec/spec/matchers/matcher_methods_spec.rb +24 -31
  116. data/spec/spec/matchers/raise_error_spec.rb +34 -34
  117. data/spec/spec/matchers/respond_to_spec.rb +32 -8
  118. data/spec/spec/matchers/satisfy_spec.rb +6 -6
  119. data/spec/spec/matchers/should_===_spec.rb +38 -0
  120. data/spec/spec/matchers/should_==_spec.rb +37 -0
  121. data/spec/spec/matchers/should_=~_spec.rb +36 -0
  122. data/spec/spec/matchers/throw_symbol_spec.rb +47 -55
  123. data/spec/spec/mocks/any_number_of_times_spec.rb +16 -21
  124. data/spec/spec/mocks/argument_expectation_spec.rb +3 -3
  125. data/spec/spec/mocks/at_least_spec.rb +30 -30
  126. data/spec/spec/mocks/at_most_spec.rb +53 -57
  127. data/spec/spec/mocks/bug_report_10260_spec.rb +8 -0
  128. data/spec/spec/mocks/bug_report_7611_spec.rb +3 -3
  129. data/spec/spec/mocks/bug_report_7805_spec.rb +3 -3
  130. data/spec/spec/mocks/bug_report_8165_spec.rb +5 -5
  131. data/spec/spec/mocks/bug_report_8302_spec.rb +5 -5
  132. data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +26 -27
  133. data/spec/spec/mocks/mock_ordering_spec.rb +19 -15
  134. data/spec/spec/mocks/mock_space_spec.rb +54 -0
  135. data/spec/spec/mocks/mock_spec.rb +111 -141
  136. data/spec/spec/mocks/multiple_return_value_spec.rb +48 -48
  137. data/spec/spec/mocks/null_object_mock_spec.rb +10 -10
  138. data/spec/spec/mocks/once_counts_spec.rb +32 -35
  139. data/spec/spec/mocks/options_hash_spec.rb +12 -10
  140. data/spec/spec/mocks/partial_mock_spec.rb +15 -15
  141. data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +24 -22
  142. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +19 -19
  143. data/spec/spec/mocks/precise_counts_spec.rb +28 -32
  144. data/spec/spec/mocks/record_messages_spec.rb +10 -10
  145. data/spec/spec/mocks/stub_spec.rb +45 -45
  146. data/spec/spec/mocks/twice_counts_spec.rb +21 -21
  147. data/spec/spec/package/bin_spec_spec.rb +12 -0
  148. data/spec/spec/runner/behaviour_runner_spec.rb +114 -0
  149. data/spec/spec/runner/command_line_spec.rb +8 -8
  150. data/spec/spec/runner/context_matching_spec.rb +14 -15
  151. data/spec/spec/runner/drb_command_line_spec.rb +12 -12
  152. data/spec/spec/runner/execution_context_spec.rb +8 -29
  153. data/spec/spec/runner/extensions/kernel_spec.rb +36 -0
  154. data/spec/spec/runner/formatter/failing_behaviours_formatter_spec.rb +27 -0
  155. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +28 -0
  156. data/spec/spec/runner/formatter/html_formatter_spec.rb +9 -8
  157. data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +6 -6
  158. data/spec/spec/runner/formatter/progress_bar_formatter_failure_dump_spec.rb +10 -10
  159. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +22 -27
  160. data/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb +6 -5
  161. data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +17 -17
  162. data/spec/spec/runner/formatter/snippet_extractor_spec.rb +11 -0
  163. data/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb +6 -6
  164. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +17 -17
  165. data/spec/spec/runner/heckle_runner_spec.rb +21 -21
  166. data/spec/spec/runner/heckler_spec.rb +5 -5
  167. data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +12 -12
  168. data/spec/spec/runner/object_ext_spec.rb +3 -3
  169. data/spec/spec/runner/option_parser_spec.rb +171 -102
  170. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +21 -12
  171. data/spec/spec/runner/reporter_spec.rb +106 -97
  172. data/spec/spec/runner/spec_matcher_spec.rb +46 -51
  173. data/spec/spec/runner/spec_parser_spec.rb +72 -16
  174. data/spec/spec/spec_classes.rb +12 -3
  175. data/spec/spec/translator_spec.rb +165 -36
  176. metadata +66 -76
  177. data/RELEASE-PLAN +0 -117
  178. data/examples/auto_spec_name_generation_example.rb +0 -18
  179. data/lib/spec/callback.rb +0 -11
  180. data/lib/spec/callback/callback_container.rb +0 -60
  181. data/lib/spec/callback/extensions/module.rb +0 -24
  182. data/lib/spec/callback/extensions/object.rb +0 -37
  183. data/lib/spec/deprecated.rb +0 -3
  184. data/lib/spec/expectations/extensions/proc.rb +0 -57
  185. data/lib/spec/expectations/should.rb +0 -5
  186. data/lib/spec/expectations/should/base.rb +0 -64
  187. data/lib/spec/expectations/should/change.rb +0 -69
  188. data/lib/spec/expectations/should/have.rb +0 -128
  189. data/lib/spec/expectations/should/not.rb +0 -74
  190. data/lib/spec/expectations/should/should.rb +0 -81
  191. data/lib/spec/expectations/sugar.rb +0 -47
  192. data/lib/spec/runner/context.rb +0 -154
  193. data/lib/spec/runner/context_eval.rb +0 -142
  194. data/lib/spec/runner/context_runner.rb +0 -55
  195. data/lib/spec/runner/execution_context.rb +0 -17
  196. data/lib/spec/runner/spec_matcher.rb +0 -25
  197. data/lib/spec/runner/specification.rb +0 -114
  198. data/spec/spec/callback/callback_container_spec.rb +0 -27
  199. data/spec/spec/callback/module_spec.rb +0 -37
  200. data/spec/spec/callback/object_spec.rb +0 -90
  201. data/spec/spec/callback/object_with_class_callback_spec.rb +0 -19
  202. data/spec/spec/expectations/should/should_==_spec.rb +0 -19
  203. data/spec/spec/expectations/should/should_=~_spec.rb +0 -13
  204. data/spec/spec/expectations/should/should_be_a_kind_of_spec.rb +0 -21
  205. data/spec/spec/expectations/should/should_be_an_instance_of_spec.rb +0 -30
  206. data/spec/spec/expectations/should/should_be_arbitrary_predicate_spec.rb +0 -81
  207. data/spec/spec/expectations/should/should_be_close_spec.rb +0 -18
  208. data/spec/spec/expectations/should/should_be_comparison_operator_spec.rb +0 -44
  209. data/spec/spec/expectations/should/should_be_false_spec.rb +0 -39
  210. data/spec/spec/expectations/should/should_be_spec.rb +0 -11
  211. data/spec/spec/expectations/should/should_be_true_spec.rb +0 -27
  212. data/spec/spec/expectations/should/should_change_spec.rb +0 -184
  213. data/spec/spec/expectations/should/should_eql_spec.rb +0 -11
  214. data/spec/spec/expectations/should/should_equal_spec.rb +0 -11
  215. data/spec/spec/expectations/should/should_have_at_least_spec.rb +0 -53
  216. data/spec/spec/expectations/should/should_have_at_most_spec.rb +0 -45
  217. data/spec/spec/expectations/should/should_have_key_spec.rb +0 -21
  218. data/spec/spec/expectations/should/should_have_spec.rb +0 -64
  219. data/spec/spec/expectations/should/should_include_spec.rb +0 -59
  220. data/spec/spec/expectations/should/should_match_spec.rb +0 -25
  221. data/spec/spec/expectations/should/should_not_==_spec.rb +0 -15
  222. data/spec/spec/expectations/should/should_not_be_a_kind_of_spec.rb +0 -21
  223. data/spec/spec/expectations/should/should_not_be_an_instance_of_spec.rb +0 -11
  224. data/spec/spec/expectations/should/should_not_be_arbitrary_predicate_spec.rb +0 -68
  225. data/spec/spec/expectations/should/should_not_be_spec.rb +0 -11
  226. data/spec/spec/expectations/should/should_not_change_spec.rb +0 -24
  227. data/spec/spec/expectations/should/should_not_eql_spec.rb +0 -11
  228. data/spec/spec/expectations/should/should_not_equal_spec.rb +0 -11
  229. data/spec/spec/expectations/should/should_not_have_key_spec.rb +0 -15
  230. data/spec/spec/expectations/should/should_not_include_spec.rb +0 -58
  231. data/spec/spec/expectations/should/should_not_match_spec.rb +0 -11
  232. data/spec/spec/expectations/should/should_not_raise_spec.rb +0 -75
  233. data/spec/spec/expectations/should/should_not_respond_to_spec.rb +0 -15
  234. data/spec/spec/expectations/should/should_not_throw_spec.rb +0 -35
  235. data/spec/spec/expectations/should/should_raise_spec.rb +0 -66
  236. data/spec/spec/expectations/should/should_respond_to_spec.rb +0 -15
  237. data/spec/spec/expectations/should/should_satisfy_spec.rb +0 -35
  238. data/spec/spec/expectations/should/should_throw_spec.rb +0 -27
  239. data/spec/spec/runner/context_runner_spec.rb +0 -100
  240. data/spec/spec/runner/context_spec.rb +0 -405
  241. data/spec/spec/runner/kernel_ext_spec.rb +0 -16
  242. data/spec/spec/runner/spec_name_generation_spec.rb +0 -102
  243. data/spec/spec/runner/specification_class_spec.rb +0 -72
  244. data/spec/spec/runner/specification_instance_spec.rb +0 -160
  245. data/spec/spec/runner/specification_should_raise_spec.rb +0 -136
@@ -2,340 +2,310 @@ require File.dirname(__FILE__) + '/../../spec_helper'
2
2
 
3
3
  module Spec
4
4
  module Mocks
5
- context "a Mock expectation" do
5
+ describe "a Mock expectation" do
6
6
 
7
- setup do
8
- @mock = Mock.new("test mock", :auto_verify => false)
7
+ before do
8
+ @mock = mock("test mock")
9
9
  end
10
10
 
11
- specify "should report line number of expectation of unreceived message" do
11
+ after do
12
+ @mock.rspec_reset
13
+ end
14
+
15
+ it "should report line number of expectation of unreceived message" do
12
16
  @mock.should_receive(:wont_happen).with("x", 3)
13
17
  #NOTE - this test is quite ticklish because it specifies that
14
18
  #the above statement appears on line 12 of this file.
15
19
 
16
20
  begin
17
- @mock.__verify
21
+ @mock.rspec_verify
18
22
  violated
19
23
  rescue MockExpectationError => e
20
- e.backtrace[0].should_match(/mock_spec\.rb:12/)
24
+ e.backtrace[0].should match(/mock_spec\.rb:16/)
21
25
  end
22
26
 
23
27
  end
24
28
 
25
- specify "should pass when not receiving message specified as not to be received" do
29
+ it "should pass when not receiving message specified as not to be received" do
26
30
  @mock.should_not_receive(:not_expected)
27
- @mock.__verify
31
+ @mock.rspec_verify
28
32
  end
29
33
 
30
- specify "should pass when receiving message specified as not to be received with different args" do
34
+ it "should pass when receiving message specified as not to be received with different args" do
31
35
  @mock.should_not_receive(:message).with("unwanted text")
32
36
  @mock.should_receive(:message).with("other text")
33
37
  @mock.message "other text"
34
- @mock.__verify
38
+ @mock.rspec_verify
35
39
  end
36
40
 
37
- specify "should fail when receiving message specified as not to be received" do
41
+ it "should fail when receiving message specified as not to be received" do
38
42
  @mock.should_not_receive(:not_expected)
39
43
  @mock.not_expected
40
44
  begin
41
- @mock.__verify
45
+ @mock.rspec_verify
42
46
  violated
43
47
  rescue MockExpectationError => e
44
- e.message.should_eql "Mock 'test mock' expected :not_expected with (any args) 0 times, but received it once"
48
+ e.message.should == "Mock 'test mock' expected :not_expected with (any args) 0 times, but received it once"
45
49
  end
46
50
  end
47
51
 
48
- specify "should fail when receiving message specified as not to be received with args" do
52
+ it "should fail when receiving message specified as not to be received with args" do
49
53
  @mock.should_not_receive(:not_expected).with("unexpected text")
50
54
  @mock.not_expected("unexpected text")
51
55
  begin
52
- @mock.__verify
56
+ @mock.rspec_verify
53
57
  violated
54
58
  rescue MockExpectationError => e
55
- e.message.should_eql "Mock 'test mock' expected :not_expected with (\"unexpected text\") 0 times, but received it once"
59
+ e.message.should == "Mock 'test mock' expected :not_expected with (\"unexpected text\") 0 times, but received it once"
56
60
  end
57
61
  end
58
62
 
59
- specify "should pass when receiving message specified as not to be received with wrong args" do
63
+ it "should pass when receiving message specified as not to be received with wrong args" do
60
64
  @mock.should_not_receive(:not_expected).with("unexpected text")
61
65
  @mock.not_expected "really unexpected text"
62
- @mock.__verify
66
+ @mock.rspec_verify
63
67
  end
64
68
 
65
- specify "should allow block to calculate return values" do
69
+ it "should allow block to calculate return values" do
66
70
  @mock.should_receive(:something).with("a","b","c").and_return { |a,b,c| c+b+a }
67
- @mock.something("a","b","c").should_eql "cba"
68
- @mock.__verify
71
+ @mock.something("a","b","c").should == "cba"
72
+ @mock.rspec_verify
69
73
  end
70
74
 
71
- specify "should allow parameter as return value" do
75
+ it "should allow parameter as return value" do
72
76
  @mock.should_receive(:something).with("a","b","c").and_return("booh")
73
- @mock.something("a","b","c").should_eql "booh"
74
- @mock.__verify
77
+ @mock.something("a","b","c").should == "booh"
78
+ @mock.rspec_verify
75
79
  end
76
80
 
77
- specify "should return nil if no return value set" do
81
+ it "should return nil if no return value set" do
78
82
  @mock.should_receive(:something).with("a","b","c")
79
- @mock.something("a","b","c").should be(nil)
80
- @mock.__verify
83
+ @mock.something("a","b","c").should be_nil
84
+ @mock.rspec_verify
81
85
  end
82
86
 
83
- specify "should raise exception if args dont match when method called" do
87
+ it "should raise exception if args dont match when method called" do
84
88
  @mock.should_receive(:something).with("a","b","c").and_return("booh")
85
89
  begin
86
90
  @mock.something("a","d","c")
87
91
  violated
88
92
  rescue MockExpectationError => e
89
- e.message.should_eql "Mock 'test mock' expected :something with (\"a\", \"b\", \"c\") but received it with (\"a\", \"d\", \"c\")"
93
+ e.message.should == "Mock 'test mock' expected :something with (\"a\", \"b\", \"c\") but received it with (\"a\", \"d\", \"c\")"
90
94
  end
91
95
  end
92
96
 
93
- specify "should fail if unexpected method called" do
97
+ it "should fail if unexpected method called" do
94
98
  begin
95
99
  @mock.something("a","b","c")
96
100
  violated
97
101
  rescue MockExpectationError => e
98
- e.message.should_eql "Mock 'test mock' received unexpected message :something with (\"a\", \"b\", \"c\")"
102
+ e.message.should == "Mock 'test mock' received unexpected message :something with (\"a\", \"b\", \"c\")"
99
103
  end
100
104
  end
101
105
 
102
- specify "should use block for expectation if provided" do
106
+ it "should use block for expectation if provided" do
103
107
  @mock.should_receive(:something) do | a, b |
104
- a.should_eql "a"
105
- b.should_eql "b"
108
+ a.should == "a"
109
+ b.should == "b"
106
110
  "booh"
107
111
  end
108
- @mock.something("a", "b").should_eql "booh"
109
- @mock.__verify
112
+ @mock.something("a", "b").should == "booh"
113
+ @mock.rspec_verify
110
114
  end
111
115
 
112
- specify "should fail if expectation block fails" do
113
- @mock.should_receive(:something) {| bool | bool.should be(true)}
116
+ it "should fail if expectation block fails" do
117
+ @mock.should_receive(:something) {| bool | bool.should be_true}
114
118
  begin
115
119
  @mock.something false
116
120
  rescue MockExpectationError => e
117
- e.message.should_match /Mock 'test mock' received :something but passed block failed with: expected true, got false/
121
+ e.message.should match(/Mock 'test mock' received :something but passed block failed with: expected true, got false/)
118
122
  end
119
123
  end
120
124
 
121
- specify "should fail when method defined as never is received" do
125
+ it "should fail when method defined as never is received" do
122
126
  @mock.should_receive(:not_expected).never
123
127
  begin
124
128
  @mock.not_expected
125
129
  rescue MockExpectationError => e
126
- e.message.should_eql "Mock 'test mock' expected :not_expected 0 times, but received it 1 times"
130
+ e.message.should == "Mock 'test mock' expected :not_expected 0 times, but received it 1 times"
127
131
  end
128
132
  end
129
133
 
130
- specify "should raise when told to" do
134
+ it "should raise when told to" do
131
135
  @mock.should_receive(:something).and_raise(RuntimeError)
132
136
  lambda do
133
137
  @mock.something
134
- end.should_raise(RuntimeError)
138
+ end.should raise_error(RuntimeError)
135
139
  end
136
140
 
137
- specify "should raise passed an Exception instance" do
141
+ it "should raise passed an Exception instance" do
138
142
  error = RuntimeError.new("error message")
139
143
  @mock.should_receive(:something).and_raise(error)
140
144
  begin
141
145
  @mock.something
142
146
  rescue RuntimeError => e
143
- e.message.should_eql("error message")
147
+ e.message.should eql("error message")
144
148
  end
145
149
  end
146
150
 
147
- specify "should raise RuntimeError with passed message" do
151
+ it "should raise RuntimeError with passed message" do
148
152
  @mock.should_receive(:something).and_raise("error message")
149
153
  begin
150
154
  @mock.something
151
155
  rescue RuntimeError => e
152
- e.message.should_eql("error message")
156
+ e.message.should eql("error message")
153
157
  end
154
158
  end
155
159
 
156
- specify "should not raise when told to if args dont match" do
160
+ it "should not raise when told to if args dont match" do
157
161
  @mock.should_receive(:something).with(2).and_raise(RuntimeError)
158
162
  lambda do
159
163
  @mock.something 1
160
- end.should_raise(MockExpectationError)
164
+ end.should raise_error(MockExpectationError)
161
165
  end
162
166
 
163
- specify "should throw when told to" do
167
+ it "should throw when told to" do
164
168
  @mock.should_receive(:something).and_throw(:blech)
165
169
  lambda do
166
170
  @mock.something
167
- end.should_throw(:blech)
171
+ end.should throw_symbol(:blech)
168
172
  end
169
173
 
170
- specify "should raise when explicit return and block constrained" do
174
+ it "should raise when explicit return and block constrained" do
171
175
  lambda do
172
176
  @mock.should_receive(:fruit) do |colour|
173
177
  :strawberry
174
178
  end.and_return :apple
175
- end.should_raise(AmbiguousReturnError)
179
+ end.should raise_error(AmbiguousReturnError)
176
180
  end
177
181
 
178
- specify "should ignore args on any args" do
182
+ it "should ignore args on any args" do
179
183
  @mock.should_receive(:something).at_least(:once).with(:any_args)
180
184
  @mock.something
181
185
  @mock.something 1
182
186
  @mock.something "a", 2
183
187
  @mock.something [], {}, "joe", 7
184
- @mock.__verify
188
+ @mock.rspec_verify
185
189
  end
186
190
 
187
- specify "should fail on no args if any args received" do
191
+ it "should fail on no args if any args received" do
188
192
  @mock.should_receive(:something).with(:no_args)
189
193
  begin
190
194
  @mock.something 1
191
195
  rescue MockExpectationError => e
192
- e.message.should_eql "Mock 'test mock' expected :something with (no args) but received it with (1)"
196
+ e.message.should == "Mock 'test mock' expected :something with (no args) but received it with (1)"
193
197
  end
194
198
  end
195
199
 
196
- specify "should fail when args are expected but none are received" do
200
+ it "should fail when args are expected but none are received" do
197
201
  @mock.should_receive(:something).with(1)
198
202
  begin
199
203
  @mock.something
200
204
  rescue MockExpectationError => e
201
- e.message.should_eql "Mock 'test mock' expected :something with (1) but received it with (no args)"
205
+ e.message.should == "Mock 'test mock' expected :something with (1) but received it with (no args)"
202
206
  end
203
207
  end
204
208
 
205
- specify "should yield 0 args to blocks that take a variable number of arguments" do
209
+ it "should yield 0 args to blocks that take a variable number of arguments" do
206
210
  @mock.should_receive(:yield_back).with(:no_args).once.and_yield
207
211
  a = nil
208
212
  @mock.yield_back {|*a|}
209
- a.should_eql []
210
- @mock.__verify
213
+ a.should == []
214
+ @mock.rspec_verify
211
215
  end
212
216
 
213
- specify "should yield one arg to blocks that take a variable number of arguments" do
217
+ it "should yield one arg to blocks that take a variable number of arguments" do
214
218
  @mock.should_receive(:yield_back).with(:no_args).once.and_yield(99)
215
219
  a = nil
216
220
  @mock.yield_back {|*a|}
217
- a.should_eql [99]
218
- @mock.__verify
221
+ a.should == [99]
222
+ @mock.rspec_verify
219
223
  end
220
224
 
221
- specify "should yield many args to blocks that take a variable number of arguments" do
225
+ it "should yield many args to blocks that take a variable number of arguments" do
222
226
  @mock.should_receive(:yield_back).with(:no_args).once.and_yield(99, 27, "go")
223
227
  a = nil
224
228
  @mock.yield_back {|*a|}
225
- a.should_eql [99, 27, "go"]
226
- @mock.__verify
229
+ a.should == [99, 27, "go"]
230
+ @mock.rspec_verify
227
231
  end
228
232
 
229
- specify "should yield single value" do
233
+ it "should yield single value" do
230
234
  @mock.should_receive(:yield_back).with(:no_args).once.and_yield(99)
231
235
  a = nil
232
236
  @mock.yield_back {|a|}
233
- a.should_eql 99
234
- @mock.__verify
237
+ a.should == 99
238
+ @mock.rspec_verify
235
239
  end
236
240
 
237
- specify "should yield two values" do
241
+ it "should yield two values" do
238
242
  @mock.should_receive(:yield_back).with(:no_args).once.and_yield('wha', 'zup')
239
243
  a, b = nil
240
244
  @mock.yield_back {|a,b|}
241
- a.should_eql 'wha'
242
- b.should_eql 'zup'
243
- @mock.__verify
245
+ a.should == 'wha'
246
+ b.should == 'zup'
247
+ @mock.rspec_verify
244
248
  end
245
249
 
246
- specify "should fail when calling yielding method with wrong arity" do
250
+ it "should fail when calling yielding method with wrong arity" do
247
251
  @mock.should_receive(:yield_back).with(:no_args).once.and_yield('wha', 'zup')
248
252
  begin
249
253
  @mock.yield_back {|a|}
250
254
  rescue MockExpectationError => e
251
- e.message.should_eql "Mock 'test mock' yielded |\"wha\", \"zup\"| to block with arity of 1"
255
+ e.message.should == "Mock 'test mock' yielded |\"wha\", \"zup\"| to block with arity of 1"
252
256
  end
253
257
  end
254
258
 
255
- specify "should fail when calling yielding method without block" do
259
+ it "should fail when calling yielding method without block" do
256
260
  @mock.should_receive(:yield_back).with(:no_args).once.and_yield('wha', 'zup')
257
261
  begin
258
262
  @mock.yield_back
259
263
  rescue MockExpectationError => e
260
- e.message.should_eql "Mock 'test mock' asked to yield |\"wha\", \"zup\"| but no block was passed"
264
+ e.message.should == "Mock 'test mock' asked to yield |\"wha\", \"zup\"| but no block was passed"
261
265
  end
262
266
  end
263
267
 
264
- specify "should be able to mock send" do
268
+ it "should be able to mock send" do
265
269
  @mock.should_receive(:send).with(:any_args)
266
270
  @mock.send 'hi'
267
- @mock.__verify
271
+ @mock.rspec_verify
268
272
  end
269
273
 
270
- specify "should be able to raise from method calling yielding mock" do
274
+ it "should be able to raise from method calling yielding mock" do
271
275
  @mock.should_receive(:yield_me).and_yield 44
272
276
 
273
277
  lambda do
274
278
  @mock.yield_me do |x|
275
279
  raise "Bang"
276
280
  end
277
- end.should_raise(StandardError)
278
-
279
- @mock.__verify
280
- end
281
+ end.should raise_error(StandardError)
281
282
 
282
- specify "should clear expectations after verify" do
283
- @mock.should_receive(:foobar)
284
- @mock.foobar
285
- @mock.__verify
286
- begin
287
- @mock.foobar
288
- rescue MockExpectationError => e
289
- e.message.should_eql "Mock 'test mock' received unexpected message :foobar with (no args)"
290
- end
283
+ @mock.rspec_verify
291
284
  end
292
285
 
293
- specify "should verify if auto verify is set to true" do
294
- reporter = Spec::Mocks::Mock.new("reporter", :null_object => true)
295
- reporter.should_receive(:spec_finished) do |name, error, location|
296
- error.to_s.should_match /expected :abcde with \(any args\) once, but received it 0 times/
297
- end
298
- Runner::Specification.new("spec") do
299
- mock = Spec::Mocks::Mock.new("mock", :auto_verify => true)
300
- mock.should_receive(:abcde)
301
- end.run(reporter, nil, nil, nil, nil)
302
- reporter.__verify
303
- end
304
-
305
- specify "should verify if auto verify not set explicitly" do
306
- reporter = Spec::Mocks::Mock.new("reporter", :null_object => true)
307
- reporter.should_receive(:spec_finished) do |name, error, location|
308
- error.to_s.should_match /expected :abcde with \(any args\) once, but received it 0 times/
309
- end
310
- Runner::Specification.new("spec") do
311
- mock = Spec::Mocks::Mock.new("mock")
312
- mock.should_receive(:abcde)
313
- end.run(reporter, nil, nil, nil, nil)
314
- reporter.__verify
315
- end
316
-
317
- specify "should not verify if auto verify is set to false" do
318
- reporter = Spec::Mocks::Mock.new("reporter", :null_object => true)
319
- reporter.should_receive(:spec_finished) do |name, error, location|
320
- error.should_be_nil
321
- end
322
- Runner::Specification.new("spec") do
323
- mock = Spec::Mocks::Mock.new("mock", :auto_verify => false)
324
- mock.should_receive(:abcde)
325
- end.run(reporter, nil, nil, nil, nil)
326
- reporter.__verify
327
- end
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
328
297
 
329
- specify "should reset on __reset_mock_methods" do
298
+ it "should restore objects to their original state on rspec_reset" do
330
299
  mock = mock("this is a mock")
331
300
  mock.should_receive(:blah)
332
- mock.__reset_mock
301
+ mock.rspec_reset
302
+ mock.rspec_verify #should throw if reset didn't work
333
303
  end
334
304
 
335
305
  end
336
306
 
337
- context "a mock message receiving a block" do
338
- setup do
307
+ describe "a mock message receiving a block" do
308
+ before(:each) do
339
309
  @mock = mock("mock")
340
310
  @calls = 0
341
311
  end
@@ -344,7 +314,7 @@ module Spec
344
314
  @calls = @calls + 1
345
315
  end
346
316
 
347
- specify "should call the block after #should_receive" do
317
+ it "should call the block after #should_receive" do
348
318
  @mock.should_receive(:foo) { add_call }
349
319
 
350
320
  @mock.foo
@@ -352,7 +322,7 @@ module Spec
352
322
  @calls.should == 1
353
323
  end
354
324
 
355
- specify "should call the block after #once" do
325
+ it "should call the block after #once" do
356
326
  @mock.should_receive(:foo).once { add_call }
357
327
 
358
328
  @mock.foo
@@ -360,7 +330,7 @@ module Spec
360
330
  @calls.should == 1
361
331
  end
362
332
 
363
- specify "should call the block after #twice" do
333
+ it "should call the block after #twice" do
364
334
  @mock.should_receive(:foo).twice { add_call }
365
335
 
366
336
  @mock.foo
@@ -369,7 +339,7 @@ module Spec
369
339
  @calls.should == 2
370
340
  end
371
341
 
372
- specify "should call the block after #times" do
342
+ it "should call the block after #times" do
373
343
  @mock.should_receive(:foo).exactly(10).times { add_call }
374
344
 
375
345
  (1..10).each { @mock.foo }
@@ -377,7 +347,7 @@ module Spec
377
347
  @calls.should == 10
378
348
  end
379
349
 
380
- specify "should call the block after #any_number_of_times" do
350
+ it "should call the block after #any_number_of_times" do
381
351
  @mock.should_receive(:foo).any_number_of_times { add_call }
382
352
 
383
353
  (1..7).each { @mock.foo }
@@ -385,7 +355,7 @@ module Spec
385
355
  @calls.should == 7
386
356
  end
387
357
 
388
- specify "should call the block after #with" do
358
+ it "should call the block after #with" do
389
359
  @mock.should_receive(:foo).with(:arg) { add_call }
390
360
 
391
361
  @mock.foo(:arg)
@@ -393,7 +363,7 @@ module Spec
393
363
  @calls.should == 1
394
364
  end
395
365
 
396
- specify "should call the block after #ordered" do
366
+ it "should call the block after #ordered" do
397
367
  @mock.should_receive(:foo).ordered { add_call }
398
368
  @mock.should_receive(:bar).ordered { add_call }
399
369