rspec 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Spec
4
+ module DSL
5
+ class Fish
6
+ def can_swim?(distance_in_yards)
7
+ distance_in_yards < 1000
8
+ end
9
+ end
10
+
11
+ describe "predicate_matcher[method_on_object] = matcher_method" do
12
+ predicate_matchers[:can_swim?] = :swim
13
+ it "should match matcher_method if method_on_object returns true" do
14
+ swim(100).matches?(Fish.new).should be_true
15
+ end
16
+ it "should not match matcher_method if method_on_object returns false" do
17
+ swim(10000).matches?(Fish.new).should be_false
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,186 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ module Spec
4
+ module DSL
5
+ describe Behaviour, ", with :shared => true" do
6
+
7
+ before do
8
+ @formatter = Spec::Mocks::Mock.new("formatter", :null_object => true)
9
+ @behaviour = behaviour_class.new("context") {}
10
+ end
11
+
12
+ after do
13
+ @formatter.rspec_verify
14
+ @behaviour_class = nil
15
+ $shared_behaviours.clear unless $shared_behaviours.nil?
16
+ end
17
+
18
+ def behaviour_class
19
+ unless @behaviour_class
20
+ @behaviour_class = Behaviour.dup
21
+ # dup copies the class instance vars
22
+ @behaviour_class.instance_variable_set(:@shared_behaviours, nil)
23
+ end
24
+ @behaviour_class
25
+ end
26
+
27
+ def make_shared_behaviour(name, opts, &block)
28
+ behaviour = behaviour_class.new(name, opts, &block)
29
+ behaviour_class.add_shared_behaviour(behaviour)
30
+ behaviour
31
+ end
32
+
33
+ it "should accept an optional options hash" do
34
+ lambda { behaviour_class.new("context") {} }.should_not raise_error(Exception)
35
+ lambda { behaviour_class.new("context", :shared => true) {} }.should_not raise_error(Exception)
36
+ end
37
+
38
+ it "should return all shared behaviours" do
39
+ make_shared_behaviour("b1", :shared => true) {}
40
+ make_shared_behaviour("b2", :shared => true) {}
41
+
42
+ behaviour_class.find_shared_behaviour("b1").should_not be_nil
43
+ behaviour_class.find_shared_behaviour("b2").should_not be_nil
44
+ end
45
+
46
+ it "should be shared when configured as shared" do
47
+ behaviour = make_shared_behaviour("context", :shared => true) {}
48
+ behaviour.should be_shared
49
+ end
50
+
51
+ it "should not be shared when not configured as shared" do
52
+ @behaviour.should_not be_shared
53
+ end
54
+
55
+ it "should not run when shared" do
56
+ behaviour = make_shared_behaviour("context", :shared => true) {}
57
+ $spec_ran = false
58
+ behaviour.it("test") {$spec_ran = true}
59
+ behaviour.run(@formatter)
60
+ $spec_ran.should be_false
61
+ end
62
+
63
+ it "should contain examples when shared" do
64
+ shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
65
+ shared_behaviour.it("shared example") {}
66
+ shared_behaviour.number_of_examples.should == 1
67
+ end
68
+
69
+ it "should complain when adding a shared behaviour with the same description" do
70
+ make_shared_behaviour("shared behaviour", :shared => true) {}
71
+ lambda { make_shared_behaviour("shared behaviour", :shared => true) {} }.should raise_error(ArgumentError)
72
+ end
73
+
74
+ it "should add examples to current behaviour when calling it_should_behave_like" do
75
+ shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
76
+ shared_behaviour.it("shared example") {}
77
+ shared_behaviour.it("shared example 2") {}
78
+
79
+ @behaviour.it("example") {}
80
+ @behaviour.number_of_examples.should == 1
81
+ @behaviour.it_should_behave_like("shared behaviour")
82
+ @behaviour.number_of_examples.should == 3
83
+ end
84
+
85
+ it "should run shared examples" do
86
+ shared_example_ran = false
87
+ shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
88
+ shared_behaviour.it("shared example") { shared_example_ran = true }
89
+
90
+ example_ran = false
91
+
92
+ @behaviour.it_should_behave_like("shared behaviour")
93
+ @behaviour.it("example") {example_ran = true}
94
+ @behaviour.run(@formatter)
95
+ example_ran.should be_true
96
+ shared_example_ran.should be_true
97
+ end
98
+
99
+ it "should run setup and teardown from shared behaviour" do
100
+ shared_setup_ran = false
101
+ shared_teardown_ran = false
102
+ shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
103
+ shared_behaviour.before { shared_setup_ran = true }
104
+ shared_behaviour.after { shared_teardown_ran = true }
105
+ shared_behaviour.it("shared example") { shared_example_ran = true }
106
+
107
+ example_ran = false
108
+
109
+ @behaviour.it_should_behave_like("shared behaviour")
110
+ @behaviour.it("example") {example_ran = true}
111
+ @behaviour.run(@formatter)
112
+ example_ran.should be_true
113
+ shared_setup_ran.should be_true
114
+ shared_teardown_ran.should be_true
115
+ end
116
+
117
+ it "should run before(:all) and after(:all) only once from shared behaviour" do
118
+ shared_before_all_run_count = 0
119
+ shared_after_all_run_count = 0
120
+ shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
121
+ shared_behaviour.before(:all) { shared_before_all_run_count += 1}
122
+ shared_behaviour.after(:all) { shared_after_all_run_count += 1}
123
+ shared_behaviour.it("shared example") { shared_example_ran = true }
124
+
125
+ example_ran = false
126
+
127
+ @behaviour.it_should_behave_like("shared behaviour")
128
+ @behaviour.it("example") {example_ran = true}
129
+ @behaviour.run(@formatter)
130
+ example_ran.should be_true
131
+ shared_before_all_run_count.should == 1
132
+ shared_after_all_run_count.should == 1
133
+ end
134
+
135
+ it "should include modules, included into shared behaviour, into current behaviour" do
136
+ @formatter.should_receive(:add_behaviour).with :any_args
137
+ @formatter.should_receive(:example_finished).twice.with :any_args
138
+
139
+ shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
140
+ shared_behaviour.it("shared example") { shared_example_ran = true }
141
+
142
+ mod1_method_called = false
143
+ mod1 = Module.new do
144
+ define_method :mod1_method do
145
+ mod1_method_called = true
146
+ end
147
+ end
148
+
149
+ mod2_method_called = false
150
+ mod2 = Module.new do
151
+ define_method :mod2_method do
152
+ mod2_method_called = true
153
+ end
154
+ end
155
+
156
+ shared_behaviour.include mod2
157
+
158
+ @behaviour.it_should_behave_like("shared behaviour")
159
+ @behaviour.include mod1
160
+
161
+ @behaviour.it("test") do
162
+ mod1_method
163
+ mod2_method
164
+ end
165
+ @behaviour.run(@formatter)
166
+ mod1_method_called.should be_true
167
+ mod2_method_called.should be_true
168
+ end
169
+
170
+ it "should error if told to inherit from a class" do
171
+ shared_behaviour = make_shared_behaviour("shared behaviour", :shared => true) {}
172
+ shared_behaviour.it("shared example") { shared_example_ran = true }
173
+ lambda { shared_behaviour.inherit Object }.should raise_error(ArgumentError)
174
+ end
175
+
176
+ it "should raise when named shared behaviour can not be found" do
177
+ begin
178
+ @behaviour.it_should_behave_like("non-existent shared behaviour")
179
+ violated
180
+ rescue => e
181
+ e.message.should == "Shared Behaviour 'non-existent shared behaviour' can not be found"
182
+ end
183
+ end
184
+ end
185
+ end
186
+ end
@@ -20,20 +20,20 @@ module Spec
20
20
  end
