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
@@ -9,9 +9,11 @@ module Spec
9
9
  class NoisyBacktraceTweaker < BacktraceTweaker
10
10
  def tweak_backtrace(error)
11
11
  return if error.backtrace.nil?
12
- error.backtrace.each do |line|
12
+ tweaked = error.backtrace.collect do |line|
13
13
  clean_up_double_slashes(line)
14
+ line
14
15
  end
16
+ error.set_backtrace(tweaked)
15
17
  end
16
18
  end
17
19
 
@@ -40,7 +42,7 @@ module Spec
40
42
 
41
43
  def tweak_backtrace(error)
42
44
  return if error.backtrace.nil?
43
- error.backtrace.collect! do |message|
45
+ tweaked = error.backtrace.collect do |message|
44
46
  clean_up_double_slashes(message)
45
47
  kept_lines = message.split("\n").select do |line|
46
48
  IGNORE_PATTERNS.each do |ignore|
@@ -49,7 +51,7 @@ module Spec
49
51
  end
50
52
  kept_lines.empty?? nil : kept_lines.join("\n")
51
53
  end
52
- error.backtrace.compact!
54
+ error.set_backtrace(tweaked.select {|line| line})
53
55
  end
54
56
  end
55
57
  end
@@ -1,16 +1,14 @@
1
1
  module Spec
2
2
  module Runner
3
3
  class ClassAndArgumentsParser
4
- class << self
5
- def parse(s)
6
- if s =~ /([a-zA-Z_]+(?:::[a-zA-Z_]+)*):?(.*)/
7
- arg = $2 == "" ? nil : $2
8
- [$1, arg]
9
- else
10
- raise "Couldn't parse #{s.inspect}"
11
- end
4
+ def self.parse(s)
5
+ if s =~ /([a-zA-Z_]+(?:::[a-zA-Z_]+)*):?(.*)/
6
+ arg = $2 == "" ? nil : $2
7
+ [$1, arg]
8
+ else
9
+ raise "Couldn't parse #{s.inspect}"
12
10
  end
13
11
  end
14
12
  end
15
13
  end
16
- end
14
+ end
@@ -3,14 +3,12 @@ require 'spec/runner/option_parser'
3
3
  module Spec
4
4
  module Runner
5
5
  class CommandLine
6
- class << self
7
- def run(tmp_options=Spec::Runner.options)
8
- orig_options = Spec::Runner.options
9
- Spec::Runner.use tmp_options
10
- tmp_options.run_examples
11
- ensure
12
- Spec::Runner.use orig_options
13
- end
6
+ def self.run(tmp_options=Spec::Runner.options)
7
+ orig_options = Spec::Runner.options
8
+ Spec::Runner.use tmp_options
9
+ tmp_options.run_examples
10
+ ensure
11
+ Spec::Runner.use orig_options
14
12
  end
15
13
  end
16
14
  end
@@ -1,5 +1,5 @@
1
1
  module Spec
2
- module Example
2
+ module Runner
3
3
  class Configuration
4
4
  # Chooses what mock framework to use. Example:
5
5
  #
@@ -47,44 +47,48 @@ module Spec
47
47
  # include(My::Helpers, :type => :key)
48
48
  #
49
49
  # Declares modules to be included in multiple example groups
50
- # (<tt>describe</tt> blocks). With no :type, the modules listed will be
51
- # included in all example groups. Use :type to restrict the inclusion to
52
- # a subset of example groups. The value assigned to :type should be a
53
- # key that maps to a class that is either a subclass of
54
- # Spec::Example::ExampleGroup or extends Spec::Example::ExampleGroupMethods
55
- # and includes Spec::Example::ExampleMethods
50
+ # (<tt>describe</tt> blocks). With no <tt>:type</tt>, the modules listed
51
+ # will be included in all example groups.
56
52
  #
