rspec 1.1.12 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. data/.autotest +2 -1
  2. data/.document +7 -0
  3. data/History.txt +58 -0
  4. data/License.txt +1 -1
  5. data/Manifest.txt +45 -82
  6. data/README.txt +3 -6
  7. data/Rakefile +33 -13
  8. data/Ruby1.9.markdown +32 -0
  9. data/TODO.txt +10 -4
  10. data/Upgrade.markdown +63 -0
  11. data/bin/spec +1 -1
  12. data/cucumber.yml +3 -0
  13. data/examples/failing/{failing_autogenerated_docstrings_example.rb → failing_implicit_docstrings_example.rb} +0 -0
  14. data/examples/failing/pending_example.rb +9 -0
  15. data/examples/failing/spec_helper.rb +1 -1
  16. data/examples/passing/{custom_expectation_matchers.rb → custom_matchers.rb} +0 -0
  17. data/examples/passing/filtered_formatter.rb +18 -0
  18. data/examples/passing/filtered_formatter_example.rb +31 -0
  19. data/examples/passing/implicit_docstrings_example.rb +18 -0
  20. data/examples/passing/spec_helper.rb +1 -1
  21. data/examples/ruby1.9.compatibility/access_to_constants_spec.rb +17 -18
  22. data/features/before_and_after_blocks/before_and_after_blocks.feature +4 -4
  23. data/features/example_groups/example_group_with_should_methods.feature +1 -1
  24. data/features/example_groups/{autogenerated_docstrings.feature → implicit_docstrings.feature} +7 -9
  25. data/features/example_groups/nested_groups.feature +1 -1
  26. data/features/heckle/heckle.feature +56 -0
  27. data/features/interop/examples_and_tests_together.feature +1 -1
  28. data/features/interop/test_but_not_test_unit.feature +1 -1
  29. data/features/interop/test_case_with_should_methods.feature +1 -1
  30. data/features/matchers/create_matcher.feature +115 -0
  31. data/features/mock_framework_integration/use_flexmock.feature +22 -4
  32. data/features/mock_framework_integration/use_mocha.feature +27 -0
  33. data/features/mock_framework_integration/use_rr.feature +27 -0
  34. data/features/mocks/mix_stubs_and_mocks.feature +22 -0
  35. data/features/pending/pending_examples.feature +81 -0
  36. data/features/step_definitions/running_rspec.rb +5 -3
  37. data/features/support/env.rb +1 -1
  38. data/features/support/matchers/smart_match.rb +2 -2
  39. data/lib/autotest/rspec.rb +1 -1
  40. data/lib/spec.rb +1 -1
  41. data/lib/{adapters → spec/adapters}/mock_frameworks/flexmock.rb +0 -0
  42. data/lib/{adapters → spec/adapters}/mock_frameworks/mocha.rb +0 -0
  43. data/lib/{adapters → spec/adapters}/mock_frameworks/rr.rb +0 -0
  44. data/lib/{adapters → spec/adapters}/mock_frameworks/rspec.rb +0 -1
  45. data/lib/spec/autorun.rb +3 -0
  46. data/lib/spec/dsl.rb +3 -1
  47. data/lib/spec/dsl/matchers.rb +13 -0
  48. data/lib/spec/example.rb +4 -0
  49. data/lib/spec/example/before_and_after_hooks.rb +5 -20
  50. data/lib/spec/example/errors.rb +3 -3
  51. data/lib/spec/example/example_description.rb +15 -0
  52. data/lib/spec/example/example_group.rb +0 -15
  53. data/lib/spec/example/example_group_factory.rb +34 -46
  54. data/lib/spec/example/example_group_hierarchy.rb +53 -0
  55. data/lib/spec/example/example_group_methods.rb +101 -211
  56. data/lib/spec/example/example_methods.rb +61 -81
  57. data/lib/spec/example/module_reopening_fix.rb +23 -1
  58. data/lib/spec/example/pending.rb +3 -2
  59. data/lib/spec/example/predicate_matchers.rb +47 -0
  60. data/lib/spec/example/subject.rb +91 -0
  61. data/lib/spec/expectations.rb +1 -1
  62. data/lib/spec/expectations/differs/default.rb +0 -1
  63. data/lib/spec/expectations/extensions.rb +0 -1
  64. data/lib/spec/expectations/handler.rb +13 -6
  65. data/lib/spec/interop/test.rb +5 -0
  66. data/lib/spec/interop/test/unit/testcase.rb +5 -22
  67. data/lib/spec/matchers.rb +22 -8
  68. data/lib/spec/matchers/be.rb +4 -9
  69. data/lib/spec/matchers/be_close.rb +20 -5
  70. data/lib/spec/matchers/be_instance_of.rb +45 -0
  71. data/lib/spec/matchers/be_kind_of.rb +45 -0
  72. data/lib/spec/matchers/change.rb +8 -6
  73. data/lib/spec/matchers/compatibility.rb +14 -0
  74. data/lib/spec/matchers/eql.rb +24 -6
  75. data/lib/spec/matchers/equal.rb +24 -6
  76. data/lib/spec/matchers/exist.rb +21 -5
  77. data/lib/spec/matchers/extensions/instance_exec.rb +25 -0
  78. data/lib/spec/matchers/generated_descriptions.rb +2 -2
  79. data/lib/spec/matchers/has.rb +28 -11
  80. data/lib/spec/matchers/have.rb +2 -2
  81. data/lib/spec/matchers/include.rb +2 -2
  82. data/lib/spec/matchers/match.rb +25 -7
  83. data/lib/spec/matchers/match_array.rb +3 -3
  84. data/lib/spec/matchers/matcher.rb +51 -0
  85. data/lib/spec/matchers/method_missing.rb +2 -2
  86. data/lib/spec/matchers/operator_matcher.rb +12 -5
  87. data/lib/spec/matchers/raise_error.rb +3 -3
  88. data/lib/spec/matchers/respond_to.rb +3 -3
  89. data/lib/spec/matchers/satisfy.rb +7 -7
  90. data/lib/spec/matchers/throw_symbol.rb +3 -5
  91. data/lib/spec/mocks.rb +3 -3
  92. data/lib/spec/mocks/argument_expectation.rb +15 -15
  93. data/lib/spec/mocks/{argument_constraints.rb → argument_matchers.rb} +19 -23
  94. data/lib/spec/mocks/error_generator.rb +5 -8
  95. data/lib/spec/mocks/framework.rb +1 -1
  96. data/lib/spec/mocks/message_expectation.rb +5 -13
  97. data/lib/spec/mocks/mock.rb +4 -5
  98. data/lib/spec/mocks/proxy.rb +9 -5
  99. data/lib/spec/mocks/spec_methods.rb +10 -1
  100. data/lib/spec/rake/spectask.rb +0 -1
  101. data/lib/spec/runner.rb +6 -28
  102. data/lib/spec/runner/configuration.rb +3 -3
  103. data/lib/spec/runner/drb_command_line.rb +2 -1
  104. data/lib/spec/runner/example_group_runner.rb +3 -2
  105. data/lib/spec/runner/formatter/base_text_formatter.rb +34 -19
  106. data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +3 -5
  107. data/lib/spec/runner/formatter/html_formatter.rb +2 -3
  108. data/lib/spec/runner/formatter/nested_text_formatter.rb +7 -25
  109. data/lib/spec/runner/formatter/progress_bar_formatter.rb +1 -1
  110. data/lib/spec/runner/formatter/snippet_extractor.rb +1 -1
  111. data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -7
  112. data/lib/spec/runner/heckle_runner.rb +3 -6
  113. data/lib/spec/runner/heckle_runner_unsupported.rb +1 -1
  114. data/lib/spec/runner/option_parser.rb +19 -21
  115. data/lib/spec/runner/options.rb +32 -27
  116. data/lib/spec/runner/reporter.rb +8 -9
  117. data/lib/spec/test/unit.rb +10 -0
  118. data/lib/spec/version.rb +2 -2
  119. data/{features/support → resources}/helpers/cmdline.rb +2 -2
  120. data/resources/rake/verify_rcov.rake +1 -1
  121. data/resources/spec/example_group_with_should_methods.rb +1 -1
  122. data/resources/spec/simple_spec.rb +1 -1
  123. data/resources/test/spec_and_test_together.rb +2 -3
  124. data/resources/test/spec_including_test_but_not_unit.rb +1 -1
  125. data/resources/test/test_case_with_should_methods.rb +2 -3
  126. data/spec/autotest/autotest_helper.rb +0 -1
  127. data/spec/autotest/rspec_spec.rb +95 -98
  128. data/spec/spec/dsl/main_spec.rb +3 -3
  129. data/spec/spec/dsl/matchers_spec.rb +25 -0
  130. data/spec/spec/example/example_group_class_definition_spec.rb +14 -15
  131. data/spec/spec/example/example_group_factory_spec.rb +31 -44
  132. data/spec/spec/example/example_group_methods_spec.rb +86 -52
  133. data/spec/spec/example/example_group_spec.rb +32 -79
  134. data/spec/spec/example/example_matcher_spec.rb +10 -10
  135. data/spec/spec/example/example_methods_spec.rb +108 -242
  136. data/spec/spec/example/nested_example_group_spec.rb +2 -2
  137. data/spec/spec/example/pending_module_spec.rb +66 -41
  138. data/spec/spec/example/shared_example_group_spec.rb +4 -4
  139. data/spec/spec/{matchers → expectations}/handler_spec.rb +52 -4
  140. data/spec/spec/interop/test/unit/resources/spec_that_fails.rb +2 -2
  141. data/spec/spec/interop/test/unit/resources/spec_that_passes.rb +2 -2
  142. data/spec/spec/interop/test/unit/resources/spec_with_errors.rb +2 -2
  143. data/spec/spec/interop/test/unit/resources/spec_with_options_hash.rb +2 -2
  144. data/spec/spec/interop/test/unit/resources/test_case_that_fails.rb +2 -2
  145. data/spec/spec/interop/test/unit/resources/test_case_that_passes.rb +2 -2
  146. data/spec/spec/interop/test/unit/resources/test_case_with_errors.rb +2 -2
  147. data/spec/spec/interop/test/unit/resources/testsuite_adapter_spec_with_test_unit.rb +2 -2
  148. data/spec/spec/interop/test/unit/testcase_spec.rb +0 -4
  149. data/spec/spec/matchers/be_close_spec.rb +1 -1
  150. data/spec/spec/matchers/be_instance_of_spec.rb +29 -0
  151. data/spec/spec/matchers/be_kind_of_spec.rb +29 -0
  152. data/spec/spec/matchers/change_spec.rb +20 -0
  153. data/spec/spec/matchers/compatibility_spec.rb +34 -0
  154. data/spec/spec/matchers/description_generation_spec.rb +0 -12
  155. data/spec/spec/matchers/eql_spec.rb +2 -2
  156. data/spec/spec/matchers/equal_spec.rb +2 -2
  157. data/spec/spec/matchers/exist_spec.rb +8 -4
  158. data/spec/spec/matchers/have_spec.rb +4 -4
  159. data/spec/spec/matchers/match_spec.rb +2 -2
  160. data/spec/spec/matchers/matcher_methods_spec.rb +1 -1
  161. data/spec/spec/matchers/matcher_spec.rb +97 -0
  162. data/spec/spec/matchers/throw_symbol_spec.rb +8 -8
  163. data/spec/spec/mocks/{bug_report_496.rb → bug_report_496_spec.rb} +0 -0
  164. data/spec/spec/mocks/{failing_mock_argument_constraints_spec.rb → failing_argument_matchers_spec.rb} +2 -2
  165. data/spec/spec/mocks/hash_including_matcher_spec.rb +4 -4
  166. data/spec/spec/mocks/hash_not_including_matcher_spec.rb +3 -3
  167. data/spec/spec/mocks/mock_spec.rb +27 -2
  168. data/spec/spec/mocks/nil_expectation_warning_spec.rb +1 -1
  169. data/spec/spec/mocks/partial_mock_spec.rb +18 -3
  170. data/spec/spec/mocks/{passing_mock_argument_constraints_spec.rb → passing_argument_matchers_spec.rb} +6 -6
  171. data/spec/spec/mocks/stubbed_message_expectations_spec.rb +13 -1
  172. data/spec/spec/package/bin_spec_spec.rb +2 -2
  173. data/spec/spec/runner/configuration_spec.rb +12 -12
  174. data/spec/spec/runner/drb_command_line_spec.rb +71 -73
  175. data/spec/spec/runner/formatter/base_text_formatter_spec.rb +82 -1
  176. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +8 -8
  177. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +4 -4
  178. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +8 -8
  179. data/spec/spec/runner/formatter/html_formatted-1.8.7.html +38 -26
  180. data/spec/spec/runner/formatter/html_formatted-1.9.1.html +61 -53
  181. data/spec/spec/runner/formatter/html_formatter_spec.rb +100 -48
  182. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +20 -34
  183. data/spec/spec/runner/formatter/profile_formatter_spec.rb +2 -1
  184. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +9 -6
  185. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +6 -6
  186. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +20 -20
  187. data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +38 -26
  188. data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +55 -47
  189. data/spec/spec/runner/formatter/{spec_mate_formatter_spec.rb → text_mate_formatter_spec.rb} +11 -9
  190. data/spec/spec/runner/heckle_runner_spec.rb +1 -1
  191. data/spec/spec/runner/heckler_spec.rb +1 -1
  192. data/spec/spec/runner/option_parser_spec.rb +28 -11
  193. data/spec/spec/runner/options_spec.rb +34 -0
  194. data/spec/spec/runner/reporter_spec.rb +66 -62
  195. data/spec/spec/runner/resources/utf8_encoded.rb +1 -0
  196. data/spec/spec/runner/spec_drb.opts +1 -0
  197. data/spec/spec/runner_spec.rb +7 -5
  198. data/spec/spec_helper.rb +24 -2
  199. metadata +49 -90
  200. data/examples/passing/autogenerated_docstrings_example.rb +0 -25
  201. data/examples/passing/before_and_after_example.rb +0 -40
  202. data/examples/passing/behave_as_example.rb +0 -45
  203. data/examples/passing/legacy_spec.rb +0 -11
  204. data/examples/passing/priority.txt +0 -1
  205. data/features/support/helpers/story_helper.rb +0 -16
  206. data/lib/spec/expectations/extensions/string_and_symbol.rb +0 -17
  207. data/lib/spec/runner/formatter/story/html_formatter.rb +0 -174
  208. data/lib/spec/runner/formatter/story/plain_text_formatter.rb +0 -194
  209. data/lib/spec/runner/formatter/story/progress_bar_formatter.rb +0 -42
  210. data/lib/spec/story.rb +0 -10
  211. data/lib/spec/story/extensions.rb +0 -3
  212. data/lib/spec/story/extensions/main.rb +0 -86
  213. data/lib/spec/story/extensions/regexp.rb +0 -9
  214. data/lib/spec/story/extensions/string.rb +0 -9
  215. data/lib/spec/story/given_scenario.rb +0 -14
  216. data/lib/spec/story/runner.rb +0 -57
  217. data/lib/spec/story/runner/plain_text_story_runner.rb +0 -48
  218. data/lib/spec/story/runner/scenario_collector.rb +0 -18
  219. data/lib/spec/story/runner/scenario_runner.rb +0 -54
  220. data/lib/spec/story/runner/story_mediator.rb +0 -137
  221. data/lib/spec/story/runner/story_parser.rb +0 -247
  222. data/lib/spec/story/runner/story_runner.rb +0 -74
  223. data/lib/spec/story/scenario.rb +0 -14
  224. data/lib/spec/story/step.rb +0 -70
  225. data/lib/spec/story/step_group.rb +0 -89
  226. data/lib/spec/story/step_mother.rb +0 -38
  227. data/lib/spec/story/story.rb +0 -39
  228. data/lib/spec/story/world.rb +0 -124
  229. data/resources/spec/spec_with_flexmock.rb +0 -19
  230. data/rspec.gemspec +0 -32
  231. data/spec/spec/matchers/mock_constraint_matchers_spec.rb +0 -24
  232. data/spec/spec/runner/formatter/story/html_formatter_spec.rb +0 -135
  233. data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +0 -600
  234. data/spec/spec/runner/formatter/story/progress_bar_formatter_spec.rb +0 -82
  235. data/spec/spec/spec_spec.rb +0 -21
  236. data/spec/spec/story/builders.rb +0 -46
  237. data/spec/spec/story/extensions/main_spec.rb +0 -161
  238. data/spec/spec/story/extensions_spec.rb +0 -14
  239. data/spec/spec/story/given_scenario_spec.rb +0 -27
  240. data/spec/spec/story/runner/plain_text_story_runner_spec.rb +0 -90
  241. data/spec/spec/story/runner/scenario_collector_spec.rb +0 -27
  242. data/spec/spec/story/runner/scenario_runner_spec.rb +0 -214
  243. data/spec/spec/story/runner/story_mediator_spec.rb +0 -143
  244. data/spec/spec/story/runner/story_parser_spec.rb +0 -401
  245. data/spec/spec/story/runner/story_runner_spec.rb +0 -294
  246. data/spec/spec/story/runner_spec.rb +0 -93
  247. data/spec/spec/story/scenario_spec.rb +0 -18
  248. data/spec/spec/story/step_group_spec.rb +0 -157
  249. data/spec/spec/story/step_mother_spec.rb +0 -84
  250. data/spec/spec/story/step_spec.rb +0 -272
  251. data/spec/spec/story/story_helper.rb +0 -2
  252. data/spec/spec/story/story_spec.rb +0 -84
  253. data/spec/spec/story/world_spec.rb +0 -423
  254. data/story_server/prototype/javascripts/builder.js +0 -136
  255. data/story_server/prototype/javascripts/controls.js +0 -972
  256. data/story_server/prototype/javascripts/dragdrop.js +0 -976
  257. data/story_server/prototype/javascripts/effects.js +0 -1117
  258. data/story_server/prototype/javascripts/prototype.js +0 -4140
  259. data/story_server/prototype/javascripts/rspec.js +0 -149
  260. data/story_server/prototype/javascripts/scriptaculous.js +0 -58
  261. data/story_server/prototype/javascripts/slider.js +0 -276
  262. data/story_server/prototype/javascripts/sound.js +0 -55
  263. data/story_server/prototype/javascripts/unittest.js +0 -568
  264. data/story_server/prototype/lib/server.rb +0 -24
  265. data/story_server/prototype/stories.html +0 -176
  266. data/story_server/prototype/stylesheets/rspec.css +0 -136
  267. data/story_server/prototype/stylesheets/test.css +0 -90
