rspec 1.1.11 → 1.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. data/.autotest +4 -0
  2. data/History.txt +55 -0
  3. data/Manifest.txt +102 -122
  4. data/README.txt +30 -12
  5. data/Rakefile +10 -10
  6. data/TODO.txt +10 -2
  7. data/{failing_examples → examples/failing}/README.txt +0 -0
  8. data/{failing_examples → examples/failing}/diffing_spec.rb +0 -0
  9. data/{failing_examples → examples/failing}/failing_autogenerated_docstrings_example.rb +0 -0
  10. data/{failing_examples/failure_in_teardown.rb → examples/failing/failure_in_after.rb} +1 -1
  11. data/{failing_examples/failure_in_setup.rb → examples/failing/failure_in_before.rb} +1 -1
  12. data/{failing_examples → examples/failing}/mocking_example.rb +0 -0
  13. data/{failing_examples → examples/failing}/mocking_with_flexmock.rb +0 -0
  14. data/{failing_examples → examples/failing}/mocking_with_mocha.rb +0 -0
  15. data/{failing_examples → examples/failing}/mocking_with_rr.rb +0 -0
  16. data/{failing_examples → examples/failing}/partial_mock_example.rb +0 -0
  17. data/{failing_examples → examples/failing}/predicate_example.rb +5 -0
  18. data/{failing_examples → examples/failing}/raising_example.rb +0 -0
  19. data/{failing_examples → examples/failing}/spec_helper.rb +1 -1
  20. data/{failing_examples → examples/failing}/syntax_error_example.rb +0 -0
  21. data/{failing_examples → examples/failing}/team_spec.rb +0 -0
  22. data/{failing_examples → examples/failing}/timeout_behaviour.rb +0 -0
  23. data/examples/{pure → passing}/autogenerated_docstrings_example.rb +6 -0
  24. data/examples/{pure → passing}/before_and_after_example.rb +0 -0
  25. data/examples/{pure → passing}/behave_as_example.rb +0 -0
  26. data/examples/{pure → passing}/custom_expectation_matchers.rb +0 -0
  27. data/examples/{pure → passing}/custom_formatter.rb +1 -1
  28. data/examples/{pure → passing}/dynamic_spec.rb +2 -2
  29. data/examples/{pure → passing}/file_accessor.rb +0 -0
  30. data/examples/{pure → passing}/file_accessor_spec.rb +0 -0
  31. data/examples/{pure → passing}/greeter_spec.rb +0 -0
  32. data/examples/{pure → passing}/helper_method_example.rb +0 -0
  33. data/examples/{pure → passing}/io_processor.rb +0 -0
  34. data/examples/{pure → passing}/io_processor_spec.rb +0 -0
  35. data/examples/{pure → passing}/legacy_spec.rb +0 -0
  36. data/examples/{pure → passing}/mocking_example.rb +0 -0
  37. data/examples/{pure/multi_threaded_behaviour_runner.rb → passing/multi_threaded_example_group_runner.rb} +1 -3
  38. data/examples/{pure → passing}/nested_classes_example.rb +0 -0
  39. data/examples/{pure → passing}/partial_mock_example.rb +0 -0
  40. data/examples/{pure → passing}/pending_example.rb +0 -0
  41. data/examples/{pure → passing}/predicate_example.rb +0 -0
  42. data/examples/{pure → passing}/priority.txt +0 -0
  43. data/examples/{pure → passing}/shared_example_group_example.rb +0 -0
  44. data/examples/{pure → passing}/shared_stack_examples.rb +1 -3
  45. data/examples/passing/simple_matcher_example.rb +31 -0
  46. data/examples/{pure → passing}/spec_helper.rb +0 -0
  47. data/examples/{pure → passing}/stack.rb +0 -0
  48. data/examples/{pure → passing}/stack_spec.rb +3 -2
  49. data/examples/{pure → passing}/stack_spec_with_nested_example_groups.rb +0 -0
  50. data/examples/{pure → passing}/stubbing_example.rb +0 -0
  51. data/examples/{pure → passing}/yielding_example.rb +0 -0
  52. data/examples/ruby1.9.compatibility/access_to_constants_spec.rb +86 -0
  53. data/features/before_and_after_blocks/before_and_after_blocks.feature +168 -0
  54. data/{stories/example_groups/autogenerated_docstrings → features/example_groups/autogenerated_docstrings.feature} +5 -5
  55. data/{stories/example_groups/example_group_with_should_methods → features/example_groups/example_group_with_should_methods.feature} +3 -3
  56. data/{stories/example_groups/nested_groups → features/example_groups/nested_groups.feature} +4 -4
  57. data/{stories/example_groups/output → features/example_groups/output.feature} +3 -8
  58. data/{stories/interop/examples_and_tests_together → features/interop/examples_and_tests_together.feature} +5 -4
  59. data/features/interop/test_but_not_test_unit.feature +14 -0
  60. data/{stories/interop/test_case_with_should_methods → features/interop/test_case_with_should_methods.feature} +2 -2
  61. data/{stories/mock_framework_integration/use_flexmock.story → features/mock_framework_integration/use_flexmock.feature} +1 -1
  62. data/features/step_definitions/running_rspec.rb +54 -0
  63. data/features/support/env.rb +26 -0
  64. data/{stories/resources → features/support}/helpers/cmdline.rb +0 -0
  65. data/{stories/resources → features/support}/helpers/story_helper.rb +1 -1
  66. data/{stories/resources → features/support}/matchers/smart_match.rb +0 -0
  67. data/{plugins → lib/adapters}/mock_frameworks/flexmock.rb +1 -1
  68. data/{plugins → lib/adapters}/mock_frameworks/mocha.rb +1 -1
  69. data/{plugins → lib/adapters}/mock_frameworks/rr.rb +1 -1
  70. data/{plugins → lib/adapters}/mock_frameworks/rspec.rb +2 -2
  71. data/lib/autotest/rspec.rb +4 -3
  72. data/lib/spec.rb +2 -27
  73. data/lib/spec/dsl.rb +1 -0
  74. data/lib/spec/{extensions → dsl}/main.rb +10 -10
  75. data/lib/spec/example.rb +175 -1
  76. data/lib/spec/example/before_and_after_hooks.rb +30 -24
  77. data/lib/spec/example/example_group.rb +1 -0
  78. data/lib/spec/example/example_group_factory.rb +26 -9
  79. data/lib/spec/example/example_group_methods.rb +138 -113
  80. data/lib/spec/example/example_methods.rb +88 -25
  81. data/lib/spec/example/shared_example_group.rb +28 -21
  82. data/lib/spec/expectations.rb +22 -18
  83. data/lib/spec/expectations/handler.rb +16 -36
  84. data/lib/spec/interop/test/unit/testcase.rb +19 -17
  85. data/lib/spec/interop/test/unit/testresult.rb +1 -1
  86. data/lib/spec/interop/test/unit/testsuite_adapter.rb +1 -1
  87. data/lib/spec/matchers.rb +7 -28
  88. data/lib/spec/matchers/be.rb +103 -116
  89. data/lib/spec/matchers/be_close.rb +6 -22
  90. data/lib/spec/matchers/eql.rb +7 -25
  91. data/lib/spec/matchers/equal.rb +7 -25
  92. data/lib/spec/matchers/errors.rb +5 -0
  93. data/lib/spec/matchers/exist.rb +8 -14
  94. data/lib/spec/matchers/generated_descriptions.rb +48 -0
  95. data/lib/spec/matchers/has.rb +12 -28
  96. data/lib/spec/matchers/include.rb +12 -9
  97. data/lib/spec/matchers/match.rb +8 -27
  98. data/lib/spec/matchers/match_array.rb +79 -0
  99. data/lib/spec/matchers/method_missing.rb +9 -0
  100. data/lib/spec/matchers/operator_matcher.rb +39 -48
  101. data/lib/spec/matchers/raise_error.rb +4 -8
  102. data/lib/spec/matchers/respond_to.rb +33 -8
  103. data/lib/spec/matchers/throw_symbol.rb +49 -17
  104. data/lib/spec/matchers/wrap_expectation.rb +55 -0
  105. data/lib/spec/mocks/argument_constraints.rb +77 -5
  106. data/lib/spec/mocks/message_expectation.rb +7 -7
  107. data/lib/spec/mocks/proxy.rb +14 -12
  108. data/lib/spec/rake/spectask.rb +4 -6
  109. data/lib/spec/ruby.rb +9 -0
  110. data/lib/spec/runner.rb +37 -162
  111. data/lib/spec/runner/backtrace_tweaker.rb +5 -3
  112. data/lib/spec/runner/class_and_arguments_parser.rb +7 -9
  113. data/lib/spec/runner/command_line.rb +6 -8
  114. data/lib/spec/{example → runner}/configuration.rb +46 -47
  115. data/lib/spec/runner/example_group_runner.rb +15 -4
  116. data/lib/spec/runner/formatter/base_text_formatter.rb +4 -3
  117. data/lib/spec/runner/formatter/html_formatter.rb +14 -11
  118. data/lib/spec/runner/formatter/nested_text_formatter.rb +2 -2
  119. data/lib/spec/runner/heckle_runner.rb +58 -56
  120. data/lib/spec/runner/option_parser.rb +8 -4
  121. data/lib/spec/runner/options.rb +29 -14
  122. data/lib/spec/runner/reporter.rb +1 -1
  123. data/lib/spec/runner/spec_parser.rb +11 -9
  124. data/lib/spec/story/runner.rb +40 -42
  125. data/lib/spec/story/runner/story_runner.rb +10 -6
  126. data/lib/spec/story/world.rb +66 -70
  127. data/lib/spec/version.rb +4 -2
  128. data/{rake_tasks → resources/rake}/examples.rake +0 -0
  129. data/{rake_tasks → resources/rake}/examples_with_rcov.rake +0 -0
  130. data/{rake_tasks → resources/rake}/failing_examples_with_html.rake +0 -0
  131. data/{rake_tasks → resources/rake}/verify_rcov.rake +0 -0
  132. data/{stories/resources → resources}/spec/example_group_with_should_methods.rb +1 -1
  133. data/{stories/resources → resources}/spec/simple_spec.rb +1 -1
  134. data/resources/spec/spec_with_flexmock.rb +19 -0
  135. data/{stories/resources → resources}/test/spec_and_test_together.rb +1 -1
  136. data/resources/test/spec_including_test_but_not_unit.rb +11 -0
  137. data/{stories/resources → resources}/test/test_case_with_should_methods.rb +2 -2
  138. data/rspec.gemspec +16 -6
  139. data/spec/autotest/autotest_helper.rb +2 -2
  140. data/spec/autotest/discover_spec.rb +4 -15
  141. data/spec/autotest/failed_results_re_spec.rb +24 -0
  142. data/spec/autotest/rspec_spec.rb +2 -38
  143. data/spec/spec/dsl/main_spec.rb +88 -0
  144. data/spec/spec/example/example_group_class_definition_spec.rb +6 -2
  145. data/spec/spec/example/example_group_factory_spec.rb +50 -10
  146. data/spec/spec/example/example_group_methods_spec.rb +210 -160
  147. data/spec/spec/example/example_group_spec.rb +44 -52
  148. data/spec/spec/example/example_matcher_spec.rb +6 -23
  149. data/spec/spec/example/example_methods_spec.rb +176 -54
  150. data/spec/spec/example/helper_method_spec.rb +24 -0
  151. data/spec/spec/example/pending_module_spec.rb +2 -8
  152. data/spec/spec/example/shared_example_group_spec.rb +56 -80
  153. data/spec/spec/expectations/extensions/object_spec.rb +0 -50
  154. data/spec/spec/expectations/wrap_expectation_spec.rb +30 -0
  155. data/spec/spec/interop/test/unit/spec_spec.rb +1 -5
  156. data/spec/spec/interop/test/unit/test_unit_spec_helper.rb +4 -0
  157. data/spec/spec/matchers/be_close_spec.rb +12 -10
  158. data/spec/spec/matchers/be_spec.rb +62 -7
  159. data/spec/spec/matchers/description_generation_spec.rb +19 -0
  160. data/spec/spec/matchers/eql_spec.rb +7 -6
  161. data/spec/spec/matchers/equal_spec.rb +7 -6
  162. data/spec/spec/matchers/handler_spec.rb +4 -43
  163. data/spec/spec/matchers/has_spec.rb +1 -1
  164. data/spec/spec/matchers/have_spec.rb +23 -18
  165. data/spec/spec/matchers/include_spec.rb +24 -0
  166. data/spec/spec/matchers/match_array_spec.rb +83 -0
  167. data/spec/spec/matchers/matcher_methods_spec.rb +1 -13
  168. data/spec/spec/matchers/raise_error_spec.rb +18 -0
  169. data/spec/spec/matchers/respond_to_spec.rb +71 -9
  170. data/spec/spec/matchers/throw_symbol_spec.rb +85 -43
  171. data/spec/spec/mocks/bug_report_11545_spec.rb +4 -5
  172. data/spec/spec/mocks/bug_report_496.rb +11 -9
  173. data/spec/spec/mocks/bug_report_600_spec.rb +22 -0
  174. data/spec/spec/mocks/hash_including_matcher_spec.rb +39 -2
  175. data/spec/spec/mocks/hash_not_including_matcher_spec.rb +67 -0
  176. data/spec/spec/mocks/mock_spec.rb +5 -6
  177. data/spec/spec/mocks/nil_expectation_warning_spec.rb +2 -2
  178. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +18 -3
  179. data/spec/spec/mocks/stub_spec.rb +6 -0
  180. data/spec/spec/mocks/stubbed_message_expectations_spec.rb +14 -0
  181. data/spec/spec/runner/command_line_spec.rb +4 -4
  182. data/spec/spec/runner/configuration_spec.rb +301 -0
  183. data/spec/spec/runner/drb_command_line_spec.rb +4 -4
  184. data/spec/spec/runner/example_group_runner_spec.rb +33 -0
  185. data/spec/spec/runner/formatter/base_formatter_spec.rb +13 -102
  186. data/spec/spec/runner/formatter/base_text_formatter_spec.rb +23 -0
  187. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +5 -5
  188. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +3 -3
  189. data/spec/spec/runner/formatter/html_formatted-1.8.4.html +6 -6
  190. data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +9 -9
  191. data/spec/spec/runner/formatter/html_formatted-1.8.5.html +6 -6
  192. data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +10 -10
  193. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +39 -30
  194. data/spec/spec/runner/formatter/html_formatted-1.8.7.html +379 -0
  195. data/spec/spec/runner/formatter/html_formatted-1.9.1.html +379 -0
  196. data/spec/spec/runner/formatter/html_formatter_spec.rb +14 -13
  197. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +5 -5
  198. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +7 -17
  199. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +18 -17
  200. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +5 -5
  201. data/spec/spec/runner/formatter/text_mate_formatted-1.8.4.html +6 -6
  202. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +33 -30
  203. data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +373 -0
  204. data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +373 -0
  205. data/spec/spec/runner/heckler_spec.rb +16 -9
  206. data/spec/spec/runner/option_parser_spec.rb +3 -18
  207. data/spec/spec/runner/options_spec.rb +27 -8
  208. data/spec/spec/runner/reporter_spec.rb +5 -5
  209. data/spec/spec/runner/resources/custom_example_group_runner.rb +14 -0
  210. data/spec/spec/runner/resources/utf8_encoded.rb +7 -0
  211. data/spec/spec/runner/spec_parser_spec.rb +85 -79
  212. data/spec/spec/spec_spec.rb +21 -0
  213. data/spec/spec_helper.rb +9 -1
  214. data/story_server/prototype/javascripts/prototype.js +1 -1
  215. metadata +119 -131
  216. data/examples/stories/adder.rb +0 -13
  217. data/examples/stories/addition +0 -34
  218. data/examples/stories/addition.rb +0 -9
  219. data/examples/stories/calculator.rb +0 -65
  220. data/examples/stories/game-of-life/.loadpath +0 -5
  221. data/examples/stories/game-of-life/README.txt +0 -21
  222. data/examples/stories/game-of-life/behaviour/everything.rb +0 -6
  223. data/examples/stories/game-of-life/behaviour/examples/examples.rb +0 -3
  224. data/examples/stories/game-of-life/behaviour/examples/game_behaviour.rb +0 -35
  225. data/examples/stories/game-of-life/behaviour/examples/grid_behaviour.rb +0 -66
  226. data/examples/stories/game-of-life/behaviour/stories/CellsWithLessThanTwoNeighboursDie.story +0 -21
  227. data/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story +0 -21
  228. data/examples/stories/game-of-life/behaviour/stories/EmptySpacesWithThreeNeighboursCreateACell.story +0 -42
  229. data/examples/stories/game-of-life/behaviour/stories/ICanCreateACell.story +0 -42
  230. data/examples/stories/game-of-life/behaviour/stories/ICanKillACell.story +0 -17
  231. data/examples/stories/game-of-life/behaviour/stories/TheGridWraps.story +0 -53
  232. data/examples/stories/game-of-life/behaviour/stories/create_a_cell.rb +0 -52
  233. data/examples/stories/game-of-life/behaviour/stories/helper.rb +0 -6
  234. data/examples/stories/game-of-life/behaviour/stories/kill_a_cell.rb +0 -26
  235. data/examples/stories/game-of-life/behaviour/stories/steps.rb +0 -5
  236. data/examples/stories/game-of-life/behaviour/stories/stories.rb +0 -3
  237. data/examples/stories/game-of-life/behaviour/stories/stories.txt +0 -22
  238. data/examples/stories/game-of-life/life.rb +0 -3
  239. data/examples/stories/game-of-life/life/game.rb +0 -23
  240. data/examples/stories/game-of-life/life/grid.rb +0 -43
  241. data/examples/stories/helper.rb +0 -9
  242. data/examples/stories/steps/addition_steps.rb +0 -18
  243. data/lib/spec/adapters.rb +0 -1
  244. data/lib/spec/adapters/ruby_engine.rb +0 -26
  245. data/lib/spec/adapters/ruby_engine/mri.rb +0 -8
  246. data/lib/spec/adapters/ruby_engine/rubinius.rb +0 -8
  247. data/lib/spec/extensions.rb +0 -4
  248. data/lib/spec/extensions/class.rb +0 -24
  249. data/lib/spec/extensions/metaclass.rb +0 -7
  250. data/lib/spec/extensions/object.rb +0 -6
  251. data/spec/spec/adapters/ruby_engine_spec.rb +0 -16
  252. data/spec/spec/example/configuration_spec.rb +0 -296
  253. data/spec/spec/example/example_runner_spec.rb +0 -194
  254. data/spec/spec/extensions/main_spec.rb +0 -71
  255. data/stories/all.rb +0 -5
  256. data/stories/configuration/before_blocks.story +0 -21
  257. data/stories/configuration/stories.rb +0 -7
  258. data/stories/example_groups/stories.rb +0 -7
  259. data/stories/helper.rb +0 -6
  260. data/stories/interop/stories.rb +0 -7
  261. data/stories/mock_framework_integration/stories.rb +0 -7
  262. data/stories/pending_stories/README +0 -3
  263. data/stories/resources/spec/before_blocks_example.rb +0 -32
  264. data/stories/resources/spec/spec_with_flexmock.rb +0 -18
  265. data/stories/resources/steps/running_rspec.rb +0 -50
  266. data/stories/resources/stories/failing_story.rb +0 -15
  267. data/stories/stories/multiline_steps.story +0 -23
  268. data/stories/stories/steps/multiline_steps.rb +0 -13
  269. data/stories/stories/stories.rb +0 -6