57
- # config.include(My::Pony, My::Horse, :type => :farm)
53
+ # Use <tt>:type</tt> to restrict
54
+ # the inclusion to a subset of example groups. The value assigned to
55
+ # <tt>:type</tt> should be a key that maps to a class that is either a
56
+ # subclass of Spec::Example::ExampleGroup or extends
57
+ # Spec::Example::ExampleGroupMethods and includes
58
+ # Spec::Example::ExampleMethods.
59
+ #
60
+ # For example, the rspec-rails gem/plugin extends Test::Unit::TestCase
61
+ # with Spec::Example::ExampleGroupMethods and includes
62
+ # Spec::Example::ExampleMethods in it. So if you have a module of helper
63
+ # methods for controller examples, you could do this:
64
+ #
65
+ # config.include(ControllerExampleHelpers, :type => :controller)
58
66
  #
59
67
  # Only example groups that have that type will get the modules included:
60
68
  #
61
- # describe "Downtown", :type => :city do
62
- # # Will *not* get My::Pony and My::Horse included
69
+ # describe Account, :type => :model do
70
+ # # Will *not* include ControllerExampleHelpers
63
71
  # end
64
72
  #
65
- # describe "Old Mac Donald", :type => :farm do
66
- # # *Will* get My::Pony and My::Horse included
73
+ # describe AccountsController, :type => :controller do
74
+ # # *Will* include ControllerExampleHelpers
67
75
  # end
68
76
  #
69
77
  def include(*args)
70
78
  include_or_extend(:include, *args)
71
79
  end
72
80
 
81
+ # :call-seq:
82
+ # extend(Some::Helpers)
83
+ # extend(Some::Helpers, More::Helpers)
84
+ # extend(My::Helpers, :type => :key)
85
+ #
86
+ # Works just like #include, but extends the example groups
87
+ # with the modules rather than including them.
73
88
  def extend(*args)
74
89
  include_or_extend(:extend, *args)
75
90
  end
76
91
 
77
- def include_or_extend(*args)
78
- action = args.shift
79
- args << {} unless Hash === args.last
80
- modules, options = args_and_options(*args)
81
- required_example_group = get_type_from_options(options)
82
- required_example_group = required_example_group.to_sym if required_example_group
83
- modules.each do |mod|
84
- ExampleGroupFactory.get(required_example_group).send(action, mod)
85
- end
86
- end
87
-
88
92
  # Defines global predicate matchers. Example:
89
93
  #
90
94
  # config.predicate_matchers[:swim] = :can_swim?
@@ -100,11 +104,7 @@ module Spec
100
104
  # Prepends a global <tt>before</tt> block to all example groups.
101
105
  # See #append_before for filtering semantics.
102
106
  def prepend_before(*args, &proc)
103
- scope, options = scope_and_options(*args)
104
- example_group = ExampleGroupFactory.get(
105
- get_type_from_options(options)
106
- )
107
- example_group.prepend_before(scope, &proc)
107
+ add_callback(:prepend_before, *args, &proc)
108
108
  end
109
109
 
110
110
  # Appends a global <tt>before</tt> block to all example groups.
@@ -119,40 +119,39 @@ module Spec
119
119
  # config.prepend_before(:type => :farm)
120
120
  #
121
121
  def append_before(*args, &proc)
122
- scope, options = scope_and_options(*args)
123
- example_group = ExampleGroupFactory.get(
124
- get_type_from_options(options)
125
- )
126
- example_group.append_before(scope, &proc)
122
+ add_callback(:append_before, *args, &proc)
127
123
  end
128
124
  alias_method :before, :append_before
129
125
 
130
126
  # Prepends a global <tt>after</tt> block to all example groups.
131
127
  # See #append_before for filtering semantics.
132
128
  def prepend_after(*args, &proc)
133
- scope, options = scope_and_options(*args)
134
- example_group = ExampleGroupFactory.get(
135
- get_type_from_options(options)
136
- )
137
- example_group.prepend_after(scope, &proc)
129
+ add_callback(:prepend_after, *args, &proc)
138
130
  end
139
131
  alias_method :after, :prepend_after
140
132
 
