rspec 0.7.5.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. data/CHANGES +60 -1
  2. data/EXAMPLES.rd +38 -19
  3. data/MIT-LICENSE +1 -1
  4. data/README +24 -17
  5. data/RELEASE-PLAN +117 -0
  6. data/Rakefile +24 -18
  7. data/TODO.0.8.0 +5 -0
  8. data/examples/auto_spec_name_generation_example.rb +18 -0
  9. data/examples/custom_expectation_matchers.rb +53 -0
  10. data/examples/dynamic_spec.rb +9 -0
  11. data/examples/io_processor_spec.rb +2 -2
  12. data/examples/mocking_example.rb +4 -4
  13. data/examples/partial_mock_example.rb +2 -2
  14. data/examples/predicate_example.rb +2 -2
  15. data/examples/stack_spec.rb +32 -36
  16. data/examples/stubbing_example.rb +19 -19
  17. data/examples/test_case_spec.rb +6 -6
  18. data/lib/spec.rb +3 -0
  19. data/lib/spec/callback.rb +8 -0
  20. data/lib/spec/callback/extensions/object.rb +4 -0
  21. data/lib/spec/deprecated.rb +3 -0
  22. data/lib/spec/expectations.rb +44 -17
  23. data/lib/spec/expectations/extensions.rb +1 -2
  24. data/lib/spec/expectations/extensions/object.rb +78 -130
  25. data/lib/spec/expectations/extensions/string_and_symbol.rb +17 -0
  26. data/lib/spec/expectations/handler.rb +47 -0
  27. data/lib/spec/expectations/should/base.rb +32 -29
  28. data/lib/spec/expectations/should/change.rb +1 -1
  29. data/lib/spec/expectations/should/have.rb +9 -17
  30. data/lib/spec/expectations/should/not.rb +54 -56
  31. data/lib/spec/expectations/should/should.rb +59 -65
  32. data/lib/spec/expectations/sugar.rb +27 -4
  33. data/lib/spec/matchers.rb +160 -0
  34. data/lib/spec/matchers/be.rb +161 -0
  35. data/lib/spec/matchers/be_close.rb +37 -0
  36. data/lib/spec/matchers/change.rb +120 -0
  37. data/lib/spec/matchers/eql.rb +43 -0
  38. data/lib/spec/matchers/equal.rb +43 -0
  39. data/lib/spec/matchers/has.rb +44 -0
  40. data/lib/spec/matchers/have.rb +140 -0
  41. data/lib/spec/matchers/include.rb +50 -0
  42. data/lib/spec/matchers/match.rb +41 -0
  43. data/lib/spec/matchers/raise_error.rb +100 -0
  44. data/lib/spec/matchers/respond_to.rb +35 -0
  45. data/lib/spec/matchers/satisfy.rb +47 -0
  46. data/lib/spec/matchers/throw_symbol.rb +75 -0
  47. data/lib/spec/mocks.rb +224 -1
  48. data/lib/spec/mocks/argument_expectation.rb +16 -2
  49. data/lib/spec/mocks/error_generator.rb +5 -3
  50. data/lib/spec/mocks/errors.rb +2 -2
  51. data/lib/spec/mocks/extensions/object.rb +1 -1
  52. data/lib/spec/mocks/message_expectation.rb +29 -19
  53. data/lib/spec/mocks/{mock_methods.rb → methods.rb} +5 -5
  54. data/lib/spec/mocks/mock.rb +2 -2
  55. data/lib/spec/mocks/mock_handler.rb +81 -68
  56. data/lib/spec/rake/spectask.rb +7 -12
  57. data/lib/spec/rake/verify_rcov.rb +1 -1
  58. data/lib/spec/runner.rb +117 -0
  59. data/lib/spec/runner/command_line.rb +8 -5
  60. data/lib/spec/runner/context.rb +13 -37
  61. data/lib/spec/runner/context_eval.rb +4 -3
  62. data/lib/spec/runner/context_runner.rb +7 -4
  63. data/lib/spec/runner/drb_command_line.rb +1 -1
  64. data/lib/spec/runner/execution_context.rb +3 -11
  65. data/lib/spec/runner/extensions/kernel.rb +7 -5
  66. data/lib/spec/runner/extensions/object.rb +4 -1
  67. data/lib/spec/runner/formatter/base_text_formatter.rb +11 -3
  68. data/lib/spec/runner/formatter/html_formatter.rb +21 -10
  69. data/lib/spec/runner/heckle_runner.rb +24 -8
  70. data/lib/spec/runner/heckle_runner_win.rb +10 -0
  71. data/lib/spec/runner/option_parser.rb +58 -13
  72. data/lib/spec/runner/spec_matcher.rb +22 -29
  73. data/lib/spec/runner/spec_parser.rb +1 -0
  74. data/lib/spec/runner/specification.rb +36 -22
  75. data/lib/spec/translator.rb +87 -0
  76. data/lib/spec/version.rb +16 -7
  77. data/spec/spec/callback/callback_container_spec.rb +27 -0
  78. data/spec/spec/callback/module_spec.rb +37 -0
  79. data/spec/spec/callback/object_spec.rb +90 -0
  80. data/spec/spec/callback/object_with_class_callback_spec.rb +19 -0
  81. data/spec/spec/expectations/differs/default_spec.rb +107 -0
  82. data/spec/spec/expectations/extensions/object_spec.rb +46 -0
  83. data/spec/spec/expectations/fail_with_spec.rb +71 -0
  84. data/spec/spec/expectations/should/should_==_spec.rb +19 -0
  85. data/spec/spec/expectations/should/should_=~_spec.rb +13 -0
  86. data/spec/spec/expectations/should/should_be_a_kind_of_spec.rb +21 -0
  87. data/spec/spec/expectations/should/should_be_an_instance_of_spec.rb +30 -0
  88. data/spec/spec/expectations/should/should_be_arbitrary_predicate_spec.rb +81 -0
  89. data/spec/spec/expectations/should/should_be_close_spec.rb +18 -0
  90. data/spec/spec/expectations/should/should_be_comparison_operator_spec.rb +44 -0
  91. data/spec/spec/expectations/should/should_be_false_spec.rb +39 -0
  92. data/spec/spec/expectations/should/should_be_spec.rb +11 -0
  93. data/spec/spec/expectations/should/should_be_true_spec.rb +27 -0
  94. data/spec/spec/expectations/should/should_change_spec.rb +184 -0
  95. data/spec/spec/expectations/should/should_eql_spec.rb +11 -0
  96. data/spec/spec/expectations/should/should_equal_spec.rb +11 -0
  97. data/spec/spec/expectations/should/should_have_at_least_spec.rb +53 -0
  98. data/spec/spec/expectations/should/should_have_at_most_spec.rb +45 -0
  99. data/spec/spec/expectations/should/should_have_key_spec.rb +21 -0
  100. data/spec/spec/expectations/should/should_have_spec.rb +64 -0
  101. data/spec/spec/expectations/should/should_include_spec.rb +59 -0
  102. data/spec/spec/expectations/should/should_match_spec.rb +25 -0
  103. data/spec/spec/expectations/should/should_not_==_spec.rb +15 -0
  104. data/spec/spec/expectations/should/should_not_be_a_kind_of_spec.rb +21 -0
  105. data/spec/spec/expectations/should/should_not_be_an_instance_of_spec.rb +11 -0
  106. data/spec/spec/expectations/should/should_not_be_arbitrary_predicate_spec.rb +68 -0
  107. data/spec/spec/expectations/should/should_not_be_spec.rb +11 -0
  108. data/spec/spec/expectations/should/should_not_change_spec.rb +24 -0
  109. data/spec/spec/expectations/should/should_not_eql_spec.rb +11 -0
  110. data/spec/spec/expectations/should/should_not_equal_spec.rb +11 -0
  111. data/spec/spec/expectations/should/should_not_have_key_spec.rb +15 -0
  112. data/spec/spec/expectations/should/should_not_include_spec.rb +58 -0
  113. data/spec/spec/expectations/should/should_not_match_spec.rb +11 -0
  114. data/spec/spec/expectations/should/should_not_raise_spec.rb +75 -0
  115. data/spec/spec/expectations/should/should_not_respond_to_spec.rb +15 -0
  116. data/spec/spec/expectations/should/should_not_throw_spec.rb +35 -0
  117. data/spec/spec/expectations/should/should_raise_spec.rb +66 -0
  118. data/spec/spec/expectations/should/should_respond_to_spec.rb +15 -0
  119. data/spec/spec/expectations/should/should_satisfy_spec.rb +35 -0
  120. data/spec/spec/expectations/should/should_throw_spec.rb +27 -0
  121. data/spec/spec/matchers/be_close_spec.rb +33 -0
  122. data/spec/spec/matchers/be_spec.rb +182 -0
  123. data/spec/spec/matchers/change_spec.rb +232 -0
  124. data/spec/spec/matchers/description_generation_spec.rb +147 -0
  125. data/spec/spec/matchers/eql_spec.rb +41 -0
  126. data/spec/spec/matchers/equal_spec.rb +41 -0
  127. data/spec/spec/matchers/handler_spec.rb +75 -0
  128. data/spec/spec/matchers/has_spec.rb +37 -0
  129. data/spec/spec/matchers/have_spec.rb +259 -0
  130. data/spec/spec/matchers/include_spec.rb +33 -0
  131. data/spec/spec/matchers/match_spec.rb +37 -0
  132. data/spec/spec/matchers/matcher_methods_spec.rb +85 -0
  133. data/spec/spec/matchers/raise_error_spec.rb +147 -0
  134. data/spec/spec/matchers/respond_to_spec.rb +30 -0
  135. data/spec/spec/matchers/satisfy_spec.rb +36 -0
  136. data/spec/spec/matchers/throw_symbol_spec.rb +59 -0
  137. data/spec/spec/mocks/any_number_of_times_spec.rb +34 -0
  138. data/spec/spec/mocks/at_least_spec.rb +97 -0
  139. data/spec/spec/mocks/at_most_spec.rb +97 -0
  140. data/spec/spec/mocks/bug_report_7611_spec.rb +19 -0
  141. data/spec/spec/mocks/bug_report_7805_spec.rb +22 -0
  142. data/spec/spec/mocks/bug_report_8165_spec.rb +31 -0
  143. data/spec/spec/mocks/bug_report_8302_spec.rb +26 -0
  144. data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +74 -0
  145. data/spec/spec/mocks/mock_ordering_spec.rb +80 -0
  146. data/spec/spec/mocks/mock_spec.rb +407 -0
  147. data/spec/spec/mocks/multiple_return_value_spec.rb +113 -0
  148. data/spec/spec/mocks/null_object_mock_spec.rb +40 -0
  149. data/spec/spec/mocks/once_counts_spec.rb +56 -0
  150. data/spec/spec/mocks/options_hash_spec.rb +31 -0
  151. data/spec/spec/mocks/partial_mock_spec.rb +52 -0
  152. data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +64 -0
  153. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +92 -0
  154. data/spec/spec/mocks/precise_counts_spec.rb +56 -0
  155. data/spec/spec/mocks/record_messages_spec.rb +26 -0
  156. data/spec/spec/mocks/stub_spec.rb +159 -0
  157. data/spec/spec/mocks/twice_counts_spec.rb +67 -0
  158. data/spec/spec/runner/command_line_spec.rb +32 -0
  159. data/spec/spec/runner/context_matching_spec.rb +28 -0
  160. data/spec/spec/runner/context_runner_spec.rb +100 -0
  161. data/spec/spec/runner/context_spec.rb +405 -0
  162. data/spec/spec/runner/drb_command_line_spec.rb +74 -0
  163. data/spec/spec/runner/execution_context_spec.rb +52 -0
  164. data/spec/spec/runner/formatter/html_formatter_spec.rb +40 -0
  165. data/spec/spec/runner/formatter/progress_bar_formatter_dry_run_spec.rb +21 -0
  166. data/spec/spec/runner/formatter/progress_bar_formatter_failure_dump_spec.rb +36 -0
  167. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +78 -0
  168. data/spec/spec/runner/formatter/rdoc_formatter_dry_run_spec.rb +18 -0
  169. data/spec/spec/runner/formatter/rdoc_formatter_spec.rb +41 -0
  170. data/spec/spec/runner/formatter/specdoc_formatter_dry_run_spec.rb +21 -0
  171. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +46 -0
  172. data/spec/spec/runner/heckle_runner_spec.rb +63 -0
  173. data/spec/spec/runner/heckler_spec.rb +14 -0
  174. data/spec/spec/runner/kernel_ext_spec.rb +16 -0
  175. data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +45 -0
  176. data/spec/spec/runner/object_ext_spec.rb +11 -0
  177. data/spec/spec/runner/option_parser_spec.rb +269 -0
  178. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +47 -0
  179. data/spec/spec/runner/reporter_spec.rb +126 -0
  180. data/spec/spec/runner/spec_matcher_spec.rb +107 -0
  181. data/spec/spec/runner/spec_name_generation_spec.rb +102 -0
  182. data/spec/spec/runner/spec_parser_spec.rb +37 -0
  183. data/spec/spec/runner/specification_class_spec.rb +72 -0
  184. data/spec/spec/runner/specification_instance_spec.rb +160 -0
  185. data/spec/spec/runner/specification_should_raise_spec.rb +136 -0
  186. data/spec/spec/spec_classes.rb +102 -0
  187. data/spec/spec/translator_spec.rb +79 -0
  188. data/spec/spec_helper.rb +35 -0
  189. metadata +141 -9
  190. data/bin/drbspec +0 -3
  191. data/lib/spec/expectations/diff.rb +0 -28
  192. data/lib/spec/expectations/extensions/numeric.rb +0 -19
  193. data/lib/spec/expectations/extensions/string.rb +0 -22
  194. data/lib/spec/expectations/message_builder.rb +0 -13
