rspec 1.2.8 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. data/History.rdoc +41 -2
  2. data/Manifest.txt +11 -10
  3. data/Rakefile +47 -22
  4. data/Ruby1.9.rdoc +1 -2
  5. data/Upgrade.rdoc +56 -7
  6. data/bin/spec +2 -1
  7. data/cucumber.yml +3 -1
  8. data/examples/failing/README.txt +7 -3
  9. data/examples/failing/failing_implicit_docstrings_example.rb +0 -2
  10. data/examples/failing/mocking_example.rb +0 -2
  11. data/examples/failing/partial_mock_example.rb +0 -2
  12. data/examples/failing/pending_example.rb +0 -2
  13. data/examples/failing/predicate_example.rb +0 -2
  14. data/examples/failing/team_spec.rb +0 -3
  15. data/examples/failing/timeout_behaviour.rb +0 -2
  16. data/examples/passing/custom_formatter.rb +0 -1
  17. data/examples/passing/dynamic_spec.rb +0 -2
  18. data/examples/passing/file_accessor.rb +1 -2
  19. data/examples/passing/file_accessor_spec.rb +1 -2
  20. data/examples/passing/filtered_formatter.rb +0 -1
  21. data/examples/passing/greeter_spec.rb +0 -1
  22. data/examples/passing/helper_method_example.rb +0 -2
  23. data/examples/passing/implicit_docstrings_example.rb +0 -2
  24. data/examples/passing/io_processor_spec.rb +1 -2
  25. data/examples/passing/mocking_example.rb +0 -2
  26. data/examples/passing/nested_classes_example.rb +1 -2
  27. data/examples/passing/options_example.rb +0 -2
  28. data/examples/passing/partial_mock_example.rb +0 -2
  29. data/examples/passing/pending_example.rb +0 -2
  30. data/examples/passing/predicate_example.rb +0 -2
  31. data/examples/passing/shared_example_group_example.rb +0 -2
  32. data/examples/passing/simple_matcher_example.rb +0 -2
  33. data/examples/passing/stack_spec.rb +2 -3
  34. data/examples/passing/stack_spec_with_nested_example_groups.rb +2 -3
  35. data/examples/passing/stubbing_example.rb +0 -2
  36. data/examples/passing/yielding_example.rb +0 -2
  37. data/features/before_and_after_blocks/before_and_after_blocks.feature +4 -4
  38. data/features/command_line/line_number_option.feature +14 -14
  39. data/features/command_line/line_number_option_with_example_with_no_name.feature +2 -2
  40. data/features/example_groups/define_example_attribute.feature +41 -0
  41. data/features/example_groups/example_group_with_should_methods.feature +1 -1
  42. data/features/example_groups/implicit_docstrings.feature +7 -7
  43. data/features/example_groups/nested_groups.feature +2 -2
  44. data/features/expectations/customized_message.feature +4 -4
  45. data/features/expectations/expect_change.feature +4 -4
  46. data/features/expectations/expect_error.feature +4 -4
  47. data/features/extensions/custom_example_group.feature +10 -10
  48. data/features/formatters/custom_formatter.feature +3 -3
  49. data/features/interop/examples_and_tests_together.feature +10 -6
  50. data/features/interop/rspec_output.feature +1 -1
  51. data/features/interop/test_case_with_should_methods.feature +1 -1
  52. data/features/load_paths/add_lib_to_load_path.feature +20 -0
  53. data/features/load_paths/add_spec_to_load_path.feature +20 -0
  54. data/features/matchers/define_diffable_matcher.feature +2 -2
  55. data/features/matchers/define_matcher.feature +19 -19
  56. data/features/matchers/define_matcher_outside_rspec.feature +2 -3
  57. data/features/matchers/define_matcher_with_fluent_interface.feature +2 -2
  58. data/features/matchers/define_wrapped_matcher.feature +29 -0
  59. data/features/mock_framework_integration/use_flexmock.feature +1 -1
  60. data/features/mock_framework_integration/use_mocha.feature +1 -1
  61. data/features/mock_framework_integration/use_rr.feature +1 -1
  62. data/features/mocks/mix_stubs_and_mocks.feature +2 -2
  63. data/features/mocks/stub_implementation.feature +1 -1
  64. data/features/pending/pending_examples.feature +16 -16
  65. data/features/runner/specify_line_number.feature +4 -4
  66. data/features/spec_helper/spec_helper.feature +25 -0
  67. data/features/step_definitions/running_rspec_steps.rb +4 -2
  68. data/features/subject/explicit_subject.feature +2 -2
  69. data/features/subject/implicit_subject.feature +14 -2
  70. data/features/support/env.rb +6 -3
  71. data/lib/spec/adapters/mock_frameworks/mocha.rb +6 -1
  72. data/lib/spec/example/example_group_methods.rb +7 -0
  73. data/lib/spec/example/example_methods.rb +1 -1
  74. data/lib/spec/example/subject.rb +8 -0
  75. data/lib/spec/interop/test.rb +27 -1
  76. data/lib/spec/interop/test/unit/testcase.rb +1 -1
  77. data/lib/spec/matchers/exist.rb +2 -2
  78. data/lib/spec/matchers/extensions/instance_exec.rb +28 -20
  79. data/lib/spec/matchers/matcher.rb +21 -20
  80. data/lib/spec/mocks/argument_matchers.rb +17 -13
  81. data/lib/spec/mocks/error_generator.rb +14 -3
  82. data/lib/spec/mocks/{spec_methods.rb → example_methods.rb} +25 -11
  83. data/lib/spec/mocks/framework.rb +1 -1
  84. data/lib/spec/mocks/methods.rb +15 -0
  85. data/lib/spec/mocks/mock.rb +16 -10
  86. data/lib/spec/mocks/proxy.rb +1 -1
  87. data/lib/spec/rake/spectask.rb +3 -3
  88. data/lib/spec/runner/backtrace_tweaker.rb +41 -22
  89. data/lib/spec/runner/configuration.rb +18 -1
  90. data/lib/spec/runner/differs/default.rb +1 -1
  91. data/lib/spec/runner/drb_command_line.rb +5 -2
  92. data/lib/spec/runner/formatter/base_text_formatter.rb +8 -3
  93. data/lib/spec/runner/option_parser.rb +21 -15
  94. data/lib/spec/runner/options.rb +54 -23
  95. data/lib/spec/version.rb +3 -3
  96. data/resources/helpers/cmdline.rb +0 -1
  97. data/spec/autotest/autotest_helper.rb +4 -6
  98. data/spec/autotest/discover_spec.rb +2 -2
  99. data/spec/autotest/failed_results_re_spec.rb +1 -1
  100. data/spec/autotest/rspec_spec.rb +1 -1
  101. data/spec/spec/dsl/main_spec.rb +1 -1
  102. data/spec/spec/example/example_group_class_definition_spec.rb +1 -1
  103. data/spec/spec/example/example_group_factory_spec.rb +1 -1
  104. data/spec/spec/example/example_group_methods_spec.rb +21 -1
  105. data/spec/spec/example/example_group_proxy_spec.rb +1 -1
  106. data/spec/spec/example/example_group_spec.rb +1 -1
  107. data/spec/spec/example/example_matcher_spec.rb +1 -1
  108. data/spec/spec/example/example_methods_spec.rb +1 -1
  109. data/spec/spec/example/example_proxy_spec.rb +1 -1
  110. data/spec/spec/example/helper_method_spec.rb +1 -1
  111. data/spec/spec/example/nested_example_group_spec.rb +1 -1
  112. data/spec/spec/example/predicate_matcher_spec.rb +1 -1
  113. data/spec/spec/example/shared_example_group_spec.rb +1 -1
  114. data/spec/spec/example/subclassing_example_group_spec.rb +1 -1
  115. data/spec/spec/example/subject_spec.rb +17 -1
  116. data/spec/spec/expectations/differs/default_spec.rb +16 -3
  117. data/spec/spec/expectations/extensions/kernel_spec.rb +1 -1
  118. data/spec/spec/expectations/fail_with_spec.rb +1 -1
  119. data/spec/spec/expectations/handler_spec.rb +1 -1
  120. data/spec/spec/expectations/wrap_expectation_spec.rb +1 -1
  121. data/spec/spec/interop/test/unit/resources/test_case_with_various_names.rb +22 -0
  122. data/spec/spec/interop/test/unit/spec_spec.rb +1 -1
  123. data/spec/spec/interop/test/unit/test_unit_spec_helper.rb +2 -2
  124. data/spec/spec/interop/test/unit/testcase_spec.rb +7 -2
  125. data/spec/spec/interop/test/unit/testsuite_adapter_spec.rb +1 -1
  126. data/spec/spec/matchers/be_close_spec.rb +1 -1
  127. data/spec/spec/matchers/be_instance_of_spec.rb +1 -1
  128. data/spec/spec/matchers/be_kind_of_spec.rb +1 -1
  129. data/spec/spec/matchers/be_spec.rb +13 -1
  130. data/spec/spec/matchers/change_spec.rb +1 -1
  131. data/spec/spec/matchers/compatibility_spec.rb +1 -1
  132. data/spec/spec/matchers/description_generation_spec.rb +1 -1
  133. data/spec/spec/matchers/dsl_spec.rb +1 -1
  134. data/spec/spec/matchers/eql_spec.rb +1 -1
  135. data/spec/spec/matchers/equal_spec.rb +1 -1
  136. data/spec/spec/matchers/exist_spec.rb +6 -2
  137. data/spec/spec/matchers/has_spec.rb +19 -1
  138. data/spec/spec/matchers/have_spec.rb +1 -1
  139. data/spec/spec/matchers/include_spec.rb +1 -1
  140. data/spec/spec/matchers/match_array_spec.rb +1 -1
  141. data/spec/spec/matchers/match_spec.rb +1 -1
  142. data/spec/spec/matchers/matcher_methods_spec.rb +1 -1
  143. data/spec/spec/matchers/matcher_spec.rb +55 -28
  144. data/spec/spec/matchers/matchers_spec.rb +1 -1
  145. data/spec/spec/matchers/operator_matcher_spec.rb +1 -1
  146. data/spec/spec/matchers/raise_error_spec.rb +1 -1
  147. data/spec/spec/matchers/respond_to_spec.rb +1 -1
  148. data/spec/spec/matchers/satisfy_spec.rb +1 -1
  149. data/spec/spec/matchers/simple_matcher_spec.rb +1 -1
  150. data/spec/spec/matchers/throw_symbol_spec.rb +1 -1
  151. data/spec/spec/mocks/any_number_of_times_spec.rb +1 -1
  152. data/spec/spec/mocks/argument_expectation_spec.rb +1 -1
  153. data/spec/spec/mocks/argument_matchers_spec.rb +19 -0
  154. data/spec/spec/mocks/at_least_spec.rb +1 -1
  155. data/spec/spec/mocks/at_most_spec.rb +1 -1
  156. data/spec/spec/mocks/bug_report_10260_spec.rb +1 -1
  157. data/spec/spec/mocks/bug_report_10263_spec.rb +1 -1
  158. data/spec/spec/mocks/bug_report_11545_spec.rb +1 -1
  159. data/spec/spec/mocks/bug_report_15719_spec.rb +3 -3
  160. data/spec/spec/mocks/bug_report_496_spec.rb +1 -1
  161. data/spec/spec/mocks/bug_report_600_spec.rb +1 -1
  162. data/spec/spec/mocks/bug_report_7611_spec.rb +1 -1
  163. data/spec/spec/mocks/bug_report_7805_spec.rb +1 -1
  164. data/spec/spec/mocks/bug_report_8165_spec.rb +1 -1
  165. data/spec/spec/mocks/bug_report_8302_spec.rb +1 -1
  166. data/spec/spec/mocks/bug_report_830_spec.rb +1 -1
  167. data/spec/spec/mocks/double_spec.rb +12 -0
  168. data/spec/spec/mocks/failing_argument_matchers_spec.rb +6 -6
  169. data/spec/spec/mocks/hash_including_matcher_spec.rb +1 -1
  170. data/spec/spec/mocks/hash_not_including_matcher_spec.rb +1 -1
  171. data/spec/spec/mocks/mock_ordering_spec.rb +4 -4
  172. data/spec/spec/mocks/mock_space_spec.rb +1 -1
  173. data/spec/spec/mocks/mock_spec.rb +20 -24
  174. data/spec/spec/mocks/multiple_return_value_spec.rb +8 -8
  175. data/spec/spec/mocks/nil_expectation_warning_spec.rb +1 -1
  176. data/spec/spec/mocks/null_object_mock_spec.rb +1 -1
  177. data/spec/spec/mocks/once_counts_spec.rb +1 -1
  178. data/spec/spec/mocks/options_hash_spec.rb +1 -1
  179. data/spec/spec/mocks/partial_mock_spec.rb +1 -1
  180. data/spec/spec/mocks/partial_mock_using_mocks_directly_spec.rb +1 -1
  181. data/spec/spec/mocks/passing_argument_matchers_spec.rb +1 -1
  182. data/spec/spec/mocks/precise_counts_spec.rb +1 -1
  183. data/spec/spec/mocks/record_messages_spec.rb +1 -1
  184. data/spec/spec/mocks/stub_chain_spec.rb +1 -1
  185. data/spec/spec/mocks/stub_implementation_spec.rb +1 -1
  186. data/spec/spec/mocks/stub_spec.rb +14 -9
  187. data/spec/spec/mocks/stubbed_message_expectations_spec.rb +2 -2
  188. data/spec/spec/mocks/twice_counts_spec.rb +1 -1
  189. data/spec/spec/mocks/unstub_spec.rb +1 -1
  190. data/spec/spec/package/bin_spec_spec.rb +4 -10
  191. data/spec/spec/rake/spectask_spec.rb +2 -2
  192. data/spec/spec/runner/class_and_argument_parser_spec.rb +1 -1
  193. data/spec/spec/runner/command_line_spec.rb +1 -1
  194. data/spec/spec/runner/configuration_spec.rb +15 -6
  195. data/spec/spec/runner/drb_command_line_spec.rb +1 -1
  196. data/spec/spec/runner/example_group_runner_spec.rb +1 -1
  197. data/spec/spec/runner/formatter/base_formatter_spec.rb +1 -1
  198. data/spec/spec/runner/formatter/base_text_formatter_spec.rb +10 -1
  199. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +1 -1
  200. data/spec/spec/runner/formatter/failing_examples_formatter_spec.rb +1 -1
  201. data/spec/spec/runner/formatter/html_formatted-1.8.6-jruby.html +72 -76
  202. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +50 -50
  203. data/spec/spec/runner/formatter/html_formatted-1.8.7.html +50 -50
  204. data/spec/spec/runner/formatter/html_formatted-1.9.1.html +61 -69
  205. data/spec/spec/runner/formatter/html_formatter_spec.rb +26 -26
  206. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +1 -1
  207. data/spec/spec/runner/formatter/profile_formatter_spec.rb +1 -1
  208. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +13 -9
  209. data/spec/spec/runner/formatter/snippet_extractor_spec.rb +1 -1
  210. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +1 -1
  211. data/spec/spec/runner/formatter/{text_mate_formatted-1.8.4.html → text_mate_formatted-1.8.6-jruby.html} +64 -59
  212. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +46 -46
  213. data/spec/spec/runner/formatter/text_mate_formatted-1.8.7.html +46 -46
  214. data/spec/spec/runner/formatter/text_mate_formatted-1.9.1.html +55 -63
  215. data/spec/spec/runner/formatter/text_mate_formatter_spec.rb +3 -3
  216. data/spec/spec/runner/heckle_runner_spec.rb +1 -1
  217. data/spec/spec/runner/heckler_spec.rb +1 -1
  218. data/spec/spec/runner/line_number_query/line_number_query_fixture.rb +1 -1
  219. data/spec/spec/runner/line_number_query_spec.rb +10 -1
  220. data/spec/spec/runner/noisy_backtrace_tweaker_spec.rb +22 -16
  221. data/spec/spec/runner/option_parser_spec.rb +48 -14
  222. data/spec/spec/runner/options_spec.rb +16 -2
  223. data/spec/spec/runner/output_one_time_fixture.rb +1 -1
  224. data/spec/spec/runner/output_one_time_fixture_runner.rb +2 -3
  225. data/spec/spec/runner/output_one_time_spec.rb +6 -7
  226. data/spec/spec/runner/quiet_backtrace_tweaker_spec.rb +65 -22
  227. data/spec/spec/runner/reporter_spec.rb +1 -1
  228. data/spec/spec/runner_spec.rb +1 -1
  229. data/spec/spec_helper.rb +5 -7
  230. data/spec/{spec → support}/spec_classes.rb +0 -0
  231. metadata +58 -17
  232. data/examples/failing/spec_helper.rb +0 -3
  233. data/examples/passing/spec_helper.rb +0 -3
  234. data/features/heckle/heckle.feature +0 -56
  235. data/spec/rspec_suite.rb +0 -6
  236. data/spec/spec/runner/formatter/html_formatted-1.8.4.html +0 -366
  237. data/spec/spec/runner/formatter/html_formatted-1.8.5-jruby.html +0 -387
  238. data/spec/spec/runner/formatter/html_formatted-1.8.5.html +0 -372
