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
data/UPGRADE ADDED
@@ -0,0 +1,31 @@
1
+ = Upgrading existing code to RSpec-0.9
2
+
3
+ == General (see below for Spec::Rails specifics)
4
+
5
+ === New Syntax for should and should_not
6
+
7
+ * Use translator (should get 90% of your code)
8
+ * Manually fix "parenthesis" warnings
9
+
10
+ === Change before_context_eval to before_eval
11
+
12
+ before_context_eval is an un-published hook used by
13
+ Spec::Rails to create specialized behaviour contexts.
14
+ Most of you don't need to change this, but for those
15
+ who have exploited it, you'll need to change it to
16
+ before_eval.
17
+
18
+ == Spec::Rails
19
+
20
+ === spec_helper.rb
21
+
22
+ We've added a new way to configure Spec::Runner to do
23
+ things like use_transactional_fixtures and use_instantiated_fixtures.
24
+ You'll need to update spec/spec_helper.rb accordingly. You can either
25
+ just re-generate it:
26
+
27
+ script/generate rspec
28
+
29
+ Or modify spec_helper.rb based on the template, which can be found at:
30
+
31
+ vendor/plugins/rspec_on_rails/generators/rspec/templates/spec_helper.rb
data/bin/spec CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env ruby
2
1
  $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
3
2
  require 'spec'
4
3
  ::Spec::Runner::CommandLine.run(ARGV, STDERR, STDOUT, true, true)
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
2
+ require 'spec/translator'
3
+ t = ::Spec::Translator.new
4
+ from = ARGV[0]
5
+ to = ARGV[1]
6
+ t.translate(from, to)
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ # Run spec w/ -fs to see the output of this file
4
+
5
+ describe "Examples with no descriptions" do
6
+
7
+ # description is auto-generated as "should equal(5)" based on the last #should
8
+ it do
9
+ 3.should equal(3)
10
+ 5.should equal(5)
11
+ end
12
+
13
+ it { 3.should be < 5 }
14
+
15
+ it { ["a"].should include("a") }
16
+
17
+ it { [1,2,3].should respond_to(:size) }
18
+
19
+ end
@@ -1,16 +1,16 @@
1
1
  $global = 0
2
2
 
3
- context "State created in context_setup" do
4
- context_setup do
3
+ describe "State created in before(:all)" do
4
+ before :all do
5
5
  @sideeffect = 1
6
6
  $global +=1
7
7
  end
8
8
 
9
- setup do
9
+ before :each do
10
10
  @isolated = 1
11
11
  end
12
12
 
13
- specify "should be accessible from spec" do
13
+ it "should be accessible from example" do
14
14
  @sideeffect.should == 1
15
15
  $global.should == 1
16
16
  @isolated.should == 1
@@ -19,7 +19,7 @@ context "State created in context_setup" do
19
19
  @isolated += 1
20
20
  end
21
21
 
22
- specify "should not have sideffects" do
22
+ it "should not have sideffects" do
23
23
  @sideeffect.should == 1
24
24
  $global.should == 1
25
25
  @isolated.should == 1
@@ -28,7 +28,7 @@ context "State created in context_setup" do
28
28
  @isolated += 1
29
29
  end
30
30
 
31
- context_teardown do
31
+ after :all do
32
32
  $global = 0
33
33
  end
34
34
  end
@@ -0,0 +1,45 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ def behave_as_electric_musician
4
+ respond_to(:read_notes, :turn_down_amp)
5
+ end
6
+
7
+ def behave_as_musician
8
+ respond_to(:read_notes)
9
+ end
10
+
11
+ module BehaveAsExample
12
+
13
+ class BluesGuitarist
14
+ def read_notes; end
15
+ def turn_down_amp; end
16
+ end
17
+
18
+ class RockGuitarist
19
+ def read_notes; end
20
+ def turn_down_amp; end
21
+ end
22
+
23
+ class ClassicGuitarist
24
+ def read_notes; end
25
+ end
26
+
27
+ describe BluesGuitarist do
28
+ it "should behave as guitarist" do
29
+ BluesGuitarist.new.should behave_as_electric_musician
30
+ end
31
+ end
32
+
33
+ describe RockGuitarist do
34
+ it "should behave as guitarist" do
35
+ RockGuitarist.new.should behave_as_electric_musician
36
+ end
37
+ end
38
+
39
+ describe ClassicGuitarist do
40
+ it "should not behave as guitarist" do
41
+ ClassicGuitarist.new.should behave_as_musician
42
+ end
43
+ end
44
+
45
+ end
@@ -35,19 +35,20 @@ module Animals
35
35
  [:cheese]