21
21
  end
22
22
 
23
- context "Diff" do
24
- setup do
23
+ describe "Diff" do
24
+ before(:each) do
25
25
  @differ = Spec::Expectations::Differs::Default.new
26
26
  end
27
27
 
28
- specify "should output unified diff of two strings" do
28
+ it "should output unified diff of two strings" do
29
29
  expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
30
30
  actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
31
31
  expected_diff="\n\n@@ -1,6 +1,6 @@\n foo\n-bar\n zap\n+bar\n this\n is\n soo\n@@ -9,5 +9,6 @@\n equal\n insert\n a\n+another\n line\n"
32
32
  diff = @differ.diff_as_string(expected, actual)
33
- diff.should_eql(expected_diff)
33
+ diff.should eql(expected_diff)
34
34
  end
35
35
 
36
- specify "should output unified diff message of two arrays" do
36
+ it "should output unified diff message of two arrays" do
37
37
  expected = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'charlie', :width, 'quite wide' ]
38
38
  actual = [ :foo, 'bar', :baz, 'quux', :metasyntactic, 'variable', :delta, 'tango' , :width, 'very wide' ]
39
39
 
@@ -53,10 +53,10 @@ EOD
53
53
 
54
54
 
55
55
  diff = @differ.diff_as_object(expected,actual)