@@ -0,0 +1,25 @@
1
+ require 'spec/ruby'
2
+
3
+ if ::Spec::Ruby.version < "1.8.7"
4
+ # based on Bounded Spec InstanceExec (Mauricio Fernandez)
5
+ # http://eigenclass.org/hiki/bounded+space+instance_exec
6
+ class Object
7
+ module InstanceExecHelper; end
8
+ include InstanceExecHelper
9
+ def instance_exec(*args, &block)
10
+ begin
11
+ orig_critical, Thread.critical = Thread.critical, true
12
+ n = 0
13
+ n += 1 while respond_to?(method_name="__instance_exec#{n}")
14
+ InstanceExecHelper.module_eval{ define_method(method_name, &block) }
15
+ ensure
16
+ Thread.critical = orig_critical
17
+ end
18
+ begin
19
+ return send(method_name, *args)
20
+ ensure
21
+ InstanceExecHelper.module_eval{ remove_method(method_name) } rescue nil
22
+ end
23
+ end
24
+ end
25
+ end
@@ -38,11 +38,11 @@ or this:
38
38
 
39
39
  it { should matcher }
40
40
 
41
- the runner expects the matcher to have a #describe method. You should either
41
+ the runner expects the matcher to have a #description method. You should either
42
42
  add a String to the example this matcher is being used in, or give it a
