rspec 1.1.11 → 1.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -4,6 +4,43 @@ module Spec
4
4
 
5
5
  extend ModuleReopeningFix
6
6
 
7
+ def subject # :nodoc: this is somewhat experimental
8
+ @subject ||= ( instance_variable_get(subject_variable_name) ||
9
+ instance_eval(&self.class.subject_block) ||
10
+ (described_class ? described_class.new : nil) )
11
+ end
12
+
13
+ # When +should+ is called with no explicit receiver, the call is
14
+ # delegated to the *subject* of the example group. This could be either
15
+ # an explicit subject generated by calling the block passed to
16
+ # +ExampleGroupMethods#subject+, or, if the group is describing a class,
17
+ # an implicitly generated instance of that class.
18
+ def should(matcher=nil)
19
+ if matcher
20
+ subject.should(matcher)
21
+ else
22
+ subject.should
23
+ end
24
+ end
25
+
26
+ # Just like +should+, +should_not+ delegates to the subject (implicit or
27
+ # explicit) of the example group.
28
+ def should_not(matcher)
29
+ subject.should_not(matcher)
30
+ end
31
+
32
+ def violated(message="")
33
+ raise Spec::Expectations::ExpectationNotMetError.new(message)
34
+ end
35
+
36
+ def description
37
+ @_defined_description || ::Spec::Matchers.generated_description || "NO NAME"
38
+ end
39
+
40
+ def options
41
+ @_options
42
+ end
43
+
7
44
  def execute(options, instance_variables)
8
45
  options.reporter.example_started(self)
9
46
  set_instance_variables_from_hash(instance_variables)
@@ -27,28 +64,24 @@ module Spec
27
64
  success = execution_error.nil? || ExamplePendingError === execution_error
28
65
  end
29
66
 
30
- def instance_variable_hash
67
+ def instance_variable_hash # :nodoc:
31
68
  instance_variables.inject({}) do |variable_hash, variable_name|
32
69
  variable_hash[variable_name] = instance_variable_get(variable_name)
33
70
  variable_hash
34
71
  end
35
72
  end
36
73
 
37
- def violated(message="")
38
- raise Spec::Expectations::ExpectationNotMetError.new(message)
39
- end
40
-
41
- def eval_each_fail_fast(procs) #:nodoc:
42
- procs.each do |proc|
43
- instance_eval(&proc)
74
+ def eval_each_fail_fast(examples) # :nodoc:
75
+ examples.each do |example|
76
+ instance_eval(&example)
44
77
  end
45
78
  end
46
79
 
47
- def eval_each_fail_slow(procs) #:nodoc:
80
+ def eval_each_fail_slow(examples) # :nodoc:
48
81
  first_exception = nil
49
- procs.each do |proc|
82
+ examples.each do |example|
50
83
  begin
51
- instance_eval(&proc)
84
+ instance_eval(&example)
52
85
  rescue Exception => e
53
86
  first_exception ||= e
54
87
  end
@@ -56,19 +89,19 @@ module Spec
56
89
  raise first_exception if first_exception
57
90
  end
58
91
 
59
- def description
60
- @_defined_description || ::Spec::Matchers.generated_description || "NO NAME"
61
- end
62
-
63
- def options
64
- @_options
65
- end
66
-
67
- def __full_description
92
+ # Concats the class description with the example description.
93
+ #
94
+ # describe Account do
95
+ # it "should start with a balance of 0" do
96
+ # ...
97
+ #
98
+ # full_description
99
+ # => "Account should start with a balance of 0"
100
+ def full_description
68
101
  "#{self.class.description} #{self.description}"
69
102
  end
70
103
 
71
- def set_instance_variables_from_hash(ivars)
104
+ def set_instance_variables_from_hash(ivars) # :nodoc:
72
105
  ivars.each do |variable_name, value|
73
106
  # Ruby 1.9 requires variable.to_s on the next line
74
107
  unless ['@_implementation', '@_defined_description', '@_matcher_description', '@method_name'].include?(variable_name.to_s)
@@ -77,15 +110,25 @@ module Spec
77
110
  end
78
111
  end
79
112
 
80
- def eval_block
113
+ def eval_block # :nodoc:
81
114
  instance_eval(&@_implementation)
82
115
  end
83
116
 
84
- def implementation_backtrace
85
- eval("caller", @_implementation)
117
+ # Provides the backtrace up to where this example was declared.
118
+ def backtrace
119
+ @_backtrace
86
120
  end
87
121
 