@@ -0,0 +1,53 @@
1
+ module AnimalSpecHelper
2
+ class Eat
3
+ def initialize(food)
4
+ @food = food
5
+ end
6
+
7
+ def matches?(animal)
8
+ @animal = animal
9
+ @animal.eats?(@food)
10
+ end
11
+
12
+ def failure_message
13
+ "expected #{@animal} to eat #{@food}, but it does not"
14
+ end
15
+
16
+ def negative_failure_message
17
+ "expected #{@animal} not to eat #{@food}, but it does"
18
+ end
19
+ end
20
+
21
+ def eat(food)
22
+ Eat.new(food)
23
+ end
24
+ end
25
+
26
+ module Animals
27
+ class Animal
28
+ def eats?(food)
29
+ return foods_i_eat.include?(food)
30
+ end
31
+ end
32
+
33
+ class Mouse < Animal
34
+ def foods_i_eat
35
+ [:cheese]
36
+ end
37
+ end
38
+ end
39
+
40
+ context "A mouse" do
41
+ include AnimalSpecHelper
42
+ setup do
43
+ @mouse = Animals::Mouse.new
44
+ end
45
+
46
+ specify "should eat cheese" do
47
+ @mouse.should eat(:cheese)
48
+ end
49
+
50
+ specify "should not eat cat" do
51
+ @mouse.should_not eat(:cat)
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ context "The month march" do
4
+ (1..10).each do |n|
5
+ specify "The root of #{n} square should be #{n}" do
6
+ Math.sqrt(n*n).should == n
7
+ end
8
+ end
9
+ end
@@ -10,12 +10,12 @@ context "An IoProcessor" do
10
10
  specify "should raise nothing when the file is exactly 32 bytes" do