@@ -4,7 +4,7 @@
4
4
 
5
5
  require 'spec/mocks/methods'
6
6
  require 'spec/mocks/argument_matchers'
7
- require 'spec/mocks/spec_methods'
7
+ require 'spec/mocks/example_methods'
8
8
  require 'spec/mocks/proxy'
9
9
  require 'spec/mocks/mock'
10
10
  require 'spec/mocks/argument_expectation'
@@ -25,6 +25,21 @@ module Spec
25
25
 
26
26
  alias_method :unstub, :unstub!
27
27
 
28
+ # :call-seq:
29
+ # object.stub_chain(:first, :second, :third).and_return(:this)
30
+ #
31
+ # Supports stubbing a chain of methods. Each argument represents
32
+ # a method name to stub, and each one returns a proxy object that
33
+ # can accept more stubs, until the last, which returns whatever
34
+ # is passed to +and_return_.
35
+ #
36
+ # == Examples
37
+ #
38
+ # # with this in an example ...
39
+ # article = double('article')
40
+ # Article.stub_chain(:authored_by, :published, :recent).and_return([article])
41
+ # # then this will return an Array with the article double in it:
42
+ # Article.authored_by(params[:author_id]).published.recent
28
43
  def stub_chain(*methods)
29
44
  if methods.length > 1