88
- protected
122
+ # Deprecated - use +backtrace()+
123
+ def implementation_backtrace
124
+ Kernel.warn <<-WARNING
125
+ ExampleMethods#implementation_backtrace is deprecated and will be removed
126
+ from a future version. Please use ExampleMethods#backtrace instead.
127
+ WARNING
128
+ backtrace
129
+ end
130
+
131
+ private
89
132
  include Matchers
90
133
  include Pending
91
134
 
@@ -100,6 +143,26 @@ module Spec
100
143
  ensure
101
144
  teardown_mocks_for_rspec
102
145
  end
146
+
147
+ def subject_variable_name
148
+ '@' << (described_class ? underscore(described_class.name) : '__this_does_not_exist')
149
+ end
150
+
151
+ def described_class
152
+ Class === described_type ? described_type : nil
153
+ end
154
+
155
+ def described_type
156
+ self.class.described_type
157
+ end
158
+
159
+ def underscore(camel_cased_word)
160
+ camel_cased_word.to_s.gsub(/::/, '_').
161
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
162
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
163
+ tr("-", "_").
164
+ downcase
165
+ end
103
166
  end
104
167
  end
105
168
  end
@@ -2,31 +2,43 @@ module Spec
2
2
  module Example
3
3
  class SharedExampleGroup < Module
4
4
  module ClassMethods
5
- def add_shared_example_group(new_example_group)
6
- guard_against_redefining_existing_example_group(new_example_group)
7
- shared_example_groups << new_example_group
5
+ def register(*args, &block)
6
+ new_example_group = new(*args, &block)
7
+ shared_example_groups << new_example_group unless already_registered?(new_example_group)
8
+ new_example_group
9
+ end
10
+
11
+ def find(example_group_description)
12
+ shared_example_groups.find {|b| b.description == example_group_description}
8
13
  end
9
14
 
10
- def find_shared_example_group(example_group_description)
11
- shared_example_groups.find do |b|
12
- b.description == example_group_description
13
- end
15
+ def clear
16
+ shared_example_groups.clear
17
+ end
18
+
19
+ def include?(group)
20
+ shared_example_groups.include?(group)
21
+ end
22
+
23
+ def count
24
+ shared_example_groups.length
14
25
  end
15
26
 
27
+ private
28
+
16
29
  def shared_example_groups
17
30
  @shared_example_groups ||= []
18
31
  end
19
-
20
- private
21
- def guard_against_redefining_existing_example_group(new_example_group)
22
- existing_example_group = find_shared_example_group(new_example_group.description)
23
- return unless existing_example_group
24
- return if new_example_group.equal?(existing_example_group)
25
- return if spec_path(new_example_group) == spec_path(existing_example_group)
32
+
33
+ def already_registered?(new_example_group)
34
+ existing_example_group = find(new_example_group.description)
35
+ return false unless existing_example_group
36
+ return true if new_example_group.equal?(existing_example_group)
37
+ return true if expanded_path(new_example_group) == expanded_path(existing_example_group)
26
38
  raise ArgumentError.new("Shared Example '#{existing_example_group.description}' already exists")
27
39
  end
28
40
 
29
- def spec_path(example_group)
41
+ def expanded_path(example_group)
30
42
  File.expand_path(example_group.spec_path)
31
43
  end
32
44
  end
@@ -35,18 +47,13 @@ module Spec
35
47
  include ExampleGroupMethods
36
48
 
37
49
  def initialize(*args, &example_group_block)
38
- describe(*args)
50
+ set_description(*args)
39
51
  @example_group_block = example_group_block
40
- self.class.add_shared_example_group(self)
41
52
  end
42
53
 
43
54
  def included(mod) # :nodoc:
44
55
  mod.module_eval(&@example_group_block)
45
56
  end
46
-
47
- def each_ancestor_example_group_class(superclass_last=false)
48
- yield self
49
- end
50
57
  end
51
58
  end
52
59
  end
@@ -30,27 +30,31 @@ module Spec
30
30
  # RSpec ships with a standard set of useful matchers, and writing your own
31
31
  # matchers is quite simple. See Spec::Matchers for details.
32
32
  module Expectations
33
- class << self
34
- attr_accessor :differ
33
+ def self.differ
34
+ @differ
35
+ end
36
+
37
+ def self.differ=(differ)
38
+ @differ = differ
39
+ end
35
40
 