36
36
  end
37
37
  end
38
- end
39
38
 
40
- context "A mouse" do
41
- include AnimalSpecHelper
42
- setup do
43
- @mouse = Animals::Mouse.new
44
- end
39
+ describe Mouse do
40
+ include AnimalSpecHelper
41
+ before(:each) do
42
+ @mouse = Animals::Mouse.new
43
+ end
45
44
 
46
- specify "should eat cheese" do
47
- @mouse.should eat(:cheese)
48
- end
45
+ it "should eat cheese" do
46
+ @mouse.should eat(:cheese)
47
+ end
49
48
 
50
- specify "should not eat cat" do
51
- @mouse.should_not eat(:cat)
49
+ it "should not eat cat" do
50
+ @mouse.should_not eat(:cat)
51
+ end
52
52
  end
53
- end
53
+
54
+ end
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- context "The month march" do
3
+ describe "Some integers" do
4
4
  (1..10).each do |n|
5
- specify "The root of #{n} square should be #{n}" do
5
+ it "The root of #{n} square should be #{n}" do
6
6
  Math.sqrt(n*n).should == n
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper'
2
2
  require File.dirname(__FILE__) + '/file_accessor'
3
3
  require 'stringio'
4
4
 
5
- context "A FileAccessor" do
5
+ describe "A FileAccessor" do
6
6
  # This sequence diagram illustrates what this spec specifies.
7
7
  #
8
8
  # +--------------+ +----------+ +-------------+
@@ -20,7 +20,7 @@ context "A FileAccessor" do
20
20
  # | |<..................................| |
21
21
  # | | |
22
22
  #
23
- specify "should open a file and pass it to the processor's process method" do
23
+ it "should open a file and pass it to the processor's process method" do
24
24
  # This is the primary actor
25
25
  accessor = FileAccessor.new
26
26
 
@@ -16,13 +16,13 @@ class Greeter
16
16
  end
17
17
  end
18
18
 
19
- context "Greeter" do
20
- specify "should say Hi to person" do
19
+ describe "Greeter" do
20
+ it "should say Hi to person" do
21
21
  greeter = Greeter.new("Kevin")
22
22
  greeter.greet.should == "Hi Kevin!"
23
23
  end
24
24
 
25
- specify "should say Hi to nobody" do
25
+ it "should say Hi to nobody" do
26
26
  greeter = Greeter.new
27
27
  # Uncomment the next line to make Heckle happy
28
28
  #greeter.greet.should == "Hi there!"
@@ -1,11 +1,11 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- context "a context with helper a method" do
3
+ describe "a context with helper a method" do
4
4
  def helper_method
5
5
  "received call"
6
6
  end
7
7
 
8
- specify "should make that method available to specs" do
8
+ it "should make that method available to specs" do
9
9
  helper_method.should == "received call"
10
10
  end
11
11
  end
@@ -2,18 +2,18 @@ require File.dirname(__FILE__) + '/spec_helper'
2
2
  require File.dirname(__FILE__) + '/io_processor'
3
3
  require 'stringio'
4
4
 
5
- context "An IoProcessor" do
6
- setup do
5
+ describe "An IoProcessor" do
6
+ before(:each) do
7
7
  @processor = IoProcessor.new
8
8
  end
9
9
 
10
- specify "should raise nothing when the file is exactly 32 bytes" do
10
+ it "should raise nothing when the file is exactly 32 bytes" do
11
11
  lambda {
12
12
  @processor.process(StringIO.new("z"*32))
13
13
  }.should_not raise_error
14
14
  end
15
15
 
16
- specify "should raise an exception when the file length is less than 32 bytes" do
16
+ it "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
19
  }.should raise_error(DataTooShort)
@@ -0,0 +1,10 @@
1
+ context "A legacy spec" do
2
+ setup do
3
+ end
4
+
5
+ specify "should work fine" do
6
+ end
7
+
8
+ teardown do
9
+ end
10
+ end
@@ -1,15 +1,15 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
- context "A consumer of a mock" do
4
- specify "should be able to send messages to the mock" do
3
+ describe "A consumer of a mock" do
4
+ it "should be able to send messages to the mock" do
5
5
  mock = mock("poke me")
6
6
  mock.should_receive(:poke)
7
7
  mock.poke
8
8
  end
9
9
  end
10
10
 
11
- context "a mock" do
12
- specify "should be able to mock the same message twice w/ different args" do
11
+ describe "a mock" do
12
+ it "should be able to mock the same message twice w/ different args" 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)
@@ -17,7 +17,7 @@ context "a mock" do
17
17
  mock.msg(:arg2).should eql(:val2)