56
- diff.should_eql expected_diff
56
+ diff.should == expected_diff
57
57
  end
58
58
 
59
- specify "should output unified diff message of two objects" do
59
+ it "should output unified diff message of two objects" do
60
60
  expected = Spec::Fixtures::Animal.new "bob", "giraffe"
61
61
  actual = Spec::Fixtures::Animal.new "bob", "tortoise"
62
62
 
@@ -71,18 +71,18 @@ EOD
71
71
  EOD
72
72
 
73
73
  diff = @differ.diff_as_object(expected,actual)
74
- diff.should_eql expected_diff
74
+ diff.should == expected_diff
75
75
  end
76
76
 
77
77
  end
78
78
 
79
79
 
80
- context "Diff in context format" do
81
- setup do
80
+ describe "Diff in context format" do
81
+ before(:each) do
82
82
  @differ = Spec::Expectations::Differs::Default.new(:context)
83
83
  end
84
84
 
85
- specify "should output unified diff message of two objects" do
85
+ it "should output unified diff message of two objects" do
86
86
  expected = Spec::Fixtures::Animal.new "bob", "giraffe"
87
87
  actual = Spec::Fixtures::Animal.new "bob", "tortoise"
88
88
 
@@ -102,6 +102,6 @@ context "Diff in context format" do
102
102
  EOD
103
103
 
104
104
  diff = @differ.diff_as_object(expected,actual)
105
- diff.should_eql expected_diff
105
+ diff.should == expected_diff
106
106
  end
107
107
  end
@@ -1,46 +1,46 @@
1
1
  require File.dirname(__FILE__) + '/../../../spec_helper.rb'
2
2
 
3
- context "Object#should" do
4
- setup do
3
+ describe "Object#should" do
4
+ before(:each) do
5
5
  @target = "target"
6
6
  @matcher = mock("matcher")
7
7
  @matcher.stub!(:matches?).and_return(true)
8
8
  @matcher.stub!(:failure_message)
9
9
  end
10
10
 
11
- specify "should accept and interact with a matcher" do
11
+ it "should accept and interact with a matcher" do
12
12
  @matcher.should_receive(:matches?).with(@target).and_return(true)
13
13
 
14
14
  @target.should @matcher
15
15
  end
16
16
 
17
- specify "should ask for a failure_message when matches? returns false" do
17
+ it "should ask for a failure_message when matches? returns false" do
18
18
  @matcher.should_receive(:matches?).with(@target).and_return(false)
19
19
  @matcher.should_receive(:failure_message).and_return("the failure message")
20
20
  lambda {
21
21
  @target.should @matcher
22
- }.should_fail_with "the failure message"
22
+ }.should fail_with("the failure message")
23
23
  end
