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
@@ -1,58 +1,58 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
- context "should be_predicate" do
4
- specify "should pass when actual returns true for :predicate?" do
3
+ describe "should be_predicate" do
4
+ it "should pass when actual returns true for :predicate?" do
5
5
  actual = stub("actual", :happy? => true)
6
6
  actual.should be_happy
7
7
  end
8
8
 
9
- specify "should pass when actual returns true for :predicates? (present tense)" do
9
+ it "should pass when actual returns true for :predicates? (present tense)" do
10
10
  actual = stub("actual", :exists? => true)
11
11
  actual.should be_exist
12
12
  end
13
13
 
14
- specify "should fail when actual returns false for :predicate?" do
14
+ it "should fail when actual returns false for :predicate?" do
15
15
  actual = stub("actual", :happy? => false)
16
16
  lambda {
17
17
  actual.should be_happy
18
18
  }.should fail_with("expected happy? to return true, got false")
19
19
  end
20
20
 
21
- specify "should fail when actual does not respond to :predicate?" do
21
+ it "should fail when actual does not respond to :predicate?" do
22
22
  lambda {
23
23
  Object.new.should be_happy
24
24
  }.should raise_error(NameError)
25
25
  end
26
26
  end
27
27
 
28
- context "should_not be_predicate" do
29
- specify "should pass when actual returns false for :sym?" do
28
+ describe "should_not be_predicate" do
29
+ it "should pass when actual returns false for :sym?" do
30
30
  actual = stub("actual", :happy? => false)
31
31
  actual.should_not be_happy
32
32
  end
33
33
 
34
- specify "should fail when actual returns true for :sym?" do
34
+ it "should fail when actual returns true for :sym?" do
35
35
  actual = stub("actual", :happy? => true)
36
36
  lambda {
37
37
  actual.should_not be_happy
38
38
  }.should fail_with("expected happy? to return false, got true")
39
39
  end
40
40
 
41
- specify "should fail when actual does not respond to :sym?" do
41
+ it "should fail when actual does not respond to :sym?" do
42
42
  lambda {
43
43
  Object.new.should_not be_happy
44
44
  }.should raise_error(NameError)
45
45
  end
46
46
  end
47
47
 
48
- context "should be_predicate(*args)" do
49
- specify "should pass when actual returns true for :predicate?(*args)" do
48
+ describe "should be_predicate(*args)" do
49
+ it "should pass when actual returns true for :predicate?(*args)" do
50
50
  actual = mock("actual")
51
51
  actual.should_receive(:older_than?).with(3).and_return(true)
52
52
  actual.should be_older_than(3)
53
53
  end
54
54
 
55
- specify "should fail when actual returns false for :predicate?(*args)" do
55
+ it "should fail when actual returns false for :predicate?(*args)" do
56
56
  actual = mock("actual")
57
57
  actual.should_receive(:older_than?).with(3).and_return(false)
58
58
  lambda {
@@ -60,21 +60,21 @@ context "should be_predicate(*args)" do
60
60
  }.should fail_with("expected older_than?(3) to return true, got false")
61
61
  end
62
62
 
63
- specify "should fail when actual does not respond to :predicate?" do
63
+ it "should fail when actual does not respond to :predicate?" do
64
64
  lambda {
65
65
  Object.new.should be_older_than(3)
66
66
  }.should raise_error(NameError)
67
67
  end
68
68
  end
69
69
 
70
- context "should_not be_predicate(*args)" do
71
- specify "should pass when actual returns false for :predicate?(*args)" do
70
+ describe "should_not be_predicate(*args)" do
71
+ it "should pass when actual returns false for :predicate?(*args)" do
72
72
  actual = mock("actual")
73
73
  actual.should_receive(:older_than?).with(3).and_return(false)
74
74
  actual.should_not be_older_than(3)
75
75
  end
76
76
 
77
- specify "should fail when actual returns true for :predicate?(*args)" do
77
+ it "should fail when actual returns true for :predicate?(*args)" do
78
78
  actual = mock("actual")
79
79
  actual.should_receive(:older_than?).with(3).and_return(true)