43
43
  description method. Then you won't have to suffer this lengthy warning again.
44
44
  MESSAGE
45
45
  end
46
46
  end
47
47
  end
48
-
48
+
@@ -1,18 +1,35 @@
1
1
  module Spec
2
2
  module Matchers
3
- def has(sym, *args) # :nodoc:
4
- simple_matcher do |actual, matcher|
5
- matcher.failure_message = "expected ##{predicate(sym)}(#{args[0].inspect}) to return true, got false"
6
- matcher.negative_failure_message = "expected ##{predicate(sym)}(#{args[0].inspect}) to return false, got true"
7
- matcher.description = "have key #{args[0].inspect}"
8
- actual.__send__(predicate(sym), *args)
3
+
4
+ class Has
5
+
6
+ def initialize(expected, *args)
7
+ @expected, @args = expected, args
9
8
  end
10
- end
9
+
10
+ def matches?(actual)
11
+ actual.__send__(predicate(@expected), *@args)
12
+ end
13
+
14
+ def failure_message_for_should
15
+ "expected ##{predicate(@expected)}(#{@args[0].inspect}) to return true, got false"
16
+ end
17
+
18
+ def failure_message_for_should_not
19
+ "expected ##{predicate(@expected)}(#{@args[0].inspect}) to return false, got true"
20
+ end
21
+
22
+ def description
23
+ "have key #{@args[0].inspect}"
24
+ end
25
+
26
+ private
11
27
 