24
24
  end
25
25
 
26
- context "Object#should_not" do
27
- setup do
26
+ describe "Object#should_not" do
27
+ before(:each) do
28
28
  @target = "target"
29
29
  @matcher = mock("matcher")
30
30
  end
31
31
 
32
- specify "should accept and interact with a matcher" do
32
+ it "should accept and interact with a matcher" do
33
33
  @matcher.should_receive(:matches?).with(@target).and_return(false)
34
34
  @matcher.stub!(:negative_failure_message)
35
35
 
36
36
  @target.should_not @matcher
37
37
  end
38
38
 
39
- specify "should ask for a negative_failure_message when matches? returns true" do
39
+ it "should ask for a negative_failure_message when matches? returns true" do
40
40
  @matcher.should_receive(:matches?).with(@target).and_return(true)
41
41
  @matcher.should_receive(:negative_failure_message).and_return("the negative failure message")
42
42
  lambda {
43
43
  @target.should_not @matcher
44
- }.should_fail_with "the negative failure message"
44
+ }.should fail_with("the negative failure message")
45
45
  end
46
46
  end
@@ -1,71 +1,71 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
- context "Spec::Expectations.fail_with with no diff" do
4
- setup do
3
+ describe "Spec::Expectations.fail_with with no diff" do
4
+ before(:each) do
5
5
  @old_differ = Spec::Expectations.differ
6
6
  Spec::Expectations.differ = nil
7
7
  end
8
8
 
9
- specify "should handle just a message" do
9
+ it "should handle just a message" do
10
10
  lambda {
11
11
  Spec::Expectations.fail_with "the message"
12
- }.should_fail_with "the message"
12
+ }.should fail_with("the message")
13
13
  end
14
14
 
15
- specify "should handle an Array" do
15
+ it "should handle an Array" do
16
16
  lambda {
17
17
  Spec::Expectations.fail_with ["the message","expected","actual"]
18
- }.should_fail_with "the message"
18
+ }.should fail_with("the message")
19
19
  end
20
20
 
21
- teardown do
21
+ after(:each) do
22
22
  Spec::Expectations.differ = @old_differ
23
23
  end
24
24
  end
25
25
 
26
- context "Spec::Expectations.fail_with with diff" do
27
- setup do
26
+ describe "Spec::Expectations.fail_with with diff" do
27
+ before(:each) do
28
28
  @old_differ = Spec::Expectations.differ
29
29
  @differ = mock("differ")
30
30
  Spec::Expectations.differ = @differ
31
31
  end
32
32
 
33
- specify "should not call differ if no expected/actual" do
33
+ it "should not call differ if no expected/actual" do
34
34
  lambda {
35
35
  Spec::Expectations.fail_with "the message"
36
- }.should_fail_with "the message"
36
+ }.should fail_with("the message")
37
37
  end
38
38
 
39
- specify "should call differ if expected/actual are presented separately" do
39
+ it "should call differ if expected/actual are presented separately" do
40
40
  @differ.should_receive(:diff_as_string).and_return("diff")
41
41
  lambda {
42
42
  Spec::Expectations.fail_with "the message", "expected", "actual"
43
- }.should_fail_with "the message\nDiff:diff"
43
+ }.should fail_with("the message\nDiff:diff")
44
44
  end
45
45
 
46
- specify "should call differ if expected/actual are not strings" do
46
+ it "should call differ if expected/actual are not strings" do
47
47
  @differ.should_receive(:diff_as_object).and_return("diff")
48
48
  lambda {
49
49
  Spec::Expectations.fail_with "the message", :expected, :actual
50
- }.should_fail_with "the message\nDiff:diff"
50
+ }.should fail_with("the message\nDiff:diff")
51
51
  end
52
52
 
53
- specify "should not call differ if expected or actual are procs" do
53
+ it "should not call differ if expected or actual are procs" do
54
54
  @differ.should_not_receive(:diff_as_string)