36
- # raises a Spec::Expectations::ExpectationNotMetError with message
37
- #
38
- # When a differ has been assigned and fail_with is passed
39
- # <code>expected</code> and <code>target</code>, passes them
40
- # to the differ to append a diff message to the failure message.
41
- def fail_with(message, expected=nil, target=nil) # :nodoc:
42
- if Array === message && message.length == 3
43
- message, expected, target = message[0], message[1], message[2]
44
- end
45
- unless (differ.nil? || expected.nil? || target.nil?)
46
- if expected.is_a?(String)
47
- message << "\nDiff:" << self.differ.diff_as_string(target.to_s, expected)
48
- elsif !target.is_a?(Proc)
49
- message << "\nDiff:" << self.differ.diff_as_object(target, expected)
50
- end
41
+ # raises a Spec::Expectations::ExpectationNotMetError with message
42
+ #
43
+ # When a differ has been assigned and fail_with is passed
44
+ # <code>expected</code> and <code>target</code>, passes them
45
+ # to the differ to append a diff message to the failure message.
46
+ def self.fail_with(message, expected=nil, target=nil) # :nodoc:
47
+ if Array === message && message.length == 3
48
+ message, expected, target = message[0], message[1], message[2]
49
+ end
50
+ unless (differ.nil? || expected.nil? || target.nil?)
51
+ if expected.is_a?(String)
52
+ message << "\nDiff:" << self.differ.diff_as_string(target.to_s, expected)
53
+ elsif !target.is_a?(Proc)
54
+ message << "\nDiff:" << self.differ.diff_as_object(target, expected)
51
55
  end
52
- Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))
53
56
  end
57
+ Kernel::raise(Spec::Expectations::ExpectationNotMetError.new(message))
54
58
  end
55
59
  end
56
60
  end
@@ -3,50 +3,30 @@ module Spec
3
3
  class InvalidMatcherError < ArgumentError; end
4
4
 
5
5
  class ExpectationMatcherHandler
6
- class << self
7
- def handle_matcher(actual, matcher, &block)
8
- ::Spec::Matchers.last_should = "should"
9
- return Spec::Matchers::PositiveOperatorMatcher.new(actual) if matcher.nil?
6
+ def self.handle_matcher(actual, matcher, &block)
7
+ ::Spec::Matchers.last_should = :should
8
+ ::Spec::Matchers.last_matcher = matcher
10
9
 
11
- unless matcher.respond_to?(:matches?)
12
- raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
13
- end
14
-
15
- match = matcher.matches?(actual, &block)
16
- ::Spec::Matchers.last_matcher = matcher
17
- Spec::Expectations.fail_with(matcher.failure_message) unless match
18
- match
19
- end
10
+ return ::Spec::Matchers::PositiveOperatorMatcher.new(actual) if matcher.nil?
11
+
12
+ match = matcher.matches?(actual, &block)
13
+ ::Spec::Expectations.fail_with(matcher.failure_message) unless match
14
+ match
20
15
  end
21
16
  end
22
17
 
23
18
  class NegativeExpectationMatcherHandler
24
- class << self
25
- def handle_matcher(actual, matcher, &block)
26
- ::Spec::Matchers.last_should = "should not"
27
- return Spec::Matchers::NegativeOperatorMatcher.new(actual) if matcher.nil?
28
-
29
- unless matcher.respond_to?(:matches?)
30
- raise InvalidMatcherError, "Expected a matcher, got #{matcher.inspect}."
31
- end
19
+ def self.handle_matcher(actual, matcher, &block)
20
+ ::Spec::Matchers.last_should = :should_not
21
+ ::Spec::Matchers.last_matcher = matcher
32
22
 
33
- unless matcher.respond_to?(:negative_failure_message)
34
- Spec::Expectations.fail_with(
35
- <<-EOF
36
- Matcher does not support should_not.
37
- See Spec::Matchers for more information
38
- about matchers.
39
- EOF
40
- )
41
- end
42
- match = matcher.matches?(actual, &block)
43
- ::Spec::Matchers.last_matcher = matcher
44
- Spec::Expectations.fail_with(matcher.negative_failure_message) if match
45
- match
46
- end
23
+ return ::Spec::Matchers::NegativeOperatorMatcher.new(actual) if matcher.nil?
24
+
25
+ match = matcher.matches?(actual, &block)
26
+ ::Spec::Expectations.fail_with(matcher.negative_failure_message) if match
27
+ match
47
28
  end
48
29
  end
49
-
50
30
  end
51
31
  end
52
32
 
@@ -23,26 +23,24 @@ module Test
23
23
  extend Spec::Example::ExampleGroupMethods
24
24
  include Spec::Example::ExampleMethods
25
25
 