80
80
  lambda {
@@ -82,101 +82,110 @@ context "should_not be_predicate(*args)" do
82
82
  }.should fail_with("expected older_than?(3) to return false, got true")
83
83
  end
84
84
 
85
- specify "should fail when actual does not respond to :predicate?" do
85
+ it "should fail when actual does not respond to :predicate?" do
86
86
  lambda {
87
87
  Object.new.should_not be_older_than(3)
88
88
  }.should raise_error(NameError)
89
89
  end
90
90
  end
91
91
 
92
- context "should be_true" do
93
- specify "should pass when actual equal(true)" do
92
+ describe "should be_true" do
93
+ it "should pass when actual equal(true)" do
94
94
  true.should be_true
95
95
  end
96
96
 
97
- specify "should fail when actual equal(false)" do
97
+ it "should fail when actual equal(false)" do
98
98
  lambda {
99
99
  false.should be_true
100
100
  }.should fail_with("expected true, got false")
101
101
  end
102
102
  end
103
103
 
104
- context "should be_false" do
105
- specify "should pass when actual equal(false)" do
104
+ describe "should be_false" do
105
+ it "should pass when actual equal(false)" do
106
106
  false.should be_false
107
107
  end
108
108
 
109
- specify "should fail when actual equal(true)" do
109
+ it "should fail when actual equal(true)" do
110
110
  lambda {
111
111
  true.should be_false
112
112
  }.should fail_with("expected false, got true")
113
113
  end
114
114
  end
115
115
 
116
- context "should be_nil" do
117
- specify "should pass when actual is nil" do
116
+ describe "should be_nil" do
117
+ it "should pass when actual is nil" do
118
118
  nil.should be_nil
119
119
  end
120
120
 
121
- specify "should fail when actual is not nil" do
121
+ it "should fail when actual is not nil" do
122
122
  lambda {
123
123
  :not_nil.should be_nil
124
124
  }.should fail_with("expected nil, got :not_nil")
125
125
  end
126
126
  end
127
127
 
128
- context "should_not be_nil" do
129
- specify "should pass when actual is not nil" do
128
+ describe "should_not be_nil" do
129
+ it "should pass when actual is not nil" do
130
130
  :not_nil.should_not be_nil
131
131
  end
132
132
 
133
- specify "should fail when actual is nil" do
133
+ it "should fail when actual is nil" do
134
134
  lambda {
135
135
  nil.should_not be_nil
136
136
  }.should fail_with("expected not nil, got nil")
137
137
  end
138
138
  end
139
139
 
140
- context "should be <" do
141
- specify "should pass when < operator returns true" do
140
+ describe "should be <" do
141
+ it "should pass when < operator returns true" do
142
142
  3.should be < 4
143
143
  end
144
144
 
145
- specify "should fail when < operator returns false" do
145
+ it "should fail when < operator returns false" do
146
146
  lambda { 3.should be < 3 }.should fail_with("expected < 3, got 3")
147
147
  end
148
148
  end
149
149
 
150
- context "should be <=" do
151
- specify "should pass when <= operator returns true" do
150
+ describe "should be <=" do
151
+ it "should pass when <= operator returns true" do
152
152
  3.should be <= 4
153
153
  4.should be <= 4
154
154
  end
155
155
 
156
- specify "should fail when <= operator returns false" do
156
+ it "should fail when <= operator returns false" do
157
157
  lambda { 3.should be <= 2 }.should fail_with("expected <= 2, got 3")
158
158
  end
159
159
  end
160
160
 
161
- context "should be >=" do
162
- specify "should pass when >= operator returns true" do
161
+ describe "should be >=" do
162
+ it "should pass when >= operator returns true" do
163
163
  4.should be >= 4
164
164
  5.should be >= 4
165
165
  end
166
166
 
167
- specify "should fail when >= operator returns false" do
167
+ it "should fail when >= operator returns false" do
168
168
  lambda { 3.should be >= 4 }.should fail_with("expected >= 4, got 3")
169
169
  end
170
170
  end
171
171
 
172
- context "should be >" do
173
- specify "should pass when > operator returns true" do
172
+ describe "should be >" do
173
+ it "should pass when > operator returns true" do
174
174
  5.should be > 4