141
133
  # Appends a global <tt>after</tt> block to all example groups.
142
134
  # See #append_before for filtering semantics.
143
135
  def append_after(*args, &proc)
144
- scope, options = scope_and_options(*args)
145
- example_group = ExampleGroupFactory.get(
146
- get_type_from_options(options)
147
- )
148
- example_group.append_after(scope, &proc)
136
+ add_callback(:append_after, *args, &proc)
149
137
  end
150
138
 
151
139
  private
140
+
141
+ def include_or_extend(action, *args)
142
+ modules, options = Spec::Example.args_and_options(*args)
143
+ [get_type_from_options(options)].flatten.each do |required_example_group|
144
+ required_example_group = required_example_group.to_sym if required_example_group
145
+ modules.each do |mod|
146
+ Spec::Example::ExampleGroupFactory.get(required_example_group).__send__(action, mod)
147
+ end
148
+ end
149
+ end
152
150
 
153
- def scope_and_options(*args)
154
- args, options = args_and_options(*args)
155
- scope = (args[0] || :each), options
151
+ def add_callback(sym, *args, &proc)
152
+ scope, options = Spec::Example.scope_and_options(*args)
153
+ example_group = Spec::Example::ExampleGroupFactory.get(get_type_from_options(options))
154
+ example_group.__send__(sym, scope, &proc)
156
155
  end
157
156
 
158
157
  def get_type_from_options(options)
@@ -160,7 +159,7 @@ module Spec
160
159
  end
161
160
 
162
161
  def mock_framework_path(framework_name)
163
- File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "plugins", "mock_frameworks", framework_name))
162
+ File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "adapters", "mock_frameworks", framework_name))
164
163
  end
165
164
  end
166
165
  end
@@ -10,6 +10,7 @@ module Spec
10
10
  # responsibility of the ExampleGroupRunner. Some implementations (like)
11
11
  # the one using DRb may choose *not* to load files, but instead tell
12
12
  # someone else to do it over the wire.
13
+ $KCODE = 'u' if RUBY_VERSION < '1.9'
13
14
  files.each do |file|
14
15
  load file
15
16
  end
@@ -19,7 +20,7 @@ module Spec
19
20
  prepare
20
21
  success = true
21
22
  example_groups.each do |example_group|
22
- success = success & example_group.run
23
+ success = success & example_group.run(@options)
23
24
  end
24
25
  return success
25
26
  ensure
@@ -53,7 +54,17 @@ module Spec
53
54
  @options.number_of_examples
54
55
  end
55
56
  end
56
- # TODO: BT - Deprecate BehaviourRunner?
57
- BehaviourRunner = ExampleGroupRunner
57
+
58
+ class BehaviourRunner < ExampleGroupRunner
59
+ def initialize(options)
60
+ Kernel.warn <<-WARNING
61
+ DEPRECATED: The BeheviourRunner class is deprecated and will
62
+ be removed from rspec-1.2.
63
+
64
+ Use ExampleGroupRunner instead.
65
+ WARNING
66
+ super
67
+ end
68
+ end
58
69
  end
59
- end
70
+ end
@@ -14,6 +14,7 @@ module Spec
14
14
  def initialize(options, where)
15
15
  super
16
16
  if where.is_a?(String)
17
+ FileUtils.mkdir_p(File.dirname(where))
17
18
  @output = File.open(where, 'w')
18
19
  else
19
20
  @output = where
@@ -22,7 +23,7 @@ module Spec
22
23
  end
23
24
 
24
25
  def example_pending(example, message, pending_caller)
25
- @pending_examples << [example.__full_description, message, pending_caller]
26
+ @pending_examples << [example.full_description, message, pending_caller]
26
27
  end
27
28
 
28
29
  def dump_failure(counter, failure)
@@ -69,8 +70,8 @@ module Spec
69
70
  @output.puts
70
71
  @output.puts "Pending:"
71
72
  @pending_examples.each do |pending_example|