30
45
  if matching_stub = __mock_proxy.find_matching_method_stub(methods[0])
@@ -7,14 +7,14 @@ module Spec
7
7
  # only) == Options:
8
8
  # * <tt>:null_object</tt> - if true, the mock object acts as a forgiving
9
9
  # null object allowing any message to be sent to it.
10
- def initialize(name='mock', stubs_and_options={})
10
+ def initialize(name=nil, stubs_and_options={})
11
11
  if name.is_a?(Hash) && stubs_and_options.empty?
12
12
  stubs_and_options = name
13
- build_name_from_options stubs_and_options
13
+ @name = nil
14
14
  else
15
15
  @name = name
16
16
  end
17
- @options = parse_options(stubs_and_options)
17
+ @options = extract_options(stubs_and_options)
18
18
  assign_stubs(stubs_and_options)
19
19
  end
20
20
 
@@ -46,8 +46,19 @@ module Spec
46
46
  end
47
47
  end
48
48
 
49
- def parse_options(options)
50
- options.has_key?(:null_object) ? {:null_object => options.delete(:null_object)} : {}
49
+ def extract_options(stubs_and_options)
50
+ options = {}
51
+ extract_option(stubs_and_options, options, :null_object)
52
+ extract_option(stubs_and_options, options, :__declared_as, 'Mock')
53
+ options
54
+ end
55
+
56
+ def extract_option(source, target, key, default=nil)
57
+ if source[key]
58
+ target[key] = source.delete(key)
59
+ elsif default
60
+ target[key] = default
61
+ end
51
62
  end