12
- private
13
- def predicate(sym)
14
- "#{sym.to_s.sub("have_","has_")}?".to_sym
28
+ def predicate(sym)
29
+ "#{sym.to_s.sub("have_","has_")}?".to_sym
30
+ end
31
+
15
32
  end
16
-
33
+
17
34
  end
18
35
  end
@@ -36,11 +36,11 @@ module Spec
36
36
  "expected #{@collection_name} to be a collection but it does not respond to #length or #size"
37
37
  end
38
38
 
39
- def failure_message
39
+ def failure_message_for_should
40
40
  "expected #{relative_expectation} #{@collection_name}, got #{@given}"
41
41
  end
42
42
 
43
- def negative_failure_message
43
+ def failure_message_for_should_not
44
44
  if @relativity == :exactly
45
45
  return "expected target not to have #{@expected} #{@collection_name}, got #{@given}"
46
46
  elsif @relativity == :at_most
@@ -25,11 +25,11 @@ module Spec
25
25
  true
26
26
  end
27
27
 
28
- def failure_message
28
+ def failure_message_for_should
29
29
  _message
30
30
  end
31
31
 
32
- def negative_failure_message
32
+ def failure_message_for_should_not
33
33
  _message("not ")
34
34
  end
35
35
 
@@ -1,5 +1,28 @@
1
1
  module Spec