175
175
  end
176
176
 
177
- specify "should fail when > operator returns false" do
177
+ it "should fail when > operator returns false" do
178
178
  lambda { 3.should be > 4 }.should fail_with("expected > 4, got 3")
179
179
  end
180
180
  end
181
181
 
182
+ describe "should be(value)" do
183
+ it "should pass if actual.equal?(value)" do
184
+ 5.should be(5)
185
+ end
186
+ it "should fail if !actual.equal?(value)" do
187
+ lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
188
+ end
189
+ end
190
+
182
191
 
@@ -5,228 +5,228 @@ class SomethingExpected
5
5
  attr_accessor :some_value
6
6
  end
7
7
 
8
- context "should change(actual, message)" do
9
- setup do
8
+ describe "should change(actual, message)" do
9
+ before(:each) do
10
10
  @instance = SomethingExpected.new
11
11
  @instance.some_value = 5
12
12
  end
13
13
 
14
- specify "should pass when actual is modified by the block" do
14
+ it "should pass when actual is modified by the block" do
15
15
  lambda {@instance.some_value = 6}.should change(@instance, :some_value)
16
16
  end
17
17
 
18
- specify "should fail when actual is not modified by the block" do
18
+ it "should fail when actual is not modified by the block" do
19
19
  lambda do
20
20
  lambda {}.should change(@instance, :some_value)
21
21
  end.should fail_with("some_value should have changed, but is still 5")
22
22
  end
23
23
  end
24
24
 
25
- context "should_not change(actual, message)" do
26
- setup do
25
+ describe "should_not change(actual, message)" do
26
+ before(:each) do
27
27
  @instance = SomethingExpected.new
28
28
  @instance.some_value = 5
29
29
  end
30
30
 
31
- specify "should pass when actual is not modified by the block" do
31
+ it "should pass when actual is not modified by the block" do
32
32
  lambda { }.should_not change(@instance, :some_value)
33
33
  end
34
34
 
35
- specify "should fail when actual is not modified by the block" do
35
+ it "should fail when actual is not modified by the block" do
36
36
  lambda do
37
37
  lambda {@instance.some_value = 6}.should_not change(@instance, :some_value)
38
38
  end.should fail_with("some_value should not have changed, but did change from 5 to 6")
39
39
  end
40
40
  end
41
41
 
42
- context "should change { block }" do
43
- setup do
42
+ describe "should change { block }" do
43
+ before(:each) do
44
44
  @instance = SomethingExpected.new
45
45
  @instance.some_value = 5
46
46
  end
47
47
 
48
- specify "should pass when actual is modified by the block" do
48
+ it "should pass when actual is modified by the block" do
49
49
  lambda {@instance.some_value = 6}.should change { @instance.some_value }
50
50
  end
51
51
 
52
- specify "should fail when actual is not modified by the block" do
52
+ it "should fail when actual is not modified by the block" do
53
53
  lambda do
54
54
  lambda {}.should change{ @instance.some_value }
55
55
  end.should fail_with("result should have changed, but is still 5")
56
56
  end
57
57
 
58
- specify "should warn if passed a block using do/end" do
58
+ it "should warn if passed a block using do/end" do
59
59
  lambda do
60
60
  lambda {}.should change do
61
61
  end
62
- end.should_raise(Spec::Matchers::MatcherError, /block passed to should or should_not/)
62
+ end.should raise_error(Spec::Matchers::MatcherError, /block passed to should or should_not/)
63
63
  end
64
64
  end
65
65
 
66
- context "should_not change { block }" do
67
- setup do
66
+ describe "should_not change { block }" do
67
+ before(:each) do
68
68
  @instance = SomethingExpected.new
69
69
  @instance.some_value = 5
70
70
  end
71
71
 
72
- specify "should pass when actual is modified by the block" do
72
+ it "should pass when actual is modified by the block" do
73
73
  lambda {}.should_not change{ @instance.some_value }
74
74
  end
75
75
 
76
- specify "should fail when actual is not modified by the block" do
76
+ it "should fail when actual is not modified by the block" do
77
77
  lambda do