11
11
  lambda {
12
12
  @processor.process(StringIO.new("z"*32))
13
- }.should_not_raise
13
+ }.should_not raise_error
14
14
  end
15
15
 
16
16
  specify "should raise an exception when the file length is less than 32 bytes" do
17
17
  lambda {
18
18
  @processor.process(StringIO.new("z"*31))
19
- }.should_raise(DataTooShort)
19
+ }.should raise_error(DataTooShort)
20
20
  end
21
21
  end
@@ -13,15 +13,15 @@ context "a mock" do
13
13
  mock = mock("mock")
14
14
  mock.should_receive(:msg).with(:arg1).and_return(:val1)
15
15
  mock.should_receive(:msg).with(:arg2).and_return(:val2)
16
- mock.msg(:arg1).should_eql(:val1)
17
- mock.msg(:arg2).should_eql(:val2)
16
+ mock.msg(:arg1).should eql(:val1)
17
+ mock.msg(:arg2).should eql(:val2)
18
18
  end
19
19
 
20
20
  specify "should be able to mock the same message twice w/ different args in reverse order" do
21
21
  mock = mock("mock")
22
22
  mock.should_receive(:msg).with(:arg1).and_return(:val1)
23
23
  mock.should_receive(:msg).with(:arg2).and_return(:val2)