2
2
  module Matchers
3
+ class Match
4
+ def initialize(expected)
5
+ @expected = expected
6
+ end
7
+
8
+ def matches?(actual)
9
+ @actual = actual
10
+ actual =~ @expected
11
+ end
12
+
13
+ def failure_message_for_should
14
+ return "expected #{@actual.inspect} to match #{@expected.inspect}", @expected, @actual
15
+ end
16
+
17
+ def failure_message_for_should_not
18
+ return "expected #{@actual.inspect} not to match #{@expected.inspect}", @expected, @actual
19
+ end
20
+
21
+ def description
22
+ "match #{@expected.inspect}"
23
+ end
24
+ end
25
+
3
26
 
4
27
  # :call-seq:
5
28
  # should match(regexp)
@@ -10,13 +33,8 @@ module Spec
10
33
  # == Examples
11
34
  #
12
35
  # email.should match(/^([^\s]+)((?:[-a-z0-9]+\.)+[a-z]{2,})$/i)
13
- def match(regexp)
14
- simple_matcher do |actual, matcher|
15
- matcher.failure_message = "expected #{actual.inspect} to match #{regexp.inspect}", regexp, actual
16
- matcher.negative_failure_message = "expected #{actual.inspect} not to match #{regexp.inspect}", regexp, actual
17
- matcher.description = "match #{regexp.inspect}"
18
- actual =~ regexp
19
- end
36
+ def match(expected)
37
+ Match.new(expected)
20
38
  end