78
78
  lambda {@instance.some_value = 6}.should_not change { @instance.some_value }
79
79
  end.should fail_with("result should not have changed, but did change from 5 to 6")
80
80
  end
81
81
 
82
- specify "should warn if passed a block using do/end" do
82
+ it "should warn if passed a block using do/end" do
83
83
  lambda do
84
84
  lambda {}.should_not change do
85
85
  end
86
- end.should_raise(Spec::Matchers::MatcherError, /block passed to should or should_not/)
86
+ end.should raise_error(Spec::Matchers::MatcherError, /block passed to should or should_not/)
87
87
  end
88
88
  end
89
89
 
90
- context "should change(actual, message).by(expected)" do
91
- setup do
90
+ describe "should change(actual, message).by(expected)" do
91
+ before(:each) do
92
92
  @instance = SomethingExpected.new
93
93
  @instance.some_value = 5
94
94
  end
95
95
 
96
- specify "should pass when attribute is changed by expected amount" do
96
+ it "should pass when attribute is changed by expected amount" do
97
97
  lambda { @instance.some_value += 1 }.should change(@instance, :some_value).by(1)
98
98
  end
99
99
 
100
- specify "should fail when the attribute is changed by unexpected amount" do
100
+ it "should fail when the attribute is changed by unexpected amount" do
101
101
  lambda do
102
102
  lambda { @instance.some_value += 2 }.should change(@instance, :some_value).by(1)
103
103
  end.should fail_with("some_value should have been changed by 1, but was changed by 2")
104
104
  end
105
105
 
106
- specify "should fail when the attribute is changed by unexpected amount in the opposite direction" do
106
+ it "should fail when the attribute is changed by unexpected amount in the opposite direction" do
107
107
  lambda do
108
108
  lambda { @instance.some_value -= 1 }.should change(@instance, :some_value).by(1)
109
109
  end.should fail_with("some_value should have been changed by 1, but was changed by -1")
110
110
  end
111
111
  end
112
112
 
113
- context "should change{ block }.by(expected)" do
114
- setup do
113
+ describe "should change{ block }.by(expected)" do
114
+ before(:each) do
115
115
  @instance = SomethingExpected.new
116
116
  @instance.some_value = 5
117
117
  end
118
118
 
119
- specify "should pass when attribute is changed by expected amount" do
119
+ it "should pass when attribute is changed by expected amount" do
120
120
  lambda { @instance.some_value += 1 }.should change{@instance.some_value}.by(1)
121
121
  end
122
122
 
123
- specify "should fail when the attribute is changed by unexpected amount" do
123
+ it "should fail when the attribute is changed by unexpected amount" do
124
124
  lambda do
125
125
  lambda { @instance.some_value += 2 }.should change{@instance.some_value}.by(1)
126
126
  end.should fail_with("result should have been changed by 1, but was changed by 2")
127
127
  end
128
128
 
129
- specify "should fail when the attribute is changed by unexpected amount in the opposite direction" do
129
+ it "should fail when the attribute is changed by unexpected amount in the opposite direction" do
130
130
  lambda do
131
131
  lambda { @instance.some_value -= 1 }.should change{@instance.some_value}.by(1)
132
132
  end.should fail_with("result should have been changed by 1, but was changed by -1")
133
133
  end
134
134
  end
135
135
 
136
- context "should change(actual, message).from(old)" do
137
- setup do
136
+ describe "should change(actual, message).from(old)" do
137
+ before(:each) do
138
138
  @instance = SomethingExpected.new
139
139
  @instance.some_value = 'string'
140
140
  end
141
141
 
142
- specify "should pass when attribute is == to expected value before executing block" do
142
+ it "should pass when attribute is == to expected value before executing block" do
143
143
  lambda { @instance.some_value = "astring" }.should change(@instance, :some_value).from("string")
144
144
  end
145
145
 
146
- specify "should fail when attribute is not == to expected value before executing block" do
146
+ it "should fail when attribute is not == to expected value before executing block" do
147
147
  lambda do
148
148
  lambda { @instance.some_value = "knot" }.should change(@instance, :some_value).from("cat")
149
149
  end.should fail_with("some_value should have initially been \"cat\", but was \"string\"")