52
63
 
53
64
  def assign_stubs(stubs)
@@ -55,11 +66,6 @@ module Spec
55
66
  stub!(message).and_return(response)
56
67
  end
57
68
  end
58
-
59
- def build_name_from_options(options)
60
- vals = options.inject([]) {|coll, pair| coll << "#{pair.first}: #{pair.last.inspect}"}
61
- @name = '{' + vals.join(', ') + '}'
62
- end
63
69
  end
64
70
  end
65
71
  end
@@ -18,7 +18,7 @@ module Spec
18
18
  def initialize(target, name=nil, options={})
19
19
  @target = target
20
20
  @name = name
21
- @error_generator = ErrorGenerator.new target, name
21
+ @error_generator = ErrorGenerator.new target, name, options
22
22
  @expectation_ordering = OrderGroup.new @error_generator
23
23
  @expectations = []
24
24
  @messages_received = []
@@ -118,14 +118,14 @@ module Spec
118
118
  # Use verbose output. If this is set to true, the task will print
119
119
  # the executed spec command to stdout. Defaults to false.
120
120
  attr_accessor :verbose
121
-
121
+
122
122
  # Explicitly define the path to the ruby binary, or its proxy (e.g. multiruby)
123
123
  attr_accessor :ruby_cmd
124
124
 