24
- mock.msg(:arg2).should_eql(:val2)
25
- mock.msg(:arg1).should_eql(:val1)
24
+ mock.msg(:arg2).should eql(:val2)
25
+ mock.msg(:arg1).should eql(:val1)
26
26
  end
27
27
  end
@@ -10,11 +10,11 @@ context "A partial mock" do
10
10
 
11
11
  specify "should work at the class level" do
12
12
  MockableClass.should_receive(:find).with(1).and_return {:stub_return}
13
- MockableClass.find(1).should_equal :stub_return
13
+ MockableClass.find(1).should equal(:stub_return)
14
14
  end
15
15
 
16
16
  specify "should revert to the original after each spec" do
17
- MockableClass.find(1).should_equal :original_return
17
+ MockableClass.find(1).should equal(:original_return)
18
18
  end
19
19
 
20
20
  specify "can be mocked w/ ordering" do
@@ -17,11 +17,11 @@ context "BDD framework" do
17
17
  end
18
18
 
19
19
  specify "should be adopted quickly" do
20
- @bdd_framework.should_be_adopted_quickly
20
+ @bdd_framework.should be_adopted_quickly
21
21
  end
22
22
 
23
23
  specify "should be intuitive" do
24
- @bdd_framework.should_be_intuitive
24
+ @bdd_framework.should be_intuitive
25
25
  end