18
18
  end
19
19
 
20
- specify "should be able to mock the same message twice w/ different args in reverse order" do
20
+ it "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)
@@ -0,0 +1,25 @@
1
+
2
+ class MultiThreadedBehaviourRunner < Spec::Runner::BehaviourRunner
3
+ def initialize(options)
4
+ super
5
+ # configure these
6
+ @thread_count = 4
7
+ @thread_wait = 0
8
+ end
9
+
10
+ def run_behaviours(behaviours)
11
+ @threads = []
12
+ q = Queue.new
13
+ behaviours.each { |b| q << b}
14
+ @thread_count.times do
15
+ @threads << Thread.new(q) do |queue|
16
+ while not queue.empty?
17
+ behaviour = queue.pop
18
+ behaviour.run(@options.reporter, @options.dry_run, @options.reverse)
19
+ end
20
+ end
21
+ sleep @thread_wait
22
+ end
23
+ @threads.each {|t| t.join}
24
+ end
25
+ end
@@ -6,18 +6,18 @@ class MockableClass
6
6
  end
7
7
  end
8
8
 
9
- context "A partial mock" do
9
+ describe "A partial mock" do
10
10
 
11
- specify "should work at the class level" do
11
+ it "should work at the class level" do
12
12
  MockableClass.should_receive(:find).with(1).and_return {:stub_return}
13
13
  MockableClass.find(1).should equal(:stub_return)
14
14
  end
15
15
 
16
- specify "should revert to the original after each spec" do
16
+ it "should revert to the original after each spec" do
17
17
  MockableClass.find(1).should equal(:original_return)
18
18
  end
19
19
 
20
- specify "can be mocked w/ ordering" do
20
+ it "can be mocked w/ ordering" do
21
21
  MockableClass.should_receive(:msg_1).ordered
22
22
  MockableClass.should_receive(:msg_2).ordered
23
23
  MockableClass.should_receive(:msg_3).ordered
@@ -10,17 +10,17 @@ class BddFramework
10
10
  end
11
11
  end
12
12
 
13
- context "BDD framework" do
13
+ describe "BDD framework" do
14
14
 
15
- setup do
15
+ before(:each) do
16
16
  @bdd_framework = BddFramework.new
17
17
  end
18
18
 
19
- specify "should be adopted quickly" do
19
+ it "should be adopted quickly" do
20
20
  @bdd_framework.should be_adopted_quickly
21
21
  end
22
22
 
23
- specify "should be intuitive" do
23
+ it "should be intuitive" do
24
24
  @bdd_framework.should be_intuitive
25
25
  end
26
26
 
@@ -0,0 +1 @@
1
+ examples/custom_expectation_matchers.rb
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ module SharedBehaviourExample
4
+ class OneThing
5
+ def what_things_do
6
+ "stuff"
7
+ end
8
+ end
9
+
10
+ class AnotherThing
11
+ def what_things_do
12
+ "stuff"
13
+ end
14
+ end
15
+
16
+ describe "All Things", :shared => true do
17
+ it "should do what things do" do
18
+ @thing.what_things_do.should == "stuff"
19
+ end
20
+ end
21
+
22
+ describe OneThing do
23
+ it_should_behave_like "All Things"
24
+ before(:each) { @thing = OneThing.new }
25
+ end
26
+
27
+ describe AnotherThing do
28
+ it_should_behave_like "All Things"
29
+ before(:each) { @thing = AnotherThing.new }
30
+ end
31
+ end
@@ -1,113 +1,96 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
  require File.dirname(__FILE__) + "/stack"
3
3
 
4
- context "A Stack" do
5
- setup do
6
- @stack = Stack.new
7
- ["a","b","c"].each { |x| @stack.push x }
8
- end
4
+ describe "non-empty Stack", :shared => true do
5
+ # NOTE that this one auto-generates the description "should not be empty"
6
+ it { @stack.should_not be_empty }
9
7
 
10
- specify "should add to the top when sent #push" do
11
- @stack.push "d"
12
- @stack.peek.should == "d"
8
+ it "should return the top item when sent #peek" do
9
+ @stack.peek.should == @last_item_added
13
10
  end
14
-
15
- specify "should return the top item when sent #peek" do
16
- @stack.peek.should == "c"
11
+
12
+ it "should NOT remove the top item when sent #peek" do
13
+ @stack.peek.should == @last_item_added
14
+ @stack.peek.should == @last_item_added
17
15
  end
18
16
 