21
39
  end
22
40
  end
@@ -11,10 +11,10 @@ module Spec
11
11
  @actual = actual
12
12
  @extra_items = difference_between_arrays(@actual, @expected)
13
13
  @missing_items = difference_between_arrays(@expected, @actual)
14
- @extra_items.empty? && @missing_items.empty?
14
+ @extra_items.empty? & @missing_items.empty?
15
15
  end
16
16
 
17
- def failure_message
17
+ def failure_message_for_should
18
18
  message = "expected collection contained: #{@expected.sort.inspect}\n"
19
19
  message += "actual collection contained: #{@actual.sort.inspect}\n"
20
20
  message += "the missing elements were: #{@missing_items.sort.inspect}\n" unless @missing_items.empty?
@@ -22,7 +22,7 @@ module Spec
22
22
  message
23
23
  end
24
24
 
25
- def negative_failure_message
25
+ def failure_message_for_should_not
26
26
  "Matcher does not support should_not"
27
27
  end
28
28
 
@@ -0,0 +1,51 @@
1
+ module Spec
2
+ module Matchers
3
+ class Matcher
4
+ def initialize(name, expected=nil, &block_passed_to_init)
5
+ @name = name
6
+ @expected = expected
7
+ @block = block_passed_to_init
8
+ @messages = {
9
+ :description => lambda {"#{name_to_sentence} #{expected}"},
10
+ :failure_message_for_should => lambda {|actual| "expected #{actual} to #{name_to_sentence} #{expected}"},
11
+ :failure_message_for_should_not => lambda {|actual| "expected #{actual} not to #{name_to_sentence} #{expected}"}
12
+ }
13
+ end
14
+
15
+ def matches?(actual)
16
+ @actual = actual
17
+ instance_exec @expected, &@block
18
+ instance_exec @actual, &@match_block
19
+ end
20
+
21
+ def description(&block)
22
+ cache_or_call_cached(:description, &block)
23
+ end
24
+
25
+ def failure_message_for_should(&block)
26
+ cache_or_call_cached(:failure_message_for_should, @actual, &block)
27
+ end
28
+
29
+ def failure_message_for_should_not(&block)
30
+ cache_or_call_cached(:failure_message_for_should_not, @actual, &block)
31
+ end
32
+
33
+ def match(&block)
34
+ @match_block = block
35
+ end
36
+
37
+ private
38
+
39
+ def cache_or_call_cached(key, actual=nil, &block)
40
+ block ? @messages[key] = block :
41
+ actual.nil? ? @messages[key].call :
42
+ @messages[key].call(actual)
43
+ end
44
+
45
+ def name_to_sentence
46
+ @name_to_sentence ||= @name.to_s.gsub(/_/,' ')
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -1,8 +1,8 @@
1
1
  module Spec
2
2
  module Matchers
3
3
  def method_missing(sym, *args, &block) # :nodoc:
4
- return Matchers::Be.new(sym, *args) if sym.starts_with?("be_")
5
- return has(sym, *args) if sym.starts_with?("have_")
4
+ return Matchers::Be.new(sym, *args) if sym.to_s =~ /^be_/
5
+ return Matchers::Has.new(sym, *args) if sym.to_s =~ /^have_/
6
6
  super
7
7
  end
8
8
  end
@@ -4,15 +4,16 @@ module Spec
4
4
  class OperatorMatcher
5
5
  class << self