125
125
  # Defines a new task, using the name +name+.
126
126
  def initialize(name=:spec)
127
127
  @name = name
128
- @libs = [File.expand_path(File.dirname(__FILE__) + '/../../../lib')]
128
+ @libs = ['lib']
129
129
  @pattern = nil
130
130
  @spec_files = nil
131
131
  @spec_opts = []
@@ -142,7 +142,7 @@ module Spec
142
142
  end
143
143
 
144
144
  def define # :nodoc:
145
- spec_script = File.expand_path(File.dirname(__FILE__) + '/../../../bin/spec')
145
+ spec_script = File.expand_path(File.join(File.dirname(__FILE__),"..","..","..","bin","spec"))
146
146
 
147
147
  lib_path = libs.join(File::PATH_SEPARATOR)
148
148
  actual_name = Hash === name ? name.keys.first : name
@@ -1,33 +1,53 @@
1
1
  module Spec
2
2
  module Runner
3
3
  class BacktraceTweaker
4
+ def initialize(*patterns)
5
+ @ignore_patterns = []
6
+ end
7
+
4
8
  def clean_up_double_slashes(line)
5
9
  line.gsub!('//','/')
6
10
  end
7
- end
8
11
 
9
- class NoisyBacktraceTweaker < BacktraceTweaker
12
+ def ignore_patterns(*patterns)
13
+ # do nothing. Only QuietBacktraceTweaker ignores patterns.
14
+ end
15
+
16
+ def ignored_patterns
17
+ []
18
+ end
19
+
10
20
  def tweak_backtrace(error)
11
21
  return if error.backtrace.nil?
12
- tweaked = error.backtrace.collect do |line|
13
- clean_up_double_slashes(line)
14
- line
22
+ tweaked = error.backtrace.collect do |message|
23
+ clean_up_double_slashes(message)
24
+ kept_lines = message.split("\n").select do |line|
25
+ ignored_patterns.each do |ignore|
26
+ break if line =~ ignore
27
+ end
28
+ end
29
+ kept_lines.empty?? nil : kept_lines.join("\n")
15
30
  end
16
- error.set_backtrace(tweaked)
31
+ error.set_backtrace(tweaked.select {|line| line})
17
32
  end
18
33
  end
19
34
 
35
+ class NoisyBacktraceTweaker < BacktraceTweaker
36
+ end
37
+
20
38
  # Tweaks raised Exceptions to mask noisy (unneeded) parts of the backtrace
21
39
  class QuietBacktraceTweaker < BacktraceTweaker
22
40
  unless defined?(IGNORE_PATTERNS)
23
- root_dir = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
24
- spec_files = Dir["#{root_dir}/lib/*"].map do |path|
25
- subpath = path[root_dir.length..-1]
41
+ spec_files = Dir["lib/*"].map do |path|
42
+ subpath = path[1..-1]
26
43
  /#{subpath}/
27
44
  end
28
45
  IGNORE_PATTERNS = spec_files + [
46
+ /\/rspec-[^\/]*\/lib\/spec\//,
47
+ /\/spork-[^\/]*\/lib\/spork\//,
29
48
  /\/lib\/ruby\//,
30
49
  /bin\/spec:/,
50
+ /bin\/spork:/,
31
51
  /bin\/rcov:/,
32
52
  /lib\/rspec-rails/,
33
53
  /vendor\/rails/,
@@ -39,19 +59,18 @@ module Spec
39
59
  /spec_server/
40
60
  ]