@@ -1,13 +1,11 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
3
  class LiarLiarPantsOnFire
4
- include Spec::MetaClass
5
- extend Spec::MetaClass
6
- def respond_to?(sym)
4
+ def respond_to?(sym, incl_private=false)
7
5
  true
8
6
  end
9
7
 
10
- def self.respond_to?(sym)
8
+ def self.respond_to?(sym, incl_private=false)
11
9
  true
12
10
  end
13
11
  end
@@ -28,6 +26,7 @@ describe 'should_receive' do
28
26
  end
29
27
 
30
28
  it 'should cleanup after itself' do
31
- LiarLiarPantsOnFire.metaclass.instance_methods.should_not include("something")
29
+ (class << LiarLiarPantsOnFire; self; end).instance_methods.should_not include("something")
32
30
  end
33
31
  end
32
+
@@ -1,16 +1,18 @@
1
1
  require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
2
 
3
- class BaseClass
4
- end
3
+ module BugReport496
4
+ class BaseClass
5
+ end
5
6
 
6
- class SubClass < BaseClass
7
- end
7
+ class SubClass < BaseClass
8
+ end
8
9
 
9
- describe "a message expectation on a base class object" do
10
- it "should correctly pick up message sent to it subclass" do
11
- pending("fix for http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/496") do
12
- BaseClass.should_receive(:new).once
13
- SubClass.new
10
+ describe "a message expectation on a base class object" do
11
+ it "should correctly pick up message sent to it subclass" do
12
+ pending("fix for http://rspec.lighthouseapp.com/projects/5645/tickets/496") do
13
+ BaseClass.should_receive(:new).once
14
+ SubClass.new
15
+ end
14
16
  end