72
- @output.puts "#{pending_example[0]} (#{pending_example[1]})"
73
- @output.puts " Called from #{pending_example[2]}"
73
+ @output.puts "\n#{pending_example[0]} (#{pending_example[1]})"
74
+ @output.puts "#{pending_example[2]}\n"
74
75
  end
75
76
  end
76
77
  @output.flush
@@ -154,14 +154,6 @@ module Spec
154
154
  font-size: 80%;
155
155
  }
156
156
  </style>
157
- </head>
158
- <body>
159
- EOF
160
- end
161
-
162
- def report_header
163
- <<-EOF
164
- <div class="rspec-report">
165
157
  <script type="text/javascript">
166
158
  // <![CDATA[
167
159
  #{global_scripts}
@@ -170,9 +162,19 @@ EOF
170
162
  <style type="text/css">
171
163
  #{global_styles}
172
164
  </style>
165
+ </head>
166
+ <body>
167
+ EOF
168
+ end
169
+
170
+ def report_header
171
+ <<-EOF
172
+ <div class="rspec-report">
173
173
 
174
174
  <div id="rspec-header">
175
- <h1>RSpec Results</h1>
175
+ <div id="label">
176
+ <h1>RSpec Results</h1>
177
+ </div>
176
178
 
177
179
  <div id="summary">
178
180
  <p id="totals">&nbsp;</p>
@@ -212,7 +214,7 @@ EOF
212
214
  def global_styles
213
215
  <<-EOF
214
216
  #rspec-header {
215
- background: #65C400; color: #fff;
217
+ background: #65C400; color: #fff; height: 42px;
216
218
  }
217
219
 
218
220
  .rspec-report h1 {
@@ -220,15 +222,16 @@ EOF
220
222
  padding: 10px;
221
223
  font-family: "Lucida Grande", Helvetica, sans-serif;
222
224
  font-size: 1.8em;
225
+ float: left;
223
226
  }
224
227
 
225
228
  #summary {
226
229
  margin: 0; padding: 5px 10px;
227
230
  font-family: "Lucida Grande", Helvetica, sans-serif;
228
231
  text-align: right;
229
- position: absolute;
230
232
  top: 0px;
231
233
  right: 0px;
234
+ float:right;
232
235
  }
233
236
 
234
237
  #summary p {
@@ -16,7 +16,7 @@ module Spec
16
16
  current_nested_example_groups = described_example_group_chain
17
17
  current_nested_example_groups.each_with_index do |nested_example_group, i|
18
18
  unless nested_example_group == previous_nested_example_groups[i]
19
- output.puts "#{' ' * i}#{nested_example_group.description_args}"
19
+ output.puts "#{' ' * i}#{nested_example_group.description_args.join}"
20
20
  end
21
21
  end
22
22
 
@@ -52,7 +52,7 @@ module Spec
52
52
 
53
53
  def described_example_group_chain
54
54
  example_group_chain = []
55
- example_group.__send__(:each_ancestor_example_group_class) do |example_group_class|
55
+ example_group.__send__(:example_group_hierarchy).each do |example_group_class|
56
56
  unless example_group_class.description_args.empty?
57
57
  example_group_chain << example_group_class
58
58
  end
@@ -1,72 +1,74 @@
1
- begin
2
- require 'rubygems'
3
- require 'heckle'
4
- rescue LoadError ; raise "You must gem install heckle to use --heckle" ; end
1
+ unless Spec::Ruby.version.to_f == 1.9
2
+ begin
3
+ require 'rubygems'
4
+ require 'heckle'
5
+ rescue LoadError ; raise "You must gem install heckle to use --heckle" ; end
5
6
 