41
61
  end
42
-
43
- def tweak_backtrace(error)
44
- return if error.backtrace.nil?
45
- tweaked = error.backtrace.collect do |message|
46
- clean_up_double_slashes(message)
47
- kept_lines = message.split("\n").select do |line|
48
- IGNORE_PATTERNS.each do |ignore|
49
- break if line =~ ignore
50
- end
51
- end
52
- kept_lines.empty?? nil : kept_lines.join("\n")
53
- end
54
- error.set_backtrace(tweaked.select {|line| line})
62
+
63
+ def initialize(*patterns)
64
+ super
65
+ ignore_patterns(*patterns)
66
+ end
67
+
68
+ def ignore_patterns(*patterns)
69
+ @ignore_patterns += patterns.flatten.map { |pattern| Regexp.new(pattern) }
70
+ end
71
+
72
+ def ignored_patterns
73
+ IGNORE_PATTERNS + @ignore_patterns
55
74
  end
56
75
  end
57
76
  end
@@ -137,6 +137,23 @@ module Spec
137
137
  def predicate_matchers
138
138
  @predicate_matchers ||= Spec::HashWithDeprecationNotice.new("predicate_matchers", "the new Matcher DSL")
139
139
  end
140
+
141
+ # Adds patterns to the list of patterns ignored in the backtrace when a
142
+ # failure is output by rspec. Example:
143
+ #
144
+ # config.ignore_backtrace_patterns /spork/, /shoulda/, "/some/weird/path/"
145
+ #
146
+ # When quiet backtraces are turned on (default), this will exclude any
147
+ # lines that match any of the Regexps and Strings passed.
148
+ #
149
+ def ignore_backtrace_patterns(*patterns)
150
+ @ignored_backtrace_patterns ||= []
151
+ @ignored_backtrace_patterns += patterns
152
+ end
153
+
154
+ def ignored_backtrace_patterns # :nodoc:
155
+ @ignored_backtrace_patterns ||= []
156
+ end
140
157
 
141
158
  private
142
159
 
@@ -161,7 +178,7 @@ module Spec
161
178
  end
162
179
 
163
180
  def mock_framework_path(framework_name)
164
- File.expand_path(File.join(File.dirname(__FILE__), "/../adapters/mock_frameworks/#{framework_name}"))
181
+ "spec/adapters/mock_frameworks/#{framework_name}"
165
182
  end
166
183
 
167
184
  def scope_and_options(*args) # :nodoc:
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "/load-diff-lcs")
1
+ require 'spec/runner/differs/load-diff-lcs'
2
2
  require 'pp'
3
3
 
4
4
  module Spec
@@ -8,8 +8,11 @@ module Spec
8
8
  # CommandLine - making it possible for clients to use both interchangeably.
9
9
  def self.run(options)
10
10
  begin
11
- # See http://redmine.ruby-lang.org/issues/show/496 as to why we specify localhost:0
12
- DRb.start_service("druby://localhost:0")
11
+ begin; \
12
+ DRb.start_service("druby://localhost:0"); \
13
+ rescue SocketError; \
14
+ DRb.start_service("druby://:0"); \
15
+ end
13
16
  spec_server = DRbObject.new_with_uri("druby://127.0.0.1:8989")
14
17
  spec_server.run(options.argv, options.error_stream, options.output_stream)
15
18
  true
@@ -102,7 +102,7 @@ module Spec
102
102
  end
103
103
 
104
104
  def autospec?
105
- !!@options.autospec
105
+ !!@options.autospec || ENV.has_key?("AUTOTEST")
106
106
  end
107
107
 
108
108
  def backtrace_line(line)
@@ -110,13 +110,18 @@ module Spec
110
110
  end
111
111
 
112
112
  def colour(text, colour_code)
113
- return text unless ENV['RSPEC_COLOR'] || (colour? & (autospec? || output_to_tty?))
113
+ return text if output_to_file?
114
+ return text unless ENV['RSPEC_COLOR'] || (colour? & (autospec? || output_to_tty?))
114
115
  "#{colour_code}#{text}\e[0m"
115
116
  end
116
117
 
118
+ def output_to_file?
119
+ File === @output
120
+ end
121
+
117
122
  def output_to_tty?
118
123
  begin
119
- @output.tty? || ENV.has_key?("AUTOTEST")
124
+ @output.tty?
120
125
  rescue NoMethodError
121
126
  false
122
127
  end
@@ -117,18 +117,18 @@ module Spec
117
117
  on("--autospec") {@options.autospec = true}
118
118
  on_tail(*OPTIONS[:help]) {parse_help}
119
119
  end
120
-
120
+
121
121
  def order!(argv, &blk)
122
122
  @argv = argv.dup