26
26
 
27
27
  end
@@ -1,31 +1,31 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
  require File.dirname(__FILE__) + "/stack"
3
3
 
4
- context "A stack which is neither empty nor full" do
4
+ context "A Stack" do
5
5
  setup do
6
6
  @stack = Stack.new
7
7
  ["a","b","c"].each { |x| @stack.push x }
8
8
  end
9
9
 
10
- specify "should add to the top when sent 'push'" do
10
+ specify "should add to the top when sent #push" do
11
11
  @stack.push "d"
12
12
  @stack.peek.should == "d"
13
13
  end
14
14
 
15
- specify "should return the top item when sent 'peek'" do
15
+ specify "should return the top item when sent #peek" do
16
16
  @stack.peek.should == "c"
17
17
  end
18
18
 
19
- specify "should NOT remove the top item when sent 'peek'" do
19
+ specify "should NOT remove the top item when sent #peek" do
20
20
  @stack.peek.should == "c"
21
21
  @stack.peek.should == "c"
22
22
  end
23
23
 
24
- specify "should return the top item when sent 'pop'" do
24
+ specify "should return the top item when sent #pop" do
25
25
  @stack.pop.should == "c"
26
26
  end
27
27
 
28
- specify "should remove the top item when sent 'pop'" do
28
+ specify "should remove the top item when sent #pop" do
29
29
  @stack.pop.should == "c"
30
30
  @stack.pop.should == "b"
31
31
  end
@@ -36,21 +36,20 @@ context "An empty stack" do
36
36
  @stack = Stack.new
37
37
  end
38
38
 
39
- specify "should be empty" do
40
- @stack.should_be_empty
41
- end
39
+ # NOTE that this one auto-generates the description "should be_empty"
40
+ specify { @stack.should be_empty }
42
41
 
43
- specify "should no longer be empty after 'push'" do
42
+ specify "should no longer be empty after #push" do
44
43
  @stack.push "anything"
45
- @stack.should_not_be_empty
44
+ @stack.should_not be_empty
46
45
  end
47
46
 
48
- specify "should complain when sent 'peek'" do
49
- lambda { @stack.peek }.should_raise StackUnderflowError
47
+ specify "should complain when sent #peek" do
48
+ lambda { @stack.peek }.should raise_error(StackUnderflowError)
50
49
  end
51
50
 
52
- specify "should complain when sent 'pop'" do
53
- lambda { @stack.pop }.should_raise StackUnderflowError
51
+ specify "should complain when sent #pop" do
52
+ lambda { @stack.pop }.should raise_error(StackUnderflowError)
54
53
  end
55
54
  end
56
55
 
@@ -60,18 +59,17 @@ context "An almost empty stack (with one item)" do
60
59
  @stack.push 3
61
60
  end
62
61
 
63
- specify "should not be empty" do
64
- @stack.should_not_be_empty
65
- end
62
+ # NOTE that this one auto-generates the description "should not be empty"
63
+ specify { @stack.should_not be_empty }
66
64
 