55
55
  @differ.should_not_receive(:diff_as_object)
56
56
  lambda {
57
57
  Spec::Expectations.fail_with "the message", lambda {}, lambda {}
58
- }.should_fail_with "the message"
58
+ }.should fail_with("the message")
59
59
  end
60
60
 
61
- specify "should call differ if expected/actual are presented in an Array with message" do
61
+ it "should call differ if expected/actual are presented in an Array with message" do
62
62
  @differ.should_receive(:diff_as_string).with("actual","expected").and_return("diff")
63
63
  lambda {
64
64
  Spec::Expectations.fail_with(["the message", "expected", "actual"])
65
- }.should_fail_with /the message\nDiff:diff/
65
+ }.should fail_with(/the message\nDiff:diff/)
66
66
  end
67
67
 
68
- teardown do
68
+ after(:each) do
69
69
  Spec::Expectations.differ = @old_differ
70
70
  end
71
71
  end
@@ -1,33 +1,39 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
-
3
- context "should be_close(expected, delta)" do
4
- specify "should pass if target == expected" do
5
- 5.0.should be_close(5.0, 0.5)
2
+ module Spec
3
+ module Matchers
4
+ describe BeClose do
5
+ it "should match when value == target" do
6
+ BeClose.new(5.0, 0.5).matches?(5.0).should be_true
7
+ end
8
+ it "should match when value < (target + delta)" do
9
+ BeClose.new(5.0, 0.5).matches?(5.49).should be_true
10
+ end
11
+ it "should match when value > (target - delta)" do
12
+ BeClose.new(5.0, 0.5).matches?(4.51).should be_true
13
+ end
14
+ it "should not match when value == (target - delta)" do
15
+ BeClose.new(5.0, 0.5).matches?(4.5).should be_false
16
+ end
17
+ it "should not match when value < (target - delta)" do
18
+ BeClose.new(5.0, 0.5).matches?(4.49).should be_false
19
+ end
20
+ it "should not match when value == (target + delta)" do
21
+ BeClose.new(5.0, 0.5).matches?(5.5).should be_false
22
+ end
23
+ it "should not match when value > (target + delta)" do
24
+ BeClose.new(5.0, 0.5).matches?(5.51).should be_false
25
+ end
26
+ it "should provide a useful failure message" do
27
+ #given
28
+ matcher = BeClose.new(5.0, 0.5)
29
+ #when
30
+ matcher.matches?(5.51)
31
+ #then
32
+ matcher.failure_message.should == "expected 5.0 +/- (< 0.5), got 5.51"
33
+ end
34
+ it "should describe itself" do
35
+ BeClose.new(5.0, 0.5).description.should == "be close to 5.0 (within +- 0.5)"
36
+ end
37
+ end
6
38
  end
7
- specify "should pass if target < expected + delta" do
8
- 5.49.should be_close(5.0, 0.5)
9
- end
10
- specify "should pass if target > expected - delta" do
11
- 4.51.should be_close(5.0, 0.5)
12
- end
13
- specify "should fail if target == expected - delta" do
14
- lambda {
15
- 4.5.should be_close(5.0, 0.5)
16
- }.should fail_with("expected 5.0 +/- (<0.5), got 4.5")
17
- end
18
- specify "should fail if target < expected - delta" do
19
- lambda {
20
- 4.49.should be_close(5.0, 0.5)
21
- }.should fail_with("expected 5.0 +/- (<0.5), got 4.49")
22
- end
23
- specify "should fail if target == expected + delta" do
24
- lambda {
25
- 5.5.should be_close(5.0, 0.5)
26
- }.should fail_with("expected 5.0 +/- (<0.5), got 5.5")
27
- end
28
- specify "should fail if target > expected + delta" do
29
- lambda {
30
- 5.51.should be_close(5.0, 0.5)
31
- }.should fail_with("expected 5.0 +/- (<0.5), got 5.51")
32
- end
33
- end
39
+ end