6
- module Spec
7
- module Runner
8
- # Creates a new Heckler configured to heckle all methods in the classes
9
- # whose name matches +filter+
10
- class HeckleRunner
11
- def initialize(filter, heckle_class=Heckler)
12
- @filter = filter
13
- @heckle_class = heckle_class
14
- end
15
-
16
- # Runs all the example groups held by +rspec_options+ once for each of the
17
- # methods in the matched classes.
18
- def heckle_with
19
- if @filter =~ /(.*)[#\.](.*)/
20
- heckle_method($1, $2)
21
- else
22
- heckle_class_or_module(@filter)
7
+ module Spec
8
+ module Runner
9
+ # Creates a new Heckler configured to heckle all methods in the classes
10
+ # whose name matches +filter+
11
+ class HeckleRunner
12
+ def initialize(filter, heckle_class=Heckler)
13
+ @filter = filter
14
+ @heckle_class = heckle_class
23
15
  end
24
- end
25
16
 
26
- def heckle_method(class_name, method_name)
27
- verify_constant(class_name)
28
- heckle = @heckle_class.new(class_name, method_name, Spec::Runner.options)
29
- heckle.validate
30
- end
17
+ # Runs all the example groups held by +rspec_options+ once for each of the
18
+ # methods in the matched classes.
19
+ def heckle_with
20
+ if @filter =~ /(.*)[#\.](.*)/
21
+ heckle_method($1, $2)
22
+ else
23
+ heckle_class_or_module(@filter)
24
+ end
25
+ end
31
26
 
32
- def heckle_class_or_module(class_or_module_name)
33
- verify_constant(class_or_module_name)
34
- pattern = /^#{class_or_module_name}/
35
- classes = []
36
- ObjectSpace.each_object(Class) do |klass|
37
- classes << klass if klass.name =~ pattern
27
+ def heckle_method(class_name, method_name)
28
+ verify_constant(class_name)
29
+ heckle = @heckle_class.new(class_name, method_name, Spec::Runner.options)
30
+ heckle.validate
38
31
  end
32
+
33
+ def heckle_class_or_module(class_or_module_name)
34
+ verify_constant(class_or_module_name)
35
+ pattern = /^#{class_or_module_name}/
36
+ classes = []
37
+ ObjectSpace.each_object(Class) do |klass|
38
+ classes << klass if klass.name =~ pattern
39
+ end
39
40
 
40
- classes.each do |klass|
41
- klass.instance_methods(false).each do |method_name|
42
- heckle = @heckle_class.new(klass.name, method_name, Spec::Runner.options)
43
- heckle.validate
41
+ classes.each do |klass|
42
+ klass.instance_methods(false).each do |method_name|
43
+ heckle = @heckle_class.new(klass.name, method_name, Spec::Runner.options)
44
+ heckle.validate
45
+ end
44
46
  end
45
47
  end
46
- end
47
48
 
48
- def verify_constant(name)
49
- begin
50
- # This is defined in Heckle
51
- name.to_class
52
- rescue
53
- raise "Heckling failed - \"#{name}\" is not a known class or module"
49
+ def verify_constant(name)
50
+ begin
51
+ # This is defined in Heckle
52
+ name.to_class
53
+ rescue
54
+ raise "Heckling failed - \"#{name}\" is not a known class or module"
55
+ end
54
56
  end
55
57
  end
56
- end
57
58
 
58
- #Supports Heckle 1.2 and prior (earlier versions used Heckle::Base)
59
- class Heckler < (Heckle.const_defined?(:Base) ? Heckle::Base : Heckle)
60
- def initialize(klass_name, method_name, rspec_options)
61
- super(klass_name, method_name)
62
- @rspec_options = rspec_options
63
- end
59
+ #Supports Heckle 1.2 and prior (earlier versions used Heckle::Base)
60
+ class Heckler < (Heckle.const_defined?(:Base) ? Heckle::Base : Heckle)
61
+ def initialize(klass_name, method_name, rspec_options)
62
+ super(klass_name, method_name)
63
+ @rspec_options = rspec_options
64
+ end
64
65
 
65
- def tests_pass?
66
- success = @rspec_options.run_examples
67
- success
68
- end
66
+ def tests_pass?
67
+ success = @rspec_options.run_examples
68
+ success
69
+ end
69
70
 
71
+ end
70
72
  end
71
73
  end
72
- end
74
+ end