15
17
  end
16
18
  end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ module BugReport600
4
+ class ExampleClass
5
+ def self.method_that_uses_define_method
6
+ define_method "defined_method" do |attributes|
7
+ load_address(address, attributes)
8
+ end
9
+ end
10
+ end
11
+
12
+ describe "stubbing a class method" do
13
+ it "should work" do
14
+ ExampleClass.should_receive(:define_method).with("defined_method")
15
+ ExampleClass.method_that_uses_define_method
16
+ end
17
+
18
+ it "should restore the original method" do
19
+ ExampleClass.method_that_uses_define_method
20
+ end
21
+ end
22
+ end
@@ -27,6 +27,32 @@ module Spec
27
27
  hash_including(:a => anything, :b => 2).should == {:a => "1", :b => 2}
28
28
  end
29
29
  end
30
+
31
+ describe "when passed only keys or keys mixed with key/value pairs" do
32
+ it "should match if the key is present" do
33
+ hash_including(:a).should == {:a => 1, :b => 2}
34
+ end
35
+
36
+ it "should match if more keys are present" do
37
+ hash_including(:a, :b).should == {:a => 1, :b => 2, :c => 3}
38
+ end
39
+
40
+ it "should match a string against a given key" do
41
+ hash_including(:a).should == {:a => "1", :b => 2}
42
+ end
43
+
44
+ it "should match if passed one key and one key/value pair" do
45
+ hash_including(:a, :b => 2).should == {:a => 1, :b => 2}
46
+ end
47
+
48
+ it "should match if passed many keys and one key/value pair" do
49
+ hash_including(:a, :b, :c => 3).should == {:a => 1, :b => 2, :c => 3, :d => 4}
50
+ end
51
+
52
+ it "should match if passed many keys and many key/value pairs" do
53
+ hash_including(:a, :b, :c => 3, :e => 5).should == {:a => 1, :b => 2, :c => 3, :d => 4, :e => 5}
54
+ end
55
+ end
30
56
  end