26
- before(:each) {setup}
27
- after(:each) {teardown}
28
-
29
- class << self
30
- def suite
31
- Test::Unit::TestSuiteAdapter.new(self)
32
- end
26
+ def self.suite
27
+ Test::Unit::TestSuiteAdapter.new(self)
28
+ end
33
29
 
34
- def example_method?(method_name)
35
- should_method?(method_name) || test_method?(method_name)
36
- end
30
+ def self.example_method?(method_name)
31
+ should_method?(method_name) || test_method?(method_name)
32
+ end
37
33
 
38
- def test_method?(method_name)
39
- method_name =~ /^test[_A-Z]./ && (
40
- instance_method(method_name).arity == 0 ||
41
- instance_method(method_name).arity == -1
42
- )
43
- end
34
+ def self.test_method?(method_name)
35
+ method_name =~ /^test[_A-Z]./ && (
36
+ instance_method(method_name).arity == 0 ||
37
+ instance_method(method_name).arity == -1
38
+ )
44
39
  end
45
40
 
41
+ before(:each) {setup}
42
+ after(:each) {teardown}
43
+
46
44
  def initialize(defined_description, options={}, &implementation)
47
45
  @_defined_description = defined_description
48
46
 
@@ -51,9 +49,13 @@ module Test
51
49
  @_implementation = implementation || pending_implementation
52
50
 
53
51
  @_result = ::Test::Unit::TestResult.new
54
- # @method_name is important to set here because it "complies" with Test::Unit's interface.
52
+ # @method_name is important to set here because it complies with Test::Unit's interface.
55
53
  # Some Test::Unit extensions depend on @method_name being present.
56
54
  @method_name = @_defined_description
55
+
56
+ # TODO - this is necessary to run single examples in rspec-rails, but I haven't
57
+ # found a good way to write a failing example just within rspec core
58
+ @_backtrace = caller
57
59
  end
58
60
 
59
61
  def run(ignore_this_argument=nil)
@@ -1,6 +1,6 @@
1
1
  class Test::Unit::TestResult
2
2
  alias_method :tu_passed?, :passed?
3
3
  def passed?
4
- return tu_passed? & ::Spec.run
4
+ return tu_passed? & ::Spec::Runner.run
5
5
  end
6
6
  end
@@ -14,7 +14,7 @@ module Test
14
14
 
15
15
  def run(*args)
16
16
  return true unless args.empty?
17
- example_group.run
17
+ example_group.run(Spec::Runner.options)
18
18
  end
19
19
 
20
20
  def size
@@ -1,7 +1,12 @@
1
+ require 'spec/matchers/operator_matcher'
2
+ require 'spec/matchers/generated_descriptions'
3
+ require 'spec/matchers/errors'
4
+ require 'spec/matchers/method_missing'
1
5
  require 'spec/matchers/simple_matcher'
2
6
  require 'spec/matchers/be'
3
7
  require 'spec/matchers/be_close'
4
8
  require 'spec/matchers/change'
9
+ require 'spec/matchers/match_array'
5
10
  require 'spec/matchers/eql'
6
11
  require 'spec/matchers/equal'
7
12
  require 'spec/matchers/exist'
@@ -13,7 +18,7 @@ require 'spec/matchers/raise_error'
13
18
  require 'spec/matchers/respond_to'
14
19
  require 'spec/matchers/satisfy'
15
20
  require 'spec/matchers/throw_symbol'
16
- require 'spec/matchers/operator_matcher'
21
+ require 'spec/matchers/wrap_expectation'
17
22
 
18
23
  module Spec
19
24
 
@@ -132,31 +137,5 @@ module Spec
132
137
  # config.include(CustomGameMatchers)
133
138
  # end
134
139
  #
135
- module Matchers
136
- module ModuleMethods
137
- attr_accessor :last_matcher, :last_should
138
-
139
- def clear_generated_description
140
- self.last_matcher = nil
141
- self.last_should = nil
142
- end
143
-
144
- def generated_description
145
- last_should.nil? ? nil :
146
- "#{last_should} #{last_matcher.respond_to?(:description) ? last_matcher.description : 'NO NAME'}"
147
- end
148
- end
149
-
150
- extend ModuleMethods
151
-
152
- def method_missing(sym, *args, &block) # :nodoc:
153
- return Matchers::Be.new(sym, *args) if sym.starts_with?("be_")
154
- return Matchers::Has.new(sym, *args) if sym.starts_with?("have_")
155
- super
156
- end
157
-
158
- class MatcherError < StandardError
159
- end
160
-
161
- end
140
+ module Matchers; end
162
141
  end