150
150
  end
151
151
  end
152
152
 
153
- context "should change{ block }.from(old)" do
154
- setup do
153
+ describe "should change{ block }.from(old)" do
154
+ before(:each) do
155
155
  @instance = SomethingExpected.new
156
156
  @instance.some_value = 'string'
157
157
  end
158
158
 
159
- specify "should pass when attribute is == to expected value before executing block" do
159
+ it "should pass when attribute is == to expected value before executing block" do
160
160
  lambda { @instance.some_value = "astring" }.should change{@instance.some_value}.from("string")
161
161
  end
162
162
 
163
- specify "should fail when attribute is not == to expected value before executing block" do
163
+ it "should fail when attribute is not == to expected value before executing block" do
164
164
  lambda do
165
165
  lambda { @instance.some_value = "knot" }.should change{@instance.some_value}.from("cat")
166
166
  end.should fail_with("result should have initially been \"cat\", but was \"string\"")
167
167
  end
168
168
  end
169
169
 
170
- context "should change(actual, message).to(new)" do
171
- setup do
170
+ describe "should change(actual, message).to(new)" do
171
+ before(:each) do
172
172
  @instance = SomethingExpected.new
173
173
  @instance.some_value = 'string'
174
174
  end
175
175
 
176
- specify "should pass when attribute is == to expected value after executing block" do
176
+ it "should pass when attribute is == to expected value after executing block" do
177
177
  lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).to("cat")
178
178
  end
179
179
 
180
- specify "should fail when attribute is not == to expected value after executing block" do
180
+ it "should fail when attribute is not == to expected value after executing block" do
181
181
  lambda do
182
182
  lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).from("string").to("dog")
183
183
  end.should fail_with("some_value should have been changed to \"dog\", but is now \"cat\"")
184
184
  end
185
185
  end
186
186
 
187
- context "should change{ block }.to(new)" do
188
- setup do
187
+ describe "should change{ block }.to(new)" do
188
+ before(:each) do
189
189
  @instance = SomethingExpected.new
190
190
  @instance.some_value = 'string'
191
191
  end
192
192
 
193
- specify "should pass when attribute is == to expected value after executing block" do
193
+ it "should pass when attribute is == to expected value after executing block" do
194
194
  lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.to("cat")
195
195
  end
196
196
 
197
- specify "should fail when attribute is not == to expected value after executing block" do
197
+ it "should fail when attribute is not == to expected value after executing block" do
198
198
  lambda do
199
199
  lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.from("string").to("dog")
200
200
  end.should fail_with("result should have been changed to \"dog\", but is now \"cat\"")
201
201
  end
202
202
  end
203
203
 
204
- context "should change(actual, message).from(old).to(new)" do
205
- setup do
204
+ describe "should change(actual, message).from(old).to(new)" do
205
+ before(:each) do
206
206
  @instance = SomethingExpected.new
207
207
  @instance.some_value = 'string'
208
208
  end
209
209
 
210
- specify "should pass when #to comes before #from" do
210
+ it "should pass when #to comes before #from" do
211
211
  lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).to("cat").from("string")
212
212
  end
213
213
 
214
- specify "should pass when #from comes before #to" do
214
+ it "should pass when #from comes before #to" do
215
215
  lambda { @instance.some_value = "cat" }.should change(@instance, :some_value).from("string").to("cat")
216
216
  end
217
217
  end
218
218
 
219
- context "should change{ block }.from(old).to(new)" do
220
- setup do
219
+ describe "should change{ block }.from(old).to(new)" do
220
+ before(:each) do
221
221
  @instance = SomethingExpected.new
222
222
  @instance.some_value = 'string'
223
223
  end
224
224
 
225
- specify "should pass when #to comes before #from" do
225
+ it "should pass when #to comes before #from" do
226
226
  lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.to("cat").from("string")
227
227
  end
228
228
 
229
- specify "should pass when #from comes before #to" do
229
+ it "should pass when #from comes before #to" do
230
230
  lambda { @instance.some_value = "cat" }.should change{@instance.some_value}.from("string").to("cat")
231
231
  end
232
232
  end