31
57
 
32
58
  describe "failing" do
@@ -34,11 +60,22 @@ module Spec
34
60
  hash_including(:a => 1).should_not == 1
35
61
  end
36
62
 
37
-
38
63
  it "should not match a hash with a missing key" do
39
64
  hash_including(:a => 1).should_not == {:b => 2}
40
65
  end
41
-
66
+
67
+ it "should not match a hash with a missing key" do
68
+ hash_including(:a).should_not == {:b => 2}
69
+ end
70
+
71
+ it "should not match an empty hash with a given key" do
72
+ hash_including(:a).should_not == {}
73
+ end
74
+
75
+ it "should not match a hash with a missing key when one pair is matching" do
76
+ hash_including(:a, :b => 2).should_not == {:b => 2}
77
+ end
78
+
42
79
  it "should not match a hash with an incorrect value" do
43
80
  hash_including(:a => 1, :b => 2).should_not == {:a => 1, :b => 3}
44
81
  end
@@ -0,0 +1,67 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ module Spec
4
+ module Mocks
5
+ module ArgumentConstraints
6
+ describe HashNotIncludingConstraint do
7
+
8
+ it "should describe itself properly" do
9
+ HashNotIncludingConstraint.new(:a => 5).description.should == "hash_not_including(:a=>5)"
10
+ end
11
+
12
+ describe "passing" do
13
+ it "should match a hash without the specified key" do
14
+ hash_not_including(:c).should == {:a => 1, :b => 2}
15
+ end
16
+
17
+ it "should match a hash with the specified key, but different value" do
18
+ hash_not_including(:b => 3).should == {:a => 1, :b => 2}
19
+ end
20
+
21
+ it "should match a hash without the specified key, given as anything()" do
22
+ hash_not_including(:c => anything).should == {:a => 1, :b => 2}
23
+ end
24
+
25
+ it "should match an empty hash" do
26
+ hash_not_including(:a).should == {}
27
+ end
28
+
29
+ it "should match a hash without any of the specified keys" do
30
+ hash_not_including(:a, :b, :c).should == { :d => 7}
31
+ end
32
+
33
+ end
34
+
35
+ describe "failing" do
36
+ it "should not match a non-hash" do
37
+ hash_not_including(:a => 1).should_not == 1
38
+ end
39
+
40
+ it "should not match a hash with a specified key" do
41
+ hash_not_including(:b).should_not == {:b => 2}
42
+ end
43
+
44
+ it "should not match a hash with the specified key/value pair" do
45
+ hash_not_including(:b => 2).should_not == {:a => 1, :b => 2}
46
+ end
47
+
48
+ it "should not match a hash with the specified key" do
49
+ hash_not_including(:a, :b => 3).should_not == {:a => 1, :b => 2}
50
+ end
51
+
52
+ it "should not match a hash with one of the specified keys" do
53
+ hash_not_including(:a, :b).should_not == {:b => 2}
54
+ end
55
+
56
+ it "should not match a hash with some of the specified keys" do
57
+ hash_not_including(:a, :b, :c).should_not == {:a => 1, :b => 2}
58
+ end
59
+
60
+ it "should not match a hash with one key/value pair included" do
61
+ hash_not_including(:a, :b, :c, :d => 7).should_not == { :d => 7}
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -3,7 +3,6 @@ require File.dirname(__FILE__) + '/../../spec_helper'
3
3
  module Spec