6
6
  def registry
7
- @registry ||= Hash.new {|h,k| h[k] = {}}
7
+ @registry ||= {}
8
8
  end
9
9
 
10
10
  def register(klass, operator, matcher)
11
+ registry[klass] ||= {}
11
12
  registry[klass][operator] = matcher
12
13
  end
13
14
 
14
15
  def get(klass, operator)
15
- registry[klass][operator]
16
+ registry[klass] && registry[klass][operator]
16
17
  end
17
18
  end
18
19
 
@@ -25,9 +26,7 @@ module Spec
25
26
  if matcher = OperatorMatcher.get(@actual.class, operator)
26
27
  @actual.send(::Spec::Matchers.last_should, matcher.new(expected))
27
28
  else
28
- ::Spec::Matchers.last_matcher = self
29
- @operator, @expected = operator, expected
30
- __delegate_operator(@actual, operator, expected)
29
+ eval_match(@actual, operator, expected)
31
30
  end
32
31
  end
33
32
  end
@@ -43,6 +42,14 @@ module Spec
43
42
  def description
44
43
  "#{@operator} #{@expected.inspect}"
45
44
  end
45
+
46
+ private
47
+
48
+ def eval_match(actual, operator, expected)
49
+ ::Spec::Matchers.last_matcher = self
50
+ @operator, @expected = operator, expected
51
+ __delegate_operator(actual, operator, expected)
52
+ end
46
53
 
47
54
  end
48
55
 
@@ -31,7 +31,7 @@ module Spec
31
31
  eval_block if @raised_expected_error && @with_expected_message && @block
32
32
  end
33
33
  ensure
34
- return (@raised_expected_error && @with_expected_message) ? (@eval_block ? @eval_block_passed : true) : false
34
+ return (@raised_expected_error & @with_expected_message) ? (@eval_block ? @eval_block_passed : true) : false
35
35
  end
36
36
 
37
37
  def eval_block
@@ -55,11 +55,11 @@ module Spec
55
55
  end
56
56
  end
57
57
 
58
- def failure_message
58
+ def failure_message_for_should
59
59
  @eval_block ? @given_error.message : "expected #{expected_error}#{given_error}"
60
60
  end
61
61
 
62
- def negative_failure_message
62
+ def failure_message_for_should_not
63
63
  "expected no #{expected_error}#{given_error}"
64
64
  end
65
65
 
@@ -16,16 +16,15 @@ module Spec
16
16
  return @names_not_responded_to.empty?
17
17
  end
18
18
 
19
- def failure_message
19
+ def failure_message_for_should
20
20
  "expected #{@actual.inspect} to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}#{with_arity}"
21
21
  end
22
22
 
23
- def negative_failure_message
23
+ def failure_message_for_should_not
24
24
  "expected #{@actual.inspect} not to respond to #{@names.collect {|name| name.inspect }.join(', ')}"
25
25
  end
26
26
 
27
27
  def description
28
- # Ruby 1.9 returns the same thing for array.to_s as array.inspect, so just use array.inspect here
29
28
  "respond to #{pp_names}#{with_arity}"
30
29
  end
31
30
 
@@ -51,6 +50,7 @@ module Spec
51
50
  end
52
51
 
53
52
  def pp_names
53
+ # Ruby 1.9 returns the same thing for array.to_s as array.inspect, so just use array.inspect here
54
54
  @names.length == 1 ? "##{@names.first}" : @names.inspect
55
55
  end
56
56
  end
@@ -6,18 +6,18 @@ module Spec
6
6
  @block = block
7
7
  end
8
8
 
9
- def matches?(given, &block)
9
+ def matches?(actual, &block)
10
10
  @block = block if block
11
- @given = given
12
- @block.call(given)
11
+ @actual = actual
12
+ @block.call(actual)
13
13
  end
14
14
 
15
- def failure_message
16
- "expected #{@given} to satisfy block"
15
+ def failure_message_for_should
16
+ "expected #{@actual} to satisfy block"
17
17
  end
18
18
 
19
- def negative_failure_message
20
- "expected #{@given} not to satisfy block"
19
+ def failure_message_for_should_not
20
+ "expected #{@actual} not to satisfy block"
21
21
  end
22
22
  end
23
23
 
@@ -35,15 +35,13 @@ module Spec
35
35
  if @expected_arg.nil?
36
36
  return @caught_symbol == @expected_symbol
37
37
  else
38
- # puts [@caught_symbol, @expected_symbol].inspect
39
- # puts [@caught_arg, @expected_arg].inspect
40
- return @caught_symbol == @expected_symbol && @caught_arg == @expected_arg
38
+ return (@caught_symbol == @expected_symbol) & (@caught_arg == @expected_arg)
41
39
  end