123
- @argv = (@argv.empty? & self.class.spec_command?) ? ['--help'] : @argv
124
-
123
+ @argv = (@argv.empty? & self.class.spec_command?) ? ['--help'] : @argv
124
+
125
125
  # Parse options file first
126
126
  parse_file_options(:options_file, :parse_options_file)
127
-
127
+
128
128
  @options.argv = @argv.dup
129
- return if parse_file_options(:generate_options, :write_generated_options)
129
+ return if parse_file_options(:generate_options, :write_options_file)
130
130
  return if parse_drb
131
-
131
+
132
132
  super(@argv) do |file|
133
133
  if file =~ /^(.+):(\d+)$/
134
134
  file = $1
@@ -141,7 +141,7 @@ module Spec
141
141
 
142
142
  @options
143
143
  end
144
-
144
+
145
145
  protected
146
146
 
147
147
  def invoke_requires(requires)
@@ -149,11 +149,6 @@ module Spec
149
149
  require file
150
150
  end
151
151
  end
152
-
153
- def parse_options_file(options_file)
154
- option_file_args = IO.readlines(options_file).map {|l| l.chomp.split " "}.flatten
155
- @argv.push(*option_file_args)
156
- end
157
152
 
158
153
  def parse_file_options(option_name, action)
159
154
  # Remove the file option and the argument before handling the file
@@ -167,6 +162,12 @@ module Spec
167
162
  end
168
163
  end
169
164
 
165
+ if options_file.nil? &&
166
+ File.exist?('spec/spec.opts') &&
167
+ !@argv.any?{|a| a =~ /^\-/ }
168
+ options_file = 'spec/spec.opts'
169
+ end
170
+
170
171
  if options_file
171
172
  send(action, options_file)
172
173
  return true
@@ -174,8 +175,13 @@ module Spec
174
175
  return false
175
176
  end
176
177
  end
177
-
178
- def write_generated_options(options_file)
178
+
179
+ def parse_options_file(options_file)
180
+ option_file_args = File.readlines(options_file).map {|l| l.chomp.split " "}.flatten
181
+ @argv.push(*option_file_args)
182
+ end
183
+
184
+ def write_options_file(options_file)
179
185
  File.open(options_file, 'w') do |io|
180
186
  io.puts @argv.join("\n")
181
187
  end
@@ -207,7 +213,7 @@ module Spec
207
213
  def parse_help
208
214
  @out_stream.puts self
209
215
  exit if stdout?
210
- end
216
+ end
211
217
 
212
218
  def stdout?
213
219
  @out_stream == $stdout
@@ -28,7 +28,7 @@ module Spec
28
28
  }
29
29
 
30
30
  attr_accessor(
31
- :autospec, # hack to tell
31
+ :autospec, # hack to tell
32
32
  :filename_pattern,
33
33
  :backtrace_tweaker,
34
34
  :context_lines,
@@ -50,7 +50,7 @@ module Spec
50
50
  :argv
51
51
  )
52
52
  attr_reader :colour, :differ_class, :files, :examples, :example_groups
53
-
53
+
54
54
  def initialize(error_stream, output_stream)
55
55
  @error_stream = error_stream
56
56
  @output_stream = output_stream
@@ -74,15 +74,15 @@ module Spec
74
74
  @files_loaded = false
75
75
  @out_used = nil
76
76
  end
77
-
77
+
78
78
  def add_example_group(example_group)
79
79
  @example_groups << example_group
80
80
  end
81
-
81
+
82
82
  def line_number_requested?
83
83
  !!line_number
84
84
  end
85
-
85
+
86
86
  def example_line
87
87
  Spec::Runner::LineNumberQuery.new(self).example_line_for(files.first, line_number)
88
88
  end
@@ -96,6 +96,28 @@ module Spec
96
96
  require 'ruby-debug'
97
97
  end
98
98
 
99
+ def project_root # :nodoc:
100
+ require 'pathname'
101
+ @project_root ||= determine_project_root
102
+ end
103
+
104
+ def determine_project_root # :nodoc:
105
+ # This is borrowed (slightly modified) from Scott Taylors
106
+ # project_path project:
107
+ # http://github.com/smtlaissezfaire/project_path
108
+ Pathname(File.expand_path('.')).ascend do |path|
109
+ if File.exists?(File.join(path, "spec"))
110
+ return path
111
+ end
112
+ end
113
+ end
114
+
115
+ def add_dir_from_project_root_to_load_path(dir, load_path=$LOAD_PATH) # :nodoc:
116
+ return if project_root.nil?
117
+ full_dir = File.join(project_root, dir)
118
+ load_path.unshift full_dir unless load_path.include?(full_dir)
119
+ end
120
+
99
121
  def run_examples
100
122
  require_ruby_debug if debug
101
123
  return true unless examples_should_be_run?
@@ -104,21 +126,23 @@ module Spec
104
126
  runner = custom_runner || ExampleGroupRunner.new(self)
105
127
 
106
128
  unless @files_loaded
129
+ ['spec','lib'].each do |dir|
130
+ add_dir_from_project_root_to_load_path(dir)
131
+ end
107
132
  runner.load_files(files_to_load)