4
4
  module Mocks
5
5
  describe Mock do
6
-
7
6
  before(:each) do
8
7
  @mock = mock("test mock")
9
8
  end
@@ -227,7 +226,7 @@ module Spec
227
226
  it "should yield 0 args to blocks that take a variable number of arguments" do
228
227
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield
229
228
  a = nil
230
- @mock.yield_back {|*a|}
229
+ @mock.yield_back {|*x| a = x}
231
230
  a.should == []
232
231
  @mock.rspec_verify
233
232
  end
@@ -245,7 +244,7 @@ module Spec
245
244
  it "should yield one arg to blocks that take a variable number of arguments" do
246
245
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield(99)
247
246
  a = nil
248
- @mock.yield_back {|*a|}
247
+ @mock.yield_back {|*x| a = x}
249
248
  a.should == [99]
250
249
  @mock.rspec_verify
251
250
  end
@@ -264,7 +263,7 @@ module Spec
264
263
  it "should yield many args to blocks that take a variable number of arguments" do
265
264
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield(99, 27, "go")
266
265
  a = nil
267
- @mock.yield_back {|*a|}
266
+ @mock.yield_back {|*x| a = x}
268
267
  a.should == [99, 27, "go"]
269
268
  @mock.rspec_verify
270
269
  end