42
40
  end
43
41
  end
44
42
  end
45
43
 
46
- def failure_message
44
+ def failure_message_for_should
47
45
  if @caught_symbol
48
46
  "expected #{expected}, got #{@caught_symbol.inspect}"
49
47
  else
@@ -51,7 +49,7 @@ module Spec
51
49
  end
52
50
  end
53
51
 
54
- def negative_failure_message
52
+ def failure_message_for_should_not
55
53
  if @expected_symbol
56
54
  "expected #{expected} not to be thrown"
57
55
  else
@@ -105,11 +105,11 @@ module Spec
105
105
  # my_mock.should_receive(:sym).with(*args)
106
106
  # my_mock.should_not_receive(:sym).with(*args)
107
107
  #
108
- # == Argument Constraints using Expression Matchers
108
+ # == Argument Matchers
109
109
  #
110
110
  # Arguments that are passed to #with are compared with actual arguments received
111
111
  # using == by default. In cases in which you want to specify things about the arguments
112
- # rather than the arguments themselves, you can use any of the Expression Matchers.
112
+ # rather than the arguments themselves, you can use any of RSpec's Expression Matchers.
113
113
  # They don't all make syntactic sense (they were primarily designed for use with
114
114
  # Spec::Expectations), but you are free to create your own custom Spec::Matchers.
115
115
  #
@@ -120,7 +120,7 @@ module Spec
120
120
  #
121
121
  # my_mock.should_receive(:sym).with(no_args())
122
122
  # my_mock.should_receive(:sym).with(any_args())
123
- # my_mock.should_receive(:sym).with(1, an_instance_of(Numeric), "b") #2nd argument can any type of Numeric
123
+ # my_mock.should_receive(:sym).with(1, kind_of(Numeric), "b") #2nd argument can any kind of Numeric
124
124
  # my_mock.should_receive(:sym).with(1, boolean(), "b") #2nd argument can true or false
125
125
  # my_mock.should_receive(:sym).with(1, /abc/, "b") #2nd argument can be any String matching the submitted Regexp
126
126
  # my_mock.should_receive(:sym).with(1, anything(), "b") #2nd argument can be anything at all
@@ -6,37 +6,37 @@ module Spec
6
6
 
7
7
  def initialize(args, &block)
8
8
  @args = args
9
- @constraints_block = block
9
+ @matchers_block = block
10
10
 
11
- if ArgumentConstraints::AnyArgsConstraint === args.first
11
+ if ArgumentMatchers::AnyArgsMatcher === args.first
12
12
  @match_any_args = true
13
- elsif ArgumentConstraints::NoArgsConstraint === args.first
14
- @constraints = []
13
+ elsif ArgumentMatchers::NoArgsMatcher === args.first
14
+ @matchers = []
15
15
  else
16
- @constraints = args.collect {|arg| constraint_for(arg)}
16
+ @matchers = args.collect {|arg| matcher_for(arg)}
17
17
  end
18
18
  end
19
19
 
20
- def constraint_for(arg)
21
- return ArgumentConstraints::MatcherConstraint.new(arg) if is_matcher?(arg)
22
- return ArgumentConstraints::RegexpConstraint.new(arg) if arg.is_a?(Regexp)
23
- return ArgumentConstraints::EqualityProxy.new(arg)
20
+ def matcher_for(arg)
21
+ return ArgumentMatchers::MatcherMatcher.new(arg) if is_matcher?(arg)
22
+ return ArgumentMatchers::RegexpMatcher.new(arg) if arg.is_a?(Regexp)
23
+ return ArgumentMatchers::EqualityProxy.new(arg)
24
24
  end
25
25
 
26
26
  def is_matcher?(obj)
27
- return obj.respond_to?(:matches?) && obj.respond_to?(:description)
27
+ return obj.respond_to?(:matches?) & obj.respond_to?(:description)
28
28
  end
29
29
 
30
30
  def args_match?(given_args)
31
- match_any_args? || constraints_block_matches?(given_args) || constraints_match?(given_args)
31
+ match_any_args? || matchers_block_matches?(given_args) || matchers_match?(given_args)
32
32
  end
33
33
 
34
- def constraints_block_matches?(given_args)
35
- @constraints_block ? @constraints_block.call(*given_args) : nil
34
+ def matchers_block_matches?(given_args)
35
+ @matchers_block ? @matchers_block.call(*given_args) : nil
36
36
  end
37
37
 
38
- def constraints_match?(given_args)
39
- @constraints == given_args
38
+ def matchers_match?(given_args)
39
+ @matchers == given_args
40
40
  end
41
41
 
42
42
  def match_any_args?