108
133
  @files_loaded = true
109
134
  end
110
-
135
+
111
136
  define_predicate_matchers
112
137
  plugin_mock_framework
138
+ ignore_backtrace_patterns
113
139
 
114
140
  # TODO - this has to happen after the files get loaded,
115
141
  # otherwise the before_suite_parts are not populated
116
142
  # from the configuration. There is no spec for this
117
143
  # directly, but features/before_and_after_blocks/before_and_after_blocks.story
118
144
  # will fail if this happens before the files are loaded.
119
- before_suite_parts.each do |part|
120
- part.call
121
- end
145
+ before_suite_parts.each { |part| part.call }
122
146
 
123
147
  if example_groups.empty?
124
148
  true
@@ -135,11 +159,11 @@ module Spec
135
159
  end
136
160
  end
137
161
  end
138
-
162
+
139
163
  def before_suite_parts
140
164
  Spec::Example::BeforeAndAfterHooks.before_suite_parts
141
165
  end
142
-
166
+
143
167
  def after_suite_parts
144
168
  Spec::Example::BeforeAndAfterHooks.after_suite_parts
145
169
  end
@@ -151,7 +175,7 @@ module Spec
151
175
  def examples_should_not_be_run
152
176
  @examples_should_be_run = false
153
177
  end
154
-
178
+
155
179
  def mock_framework
156
180
  # TODO - don't like this dependency - perhaps store this in here instead?
157
181
  Spec::Runner.configuration.mock_framework
@@ -204,7 +228,7 @@ module Spec
204
228
  @format_options ||= []
205
229
  @format_options << [format, where]
206
230
  end
207
-
231
+
208
232
  def formatters
209
233
  @format_options ||= [['progress', @output_stream]]
210
234
  @formatters ||= load_formatters(@format_options, EXAMPLE_FORMATTERS)
@@ -221,7 +245,7 @@ module Spec
221
245
  formatter_type.new(formatter_options, where)
222
246
  end
223
247
  end
224
-
248
+
225
249
  def formatter_options
226
250
  @formatter_options ||= OpenStruct.new(
227
251
  :colour => colour,
@@ -230,10 +254,13 @@ module Spec
230
254
  )
231
255
  end
232
256
 
257
+ def which_heckle_runner
258
+ ([/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM} || Spec::Ruby.version.to_f == 1.9) ? "spec/runner/heckle_runner_unsupported" : "spec/runner/heckle_runner"
259
+ end
260
+
233
261
  def load_heckle_runner(heckle)
234
262
  @format_options ||= [['silent', @output_stream]]
235
- suffix = ([/mswin/, /java/].detect{|p| p =~ RUBY_PLATFORM} || Spec::Ruby.version.to_f == 1.9) ? '_unsupported' : ''
236
- require "spec/runner/heckle_runner#{suffix}"
263
+ require which_heckle_runner
237
264
  @heckle_runner = ::Spec::Runner::HeckleRunner.new(heckle)
238
265
  end
239
266
 
@@ -257,11 +284,11 @@ module Spec
257
284
  end
258
285
  result
259
286
  end
260
-
287
+
261
288
  def dry_run?
262
289
  @dry_run == true
263
290
  end
264
-
291
+
265
292
  protected
266
293
 
267
294
  def define_predicate_matchers
@@ -271,7 +298,7 @@ module Spec
271
298
  end
272
299
  end
273
300
  end
274
-
301
+
275
302
  def plugin_mock_framework
276
303
  case mock_framework
277
304
  when Module
@@ -282,11 +309,15 @@ module Spec
282
309
  end
283
310
  end
284
311
 
312
+ def ignore_backtrace_patterns
313
+ @backtrace_tweaker.ignore_patterns Spec::Runner.configuration.ignored_backtrace_patterns
314
+ end
315
+
285
316
  def examples_should_be_run?
286
317
  return @examples_should_be_run unless @examples_should_be_run.nil?
287
318
  @examples_should_be_run = true
288
319
  end
289
-
320
+
290
321
  def differ_class=(klass)
291
322
  return unless klass
292
323
  @differ_class = klass
@@ -310,7 +341,7 @@ module Spec
310
341
  if $_spec_spec ; raise e ; else exit(1) ; end
311
342
  end
312
343
  end
313
-
344
+
314
345
  def custom_runner
315
346
  return nil unless custom_runner?
316
347
  klass_name, arg = ClassAndArgumentsParser.parse(user_input_for_runner)
@@ -321,13 +352,13 @@ module Spec
321
352
  def custom_runner?
322
353
  return user_input_for_runner ? true : false
323
354
  end
324
-
355
+
325
356
  def heckle
326
357
  heckle_runner = self.heckle_runner
327
358
  self.heckle_runner = nil
328
359
  heckle_runner.heckle_with
329
360
  end
330
-
361
+
331
362
  def sorted_files
332
363
  return sorter ? files.sort(&sorter) : files
333
364
  end