@@ -283,7 +282,7 @@ module Spec
283
282
  it "should yield single value" do
284
283
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield(99)
285
284
  a = nil
286
- @mock.yield_back {|a|}
285
+ @mock.yield_back {|x| a = x}
287
286
  a.should == 99
288
287
  @mock.rspec_verify
289
288
  end
@@ -302,7 +301,7 @@ module Spec
302
301
  it "should yield two values" do
303
302
  @mock.should_receive(:yield_back).with(no_args()).once.and_yield('wha', 'zup')
304
303
  a, b = nil
305
- @mock.yield_back {|a,b|}
304
+ @mock.yield_back {|x,y| a=x; b=y}
306
305
  a.should == 'wha'
307
306
  b.should == 'zup'
308
307
  @mock.rspec_verify
@@ -6,7 +6,7 @@ module Spec
6
6
  describe "an expectation set on nil" do
7
7
 
8
8
  it "should issue a warning with file and line number information" do
9
- expected_warning = "An expectation of :foo was set on nil. Called from #{__FILE__}:#{__LINE__+3}. Use allow_message_expectations_on_nil to disable warnings."
9
+ expected_warning = %r%An expectation of :foo was set on nil. Called from #{__FILE__}:#{__LINE__+3}(:in `block \(2 levels\) in <module:Mocks>')?. Use allow_message_expectations_on_nil to disable warnings.%
10
10
  Kernel.should_receive(:warn).with(expected_warning)
11
11
 
12
12
  nil.should_receive(:foo)
@@ -43,7 +43,7 @@ module Spec
43
43
  nil.foo
44
44
  end
45
45
 
46
- example_group.run.should be_true
46
+ example_group.run(Spec::Runner.options).should be_true
47
47
 
48
48
  end
49
49
 
@@ -26,13 +26,28 @@ module Spec
26
26
  @mock.random_call(false)
27
27
  end
28
28
 
29
- it "should accept fixnum as an_instance_of(Numeric)" do
30
- @mock.should_receive(:random_call).with(an_instance_of(Numeric))
29
+ it "should accept fixnum as kind_of(Numeric)" do
30
+ @mock.should_receive(:random_call).with(kind_of(Numeric))
31
31
  @mock.random_call(1)
32
32
  end
33
33
 
34
34
  it "should accept float as an_instance_of(Numeric)" do
35
- @mock.should_receive(:random_call).with(an_instance_of(Numeric))
35
+ @mock.should_receive(:random_call).with(kind_of(Numeric))
36
+ @mock.random_call(1.5)
37
+ end
38
+
39
+ it "accepts fixnum as instance_of(Fixnum)" do
40
+ @mock.should_receive(:random_call).with(instance_of(Fixnum))
41
+ @mock.random_call(1)
42
+ end
43
+
44
+ it "should NOT accept fixnum as instance_of(Numeric)" do
45
+ @mock.should_not_receive(:random_call).with(instance_of(Numeric))
46
+ @mock.random_call(1)
47
+ end
48
+
49
+ it "should NOT accept float as instance_of(Numeric)" do
50
+ @mock.should_not_receive(:random_call).with(instance_of(Numeric))
36
51
  @mock.random_call(1.5)
37
52
  end
38
53
 
@@ -137,6 +137,12 @@ module Spec
137
137
  @stub.foo("bar")
138
138
  @stub.foo("baz")
139
139
  end
140
+
141
+ it "calculates return value by executing block passed to #and_return" do
142
+ @mock.stub!(:something).with("a","b","c").and_return { |a,b,c| c+b+a }
143
+ @mock.something("a","b","c").should == "cba"
144
+ @mock.rspec_verify
145
+ end
140
146
  end
141
147
 
142
148
  describe "A method stub with args" do
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ module Spec
4
+ module Mocks
5
+ describe "Example with stubbed and then called message" do
6
+ it "should fail if the message is expected and then subsequently not called again" do
7
+ mock_obj = mock("mock", :msg => nil)
8
+ mock_obj.msg
9
+ mock_obj.should_receive(:msg)
10
+ lambda { mock_obj.rspec_verify }.should raise_error(Spec::Mocks::MockExpectationError)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -11,19 +11,19 @@ module Spec
11
11
  end
12
12
 
13
13
  it "should run directory" do
14
- file = File.dirname(__FILE__) + '/../../../examples/pure'
15
- run_with(OptionParser.parse([file,"-p","**/*.rb"], @err, @out))
14
+ file = File.dirname(__FILE__) + '/../../../examples/passing'
15
+ run_with(OptionParser.parse([file,"-p","**/*_spec.rb,**/*_example.rb"], @err, @out))
16
16
 
17
17
  @out.rewind
18
18
  @out.read.should =~ /\d+ examples, 0 failures, 3 pending/n
19
19
  end
20
20
 
21
21
  it "should run file" do
22
- file = File.dirname(__FILE__) + '/../../../failing_examples/predicate_example.rb'
22
+ file = File.dirname(__FILE__) + '/../../../examples/failing/predicate_example.rb'
23
23
  run_with(OptionParser.parse([file], @err, @out))