67
- specify "should remain not empty after 'peek'" do
65
+ specify "should remain not empty after #peek" do
68
66
  @stack.peek
69
- @stack.should_not_be_empty
67
+ @stack.should_not be_empty
70
68
  end
71
69
 
72
- specify "should become empty after 'pop'" do
70
+ specify "should become empty after #pop" do
73
71
  @stack.pop
74
- @stack.should_be_empty
72
+ @stack.should be_empty
75
73
  end
76
74
  end
77
75
 
@@ -81,13 +79,12 @@ context "An almost full stack (with one item less than capacity)" do
81
79
  (1..9).each { |i| @stack.push i }
82
80
  end
83
81
 
84
- specify "should not be full" do
85
- @stack.should_not_be_full
86
- end
82
+ # NOTE that this one auto-generates the description "should not be full"
83
+ specify { @stack.should_not be_full }
87
84
 
88
- specify "should become full when sent 'push'" do
85
+ specify "should become full when sent #push" do
89
86
  @stack.push Object.new
90
- @stack.should_be_full
87
+ @stack.should be_full
91
88
  end
92
89
  end
93
90
 
@@ -97,21 +94,20 @@ context "A full stack" do
97
94
  (1..10).each { |i| @stack.push i }
98
95
  end
99
96
 
100
- specify "should be full" do
101
- @stack.should_be_full
102
- end
97
+ # NOTE that this one auto-generates the description "should be full"
98
+ specify { @stack.should be_full }
103
99
 
104
- specify "should remain full after 'peek'" do
100
+ specify "should remain full after #peek" do
105
101
  @stack.peek
106
- @stack.should_be_full
102
+ @stack.should be_full
107
103
  end
108
104
 
109
- specify "should no longer be full after 'pop'" do
105
+ specify "should no longer be full after #pop" do
110
106
  @stack.pop
111
- @stack.should_not_be_full
107
+ @stack.should_not be_full
112
108
  end
113
109
 
114
- specify "should complain on 'push'" do
115
- lambda { @stack.push Object.new }.should_raise StackOverflowError
110
+ specify "should complain on #push" do
111
+ lambda { @stack.push Object.new }.should raise_error(StackOverflowError)
116
112
  end
117
113
  end
@@ -4,7 +4,7 @@ context "A consumer of a stub" do
4
4
  specify "should be able to stub methods on any Object" do
5
5
  obj = Object.new
6
6
  obj.stub!(:foobar).and_return {:return_value}
7
- obj.foobar.should_equal :return_value
7
+ obj.foobar.should equal(:return_value)
8
8
  end
9
9
  end
10
10
 
@@ -17,23 +17,23 @@ end
17
17
  context "A stubbed method on a class" do
18
18
  specify "should return the stubbed value" do
19
19
  StubbableClass.stub!(:find).and_return(:stub_return)
20
- StubbableClass.find(1).should_equal :stub_return
20
+ StubbableClass.find(1).should equal(:stub_return)
21
21
  end
22
22
 
23
23
  specify "should revert to the original method after each spec" do
24
- StubbableClass.find(1).should_equal :original_return
24
+ StubbableClass.find(1).should equal(:original_return)
25
25
  end
26
26
 
27
27
  specify "can stub! and mock the same message" do
28
28
  StubbableClass.stub!(:msg).and_return(:stub_value)
29
29
  StubbableClass.should_receive(:msg).with(:arg).and_return(:mock_value)
30
30
 
31
- StubbableClass.msg.should_equal :stub_value
32
- StubbableClass.msg(:other_arg).should_equal :stub_value
33
- StubbableClass.msg(:arg).should_equal :mock_value
34
- StubbableClass.msg(:another_arg).should_equal :stub_value
35
- StubbableClass.msg(:yet_another_arg).should_equal :stub_value
36
- StubbableClass.msg.should_equal :stub_value
31
+ StubbableClass.msg.should equal(:stub_value)
32
+ StubbableClass.msg(:other_arg).should equal(:stub_value)
33
+ StubbableClass.msg(:arg).should equal(:mock_value)
34
+ StubbableClass.msg(:another_arg).should equal(:stub_value)
35
+ StubbableClass.msg(:yet_another_arg).should equal(:stub_value)
36
+ StubbableClass.msg.should equal(:stub_value)
37
37
  end