19
- specify "should NOT remove the top item when sent #peek" do
20
- @stack.peek.should == "c"
21
- @stack.peek.should == "c"
17
+ it "should return the top item when sent #pop" do
18
+ @stack.pop.should == @last_item_added
22
19
  end
23
20
 
24
- specify "should return the top item when sent #pop" do
25
- @stack.pop.should == "c"
21
+ it "should remove the top item when sent #pop" do
22
+ @stack.pop.should == @last_item_added
23
+ unless @stack.empty?
24
+ @stack.pop.should_not == @last_item_added
25
+ end
26
26
  end
27
-
28
- specify "should remove the top item when sent #pop" do
29
- @stack.pop.should == "c"
30
- @stack.pop.should == "b"
27
+ end
28
+
29
+ describe "non-full Stack", :shared => true do
30
+ # NOTE that this one auto-generates the description "should not be full"
31
+ it { @stack.should_not be_full }
32
+
33
+ it "should add to the top when sent #push" do
34
+ @stack.push "newly added top item"
35
+ @stack.peek.should == "newly added top item"
31
36
  end
32
37
  end
33
38
 
34
- context "An empty stack" do
35
- setup do
39
+ describe Stack, " (empty)" do
40
+ before(:each) do
36
41
  @stack = Stack.new
37
42
  end
38
43
 
39
- # NOTE that this one auto-generates the description "should be_empty"
40
- specify { @stack.should be_empty }
44
+ # NOTE that this one auto-generates the description "should be empty"
45
+ it { @stack.should be_empty }
41
46
 
42
- specify "should no longer be empty after #push" do
43
- @stack.push "anything"
44
- @stack.should_not be_empty
45
- end
47
+ it_should_behave_like "non-full Stack"
46
48
 
47
- specify "should complain when sent #peek" do
49
+ it "should complain when sent #peek" do
48
50
  lambda { @stack.peek }.should raise_error(StackUnderflowError)
49
51
  end
50
52
 
51
- specify "should complain when sent #pop" do
53
+ it "should complain when sent #pop" do
52
54
  lambda { @stack.pop }.should raise_error(StackUnderflowError)
53
55
  end
54
56
  end
55
57
 
56
- context "An almost empty stack (with one item)" do
57
- setup do
58
+ describe Stack, " (with one item)" do
59
+ before(:each) do
58
60
  @stack = Stack.new
59
61
  @stack.push 3
62
+ @last_item_added = 3
60
63
  end
61
-
62
- # NOTE that this one auto-generates the description "should not be empty"
63
- specify { @stack.should_not be_empty }
64
-
65
- specify "should remain not empty after #peek" do
66
- @stack.peek
67
- @stack.should_not be_empty
68
- end
69
-
70
- specify "should become empty after #pop" do
71
- @stack.pop
72
- @stack.should be_empty
73
- end
64
+
65
+ it_should_behave_like "non-empty Stack"
66
+ it_should_behave_like "non-full Stack"
67
+
74
68
  end
75
69
 
76
- context "An almost full stack (with one item less than capacity)" do
77
- setup do
70
+ describe Stack, " (with one item less than capacity)" do
71
+ before(:each) do
78
72
  @stack = Stack.new
79
73
  (1..9).each { |i| @stack.push i }
74
+ @last_item_added = 9
80
75
  end
81
76
 
82
- # NOTE that this one auto-generates the description "should not be full"
83
- specify { @stack.should_not be_full }
84
-
85
- specify "should become full when sent #push" do
86
- @stack.push Object.new
87
- @stack.should be_full
88
- end
77
+ it_should_behave_like "non-empty Stack"
78
+ it_should_behave_like "non-full Stack"
89
79
  end
90
80
 
91
- context "A full stack" do
92
- setup do
81
+ describe Stack, " (full)" do
82
+ before(:each) do
93
83
  @stack = Stack.new
94
84
  (1..10).each { |i| @stack.push i }
85
+ @last_item_added = 10
95
86
  end
96
-
87
+
97
88
  # NOTE that this one auto-generates the description "should be full"
98
- specify { @stack.should be_full }
99
-
100
- specify "should remain full after #peek" do
101
- @stack.peek
102
- @stack.should be_full
103
- end
104
-
105
- specify "should no longer be full after #pop" do
106
- @stack.pop
107
- @stack.should_not be_full
108
- end
89
+ it { @stack.should be_full }
90
+
91
+ it_should_behave_like "non-empty Stack"
109
92
 
110
- specify "should complain on #push" do
93
+ it "should complain on #push" do
111
94
  lambda { @stack.push Object.new }.should raise_error(StackOverflowError)
112
95
  end
113
96
  end