24
24
 
25
25
  @out.rewind
26
- @out.read.should =~ /2 examples, 1 failure/n
26
+ @out.read.should =~ /3 examples, 2 failures/n
27
27
  end
28
28
 
29
29
  it "should raise when file does not exist" do
@@ -0,0 +1,301 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
+
3
+ module Spec
4
+ module Runner
5
+ describe Configuration do
6
+ with_sandboxed_options do
7
+ with_sandboxed_config do
8
+ describe "#mock_with" do
9
+ it "should default mock framework to rspec" do
10
+ config.mock_framework.should =~ /\/adapters\/mock_frameworks\/rspec$/
11
+ end
12
+
13
+ it "should set rspec mocking explicitly" do
14
+ config.mock_with(:rspec)
15
+ config.mock_framework.should =~ /\/adapters\/mock_frameworks\/rspec$/
16
+ end
17
+
18
+ it "should set mocha" do
19
+ config.mock_with(:mocha)
20
+ config.mock_framework.should =~ /\/adapters\/mock_frameworks\/mocha$/
21
+ end
22
+
23
+ it "should set flexmock" do
24
+ config.mock_with(:flexmock)
25
+ config.mock_framework.should =~ /\/adapters\/mock_frameworks\/flexmock$/
26
+ end
27
+
28
+ it "should set rr" do
29
+ config.mock_with(:rr)
30
+ config.mock_framework.should =~ /\/adapters\/mock_frameworks\/rr$/
31
+ end
32
+
33
+ it "should set an arbitrary adapter module" do
34
+ adapter = Module.new
35
+ config.mock_with(adapter)
36
+ config.mock_framework.should == adapter
37
+ end
38
+ end
39
+
40
+ describe "#include" do
41
+
42
+ before(:each) do
43
+ @example_group_class = Class.new(ExampleGroup) {}
44
+ Spec::Example::ExampleGroupFactory.register(:foobar, @example_group_class)
45
+ end
46
+
47
+ it "should include the submitted module in ExampleGroup subclasses" do
48
+ mod = Module.new
49
+ config.include mod
50
+ Class.new(@example_group_class).included_modules.should include(mod)
51
+ end
52
+
53
+ it "should scope modules to be included for a specific type" do
54
+ mod = Module.new
55
+ config.include mod, :type => :foobar
56
+ Class.new(@example_group_class).included_modules.should include(mod)
57
+ end
58
+
59
+ it "should not include modules in a type they are not intended for" do
60
+ mod = Module.new
61
+ @other_example_group_class = Class.new(ExampleGroup)
62
+ Spec::Example::ExampleGroupFactory.register(:baz, @other_example_group_class)
63
+
64
+ config.include mod, :type => :foobar
65
+
66
+ Class.new(@other_example_group_class).included_modules.should_not include(mod)
67
+ end
68
+
69
+ it "accepts an Array of types" do
70
+ mod = Module.new
71
+ @other_example_group_class = Class.new(ExampleGroup)
72
+ Spec::Example::ExampleGroupFactory.register(:baz, @other_example_group_class)
73
+
74
+ config.include mod, :type => [:foobar, :baz]
75
+
76
+ Class.new(@example_group_class).included_modules.should include(mod)
77
+ Class.new(@other_example_group_class).included_modules.should include(mod)
78
+ end
79
+
80
+ end
81
+
82
+ describe "#extend" do
83
+
84
+ before(:each) do
85
+ @example_group_class = Class.new(ExampleGroup) {}
86
+ Spec::Example::ExampleGroupFactory.register(:foobar, @example_group_class)
87
+ end
88
+
89
+ it "should extend all groups" do
90
+ mod = Module.new
91
+ ExampleGroup.should_receive(:extend).with(mod)
92
+ Spec::Runner.configuration.extend mod
93
+ end
94
+
95
+ it "should extend specified groups" do
96
+ mod = Module.new
97
+ @example_group_class.should_receive(:extend).with(mod)
98
+ Spec::Runner.configuration.extend mod, :type => :foobar
99
+ end
100
+
101
+ it "should not extend non-specified groups" do
102
+ @other_example_group_class = Class.new(ExampleGroup)
103
+ Spec::Example::ExampleGroupFactory.register(:baz, @other_example_group_class)
104
+
105
+ mod = Module.new
106
+ @other_example_group_class.should_not_receive(:extend)
107
+
108
+ Spec::Runner.configuration.extend mod, :type => :foobar
109
+ end
110
+
111
+ end
112
+ end
113
+
114
+ describe "ordering methods: " do
115
+
116
+ before(:each) do
117
+ @special_example_group = Class.new(ExampleGroup).describe("special_example_group")
118
+ @special_child_example_group = Class.new(@special_example_group).describe("special_child_example_group")
119
+ @nonspecial_example_group = Class.new(ExampleGroup).describe("nonspecial_example_group")
120
+ Spec::Example::ExampleGroupFactory.register(:special, @special_example_group)
121
+ Spec::Example::ExampleGroupFactory.register(:special_child, @special_child_example_group)
122
+ Spec::Example::ExampleGroupFactory.register(:non_special, @nonspecial_example_group)
123
+ @example_group = @special_child_example_group.describe "Special Example Group"
124
+ @unselected_example_group = Class.new(@nonspecial_example_group).describe "Non Special Example Group"
125
+ end
126
+
127
+ describe "#prepend_before" do
128
+ it "prepends the before block on all instances of the passed in type" do
129
+ order = []
130
+ config.prepend_before(:all) do
131
+ order << :prepend__before_all
132
+ end
133
+ config.prepend_before(:all, :type => :special) do
134
+ order << :special_prepend__before_all
135
+ end
136
+ config.prepend_before(:all, :type => :special_child) do
137
+ order << :special_child_prepend__before_all
138
+ end
139
+ config.prepend_before(:each) do
140
+ order << :prepend__before_each
141
+ end
142
+ config.prepend_before(:each, :type => :special) do
143
+ order << :special_prepend__before_each
144
+ end
145
+ config.prepend_before(:each, :type => :special_child) do
146
+ order << :special_child_prepend__before_each
147
+ end
148
+ config.prepend_before(:all, :type => :non_special) do
149
+ order << :special_prepend__before_all
150
+ end
151
+ config.prepend_before(:each, :type => :non_special) do
152
+ order << :special_prepend__before_each
153
+ end
154
+ @example_group.it "calls prepend_before" do
155
+ end
156
+
157
+ @example_group.run(options)
158
+ order.should == [
159
+ :prepend__before_all,
160
+ :special_prepend__before_all,
161
+ :special_child_prepend__before_all,
162
+ :prepend__before_each,
163
+ :special_prepend__before_each,
164
+ :special_child_prepend__before_each
165
+ ]
166
+ end
167
+ end
168
+
169
+ describe "#append_before" do
170
+
171
+ it "calls append_before on the type" do
172
+ order = []
173
+ config.append_before(:all) do
174
+ order << :append_before_all
175
+ end
176
+ config.append_before(:all, :type => :special) do
177
+ order << :special_append_before_all
178
+ end
179
+ config.append_before(:all, :type => :special_child) do
180
+ order << :special_child_append_before_all
181
+ end
182
+ config.append_before(:each) do
183
+ order << :append_before_each
184
+ end
185
+ config.append_before(:each, :type => :special) do
186
+ order << :special_append_before_each
187
+ end
188
+ config.append_before(:each, :type => :special_child) do
189
+ order << :special_child_append_before_each
190
+ end
191
+ config.append_before(:all, :type => :non_special) do
192
+ order << :special_append_before_all
193
+ end
194
+ config.append_before(:each, :type => :non_special) do
195
+ order << :special_append_before_each
196
+ end
197
+ @example_group.it "calls append_before" do
198
+ end
199
+
200
+ @example_group.run(options)
201
+ order.should == [
202
+ :append_before_all,
203
+ :special_append_before_all,
204
+ :special_child_append_before_all,
205
+ :append_before_each,
206
+ :special_append_before_each,
207
+ :special_child_append_before_each
208
+ ]
209
+ end
210
+ end
211
+
212
+ describe "#prepend_after" do
213
+
214
+ it "prepends the after block on all instances of the passed in type" do
215
+ order = []
216
+ config.prepend_after(:all) do
217
+ order << :prepend__after_all
218
+ end
219
+ config.prepend_after(:all, :type => :special) do
220
+ order << :special_prepend__after_all
221
+ end
222
+ config.prepend_after(:all, :type => :special) do
223
+ order << :special_child_prepend__after_all
224
+ end
225
+ config.prepend_after(:each) do
226
+ order << :prepend__after_each
227
+ end
228
+ config.prepend_after(:each, :type => :special) do
229
+ order << :special_prepend__after_each
230
+ end
231
+ config.prepend_after(:each, :type => :special) do
232
+ order << :special_child_prepend__after_each
233
+ end
234
+ config.prepend_after(:all, :type => :non_special) do
235
+ order << :special_prepend__after_all
236
+ end
237
+ config.prepend_after(:each, :type => :non_special) do
238
+ order << :special_prepend__after_each
239
+ end
240
+ @example_group.it "calls prepend_after" do
241
+ end
242
+
243
+ @example_group.run(options)
244
+ order.should == [
245
+ :special_child_prepend__after_each,
246
+ :special_prepend__after_each,
247
+ :prepend__after_each,
248
+ :special_child_prepend__after_all,
249
+ :special_prepend__after_all,
250
+ :prepend__after_all
251
+ ]
252
+ end
253
+ end
254
+
255
+ describe "#append_after" do
256
+
257
+ it "calls append_after on the type" do
258
+ order = []
259
+ config.append_after(:all) do
260
+ order << :append__after_all
261
+ end
262
+ config.append_after(:all, :type => :special) do
263
+ order << :special_append__after_all
264
+ end
265
+ config.append_after(:all, :type => :special_child) do
266
+ order << :special_child_append__after_all
267
+ end
268
+ config.append_after(:each) do
269
+ order << :append__after_each
270
+ end
271
+ config.append_after(:each, :type => :special) do
272
+ order << :special_append__after_each
273
+ end
274
+ config.append_after(:each, :type => :special_child) do
275
+ order << :special_child_append__after_each
276
+ end
277
+ config.append_after(:all, :type => :non_special) do
278
+ order << :non_special_append_after_all
279
+ end
280
+ config.append_after(:each, :type => :non_special) do
281
+ order << :non_special_append_after_each
282
+ end
283
+ @example_group.it "calls append_after" do
284
+ end
285
+
286
+ @example_group.run(options)
287
+ order.should == [
288
+ :special_child_append__after_each,
289
+ :special_append__after_each,
290
+ :append__after_each,
291
+ :special_child_append__after_all,
292
+ :special_append__after_all,
293
+ :append__after_all
294
+ ]
295
+ end
296
+ end
297
+ end
298
+ end
299
+ end
300
+ end
301
+ end