38
38
  end
39
39
 
@@ -41,28 +41,28 @@ context "A mock" do
41
41
  specify "can stub!" do
42
42
  mock = mock("stubbing mock")
43
43
  mock.stub!(:msg).and_return(:value)
44
- (1..10).each {mock.msg.should_equal :value}
44
+ (1..10).each {mock.msg.should equal(:value)}
45
45
  end
46
46
 
47
47
  specify "can stub! and mock" do
48
48
  mock = mock("stubbing mock")
49
49
  mock.stub!(:stub_message).and_return(:stub_value)
50
50
  mock.should_receive(:mock_message).once.and_return(:mock_value)
51
- (1..10).each {mock.stub_message.should_equal :stub_value}
52
- mock.mock_message.should_equal :mock_value
53
- (1..10).each {mock.stub_message.should_equal :stub_value}
51
+ (1..10).each {mock.stub_message.should equal(:stub_value)}
52
+ mock.mock_message.should equal(:mock_value)
53
+ (1..10).each {mock.stub_message.should equal(:stub_value)}
54
54
  end
55
55
 
56
56
  specify "can stub! and mock the same message" do
57
57
  mock = mock("stubbing mock")
58
58
  mock.stub!(:msg).and_return(:stub_value)
59
59
  mock.should_receive(:msg).with(:arg).and_return(:mock_value)
60
- mock.msg.should_equal :stub_value
61
- mock.msg(:other_arg).should_equal :stub_value
62
- mock.msg(:arg).should_equal :mock_value
63
- mock.msg(:another_arg).should_equal :stub_value
64
- mock.msg(:yet_another_arg).should_equal :stub_value
65
- mock.msg.should_equal :stub_value
60
+ mock.msg.should equal(:stub_value)
61
+ mock.msg(:other_arg).should equal(:stub_value)
62
+ mock.msg(:arg).should equal(:mock_value)
63
+ mock.msg(:another_arg).should equal(:stub_value)
64
+ mock.msg(:yet_another_arg).should equal(:stub_value)
65
+ mock.msg.should equal(:stub_value)
66
66
  end
67
67
  end
68
68
 
@@ -7,7 +7,7 @@ class RSpecIntegrationTest < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  def self.verify_class_method
10
- @@fixtures.should_be true
10
+ @@fixtures.should == true
11
11
  end
12
12
 
13
13
  def setup
@@ -35,7 +35,7 @@ end
35
35
  context "RSpec should integrate with Test::Unit::TestCase" do
36
36
  inherit RSpecIntegrationTest
37
37
  include RandomHelperModule
38
-
38
+
39
39
  fixtures :some_table
40
40
 
41
41
  setup do
@@ -43,18 +43,18 @@ context "RSpec should integrate with Test::Unit::TestCase" do
43
43
  end
44
44
 
45
45
  specify "TestCase#setup should be called." do
46
- @test_case_setup_called.should_be true
47
- @rspec_setup_called.should_be true
46
+ @test_case_setup_called.should be_true
47
+ @rspec_setup_called.should be_true
48
48
  end
49
49
 
50
50
  specify "RSpec should be able to access TestCase methods" do
51
51
  helper_method
52
- @helper_method_called.should_be true
52
+ @helper_method_called.should be_true
53
53
  end
54
54
 
55
55
  specify "RSpec should be able to accept included modules" do
56
56
  random_task
57
- @random_task_called.should_be true
57
+ @random_task_called.should be_true
58
58
  end
59
59
 
60
60
  teardown do
@@ -1,5 +1,8 @@
1
+ require 'spec/deprecated'
1
2
  require 'spec/version'
2
3
  require 'spec/callback'
4
+ require 'spec/matchers'
3
5
  require 'spec/expectations'
4
6
  require 'spec/mocks'
5
7
  require 'spec/runner'
8
+ require 'spec/translator'
@@ -1,3 +1,11 @@
1
1
  require 'spec/callback/callback_container'
2
2
  require 'spec/callback/extensions/module'
3
3
  require 'spec/callback/extensions/object'
4
+
5
+ # Callback is a fork of Brian Takita's "callback library" (see http://callback.rubyforge.org),
6
+ # which Brian graciously contributed to RSpec in order to avoid the dependency.
7
+ #
8
+ # RSpec uses Callback internally to create hooks to Spec::Runner events. If you're interested
9
+ # in a simple, powerful API for generating callback events, check out http://callback.rubyforge.org.
10
+ module Callback
11
+ end
@@ -21,6 +21,10 @@ module Callback
21
21
  callbacks.notify(event, *args, &error_handler)
22
22
  end
23
23
 
24
+ def notify_class_callbacks(event, *args, &error_handler)
25
+ self.class.send(:notify_callbacks, event, *args, &error_handler)
26
+ end
27
+
24
28
  # The CallbackContainer for this object.
25
29
  def callbacks
26
30
  @callbacks ||= CallbackContainer.new
@@ -0,0 +1,3 @@
1
+ def deprecated(&block)
2
+ block.call unless ENV['RSPEC_DISABLE_DEPRECATED_FEATURES'] == 'true'
3
+ end
@@ -1,32 +1,59 @@
1
+ require 'spec/deprecated'
2
+ require 'spec/matchers'
1
3
  require 'spec/expectations/sugar'
2
4
  require 'spec/expectations/errors'
3
5
  require 'spec/expectations/extensions'
4
6
  require 'spec/expectations/should'
5
- require 'spec/expectations/message_builder'
7
+ require 'spec/expectations/handler'
6
8
 
7
9
  module Spec
8
- # See Spec::Expectations::ObjectExpectations for expectations that
9
- # are available on all objects.
10
+
11
+ # Spec::Expectations lets you set expectations on your objects.
10
12
  #
11
- # See Spec::Expectations::ProcExpectations for expectations that
12
- # are available on Proc objects.
13
+ # result.should == 37
14
+ # team.should have(11).players_on_the_field
13
15
  #
14
- # See Spec::Expectations::NumericExpectations for expectations that
15
- # are available on Numeric objects.
16
+ # == How Expectations work.
17
+ #
18
+ # Spec::Expectations adds two methods to Object:
19
+ #
20
+ # should(matcher=nil)
21
+ # should_not(matcher=nil)
22
+ #
23
+ # Both methods take an optional Expression Matcher (See Spec::Matchers).
24
+ #
25
+ # When +should+ receives an Expression Matcher, it calls <tt>matches?(self)</tt>. If
26
+ # it returns +true+, the spec passes and execution continues. If it returns
27
+ # +false+, then the spec fails with the message returned by <tt>matcher.failure_message</tt>.
28
+ #
29
+ # Similarly, when +should_not+ receives a matcher, it calls <tt>matches?(self)</tt>. If
30
+ # it returns +false+, the spec passes and execution continues. If it returns
31
+ # +true+, then the spec fails with the message returned by <tt>matcher.negative_failure_message</tt>.
32
+ #
33
+ # RSpec ships with a standard set of useful matchers, and writing your own
34
+ # matchers is quite simple. See Spec::Matchers for details.
16
35
  module Expectations
17
36
  class << self
18
- # raises a Spec::Expectations::ExpecationNotMetError with message
19
- def fail_with(message)
37
+ attr_accessor :differ
38
+
39
+ # raises a Spec::Expectations::ExpectationNotMetError with message
40
+ #
41
+ # When a differ has been assigned and fail_with is passed
42
+ # <code>expected</code> and <code>target</code>, passes them
43
+ # to the differ to append a diff message to the failure message.
44
+ def fail_with(message, expected=nil, target=nil) # :nodoc:
45
+ if Array === message && message.length == 3
46
+ message, expected, target = message[0], message[1], message[2]
47
+ end
48
+ unless (differ.nil? || expected.nil? || target.nil?)
49
+ if expected.is_a?(String)
50
+ message << "\nDiff:" << self.differ.diff_as_string(target.to_s, expected)
51
+ elsif !target.is_a?(Proc)
52
+ message << "\nDiff:" << self.differ.diff_as_object(target, expected)
53
+ end
54
+ end
20
55
  Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))
21
56
  end
22
-
23
- def build_message(actual, expectation, expected)
24
- message_builder.build_message(actual, expectation, expected)
25
- end
26
-
27
- def message_builder #:nodoc:
28
- @message_builder ||= MessageBuilder.new
29
- end
30
57
  end
31
58
  end
32
59
  end