rspec-core 2.99.0 → 3.0.0

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 (216) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.sig +0 -0
  3. data/.yardopts +1 -0
  4. data/Changelog.md +339 -1
  5. data/License.txt +1 -0
  6. data/README.md +19 -37
  7. data/exe/rspec +2 -23
  8. data/lib/rspec/core/backport_random.rb +336 -0
  9. data/lib/rspec/core/backtrace_formatter.rb +70 -0
  10. data/lib/rspec/core/configuration.rb +479 -577
  11. data/lib/rspec/core/configuration_options.rb +71 -54
  12. data/lib/rspec/core/drb.rb +111 -0
  13. data/lib/rspec/core/dsl.rb +86 -18
  14. data/lib/rspec/core/example.rb +267 -119
  15. data/lib/rspec/core/example_group.rb +381 -393
  16. data/lib/rspec/core/filter_manager.rb +133 -114
  17. data/lib/rspec/core/flat_map.rb +18 -0
  18. data/lib/rspec/core/formatters/base_formatter.rb +51 -125
  19. data/lib/rspec/core/formatters/base_text_formatter.rb +34 -286
  20. data/lib/rspec/core/formatters/console_codes.rb +24 -1
  21. data/lib/rspec/core/formatters/deprecation_formatter.rb +25 -26
  22. data/lib/rspec/core/formatters/documentation_formatter.rb +27 -25
  23. data/lib/rspec/core/formatters/helpers.rb +14 -36
  24. data/lib/rspec/core/formatters/html_formatter.rb +58 -65
  25. data/lib/rspec/core/formatters/html_printer.rb +12 -18
  26. data/lib/rspec/core/formatters/json_formatter.rb +54 -31
  27. data/lib/rspec/core/formatters/profile_formatter.rb +67 -0
  28. data/lib/rspec/core/formatters/progress_formatter.rb +11 -15
  29. data/lib/rspec/core/formatters/snippet_extractor.rb +22 -11
  30. data/lib/rspec/core/formatters.rb +90 -43
  31. data/lib/rspec/core/hooks.rb +325 -270
  32. data/lib/rspec/core/memoized_helpers.rb +45 -156
  33. data/lib/rspec/core/metadata.rb +284 -236
  34. data/lib/rspec/core/metadata_filter.rb +86 -0
  35. data/lib/rspec/core/mocking_adapters/flexmock.rb +29 -0
  36. data/lib/rspec/core/{mocking/with_mocha.rb → mocking_adapters/mocha.rb} +19 -16
  37. data/lib/rspec/core/mocking_adapters/null.rb +12 -0
  38. data/lib/rspec/core/mocking_adapters/rr.rb +29 -0
  39. data/lib/rspec/core/mocking_adapters/rspec.rb +30 -0
  40. data/lib/rspec/core/notifications.rb +511 -0
  41. data/lib/rspec/core/option_parser.rb +49 -74
  42. data/lib/rspec/core/ordering.rb +156 -0
  43. data/lib/rspec/core/pending.rb +94 -96
  44. data/lib/rspec/core/project_initializer/.rspec +3 -0
  45. data/lib/rspec/core/project_initializer/spec/spec_helper.rb +78 -0
  46. data/lib/rspec/core/project_initializer.rb +24 -64
  47. data/lib/rspec/core/rake_task.rb +44 -130
  48. data/lib/rspec/core/reporter.rb +76 -59
  49. data/lib/rspec/core/ruby_project.rb +2 -1
  50. data/lib/rspec/core/runner.rb +117 -52
  51. data/lib/rspec/core/shared_context.rb +10 -10
  52. data/lib/rspec/core/shared_example_group.rb +108 -121
  53. data/lib/rspec/core/version.rb +3 -1
  54. data/lib/rspec/core/warnings.rb +40 -0
  55. data/lib/rspec/core/world.rb +66 -10
  56. data/lib/rspec/core.rb +64 -104
  57. data.tar.gz.sig +3 -0
  58. metadata +75 -322
  59. metadata.gz.sig +1 -0
  60. data/exe/autospec +0 -13
  61. data/features/Autotest.md +0 -38
  62. data/features/README.md +0 -17
  63. data/features/Upgrade.md +0 -364
  64. data/features/command_line/README.md +0 -28
  65. data/features/command_line/example_name_option.feature +0 -97
  66. data/features/command_line/exit_status.feature +0 -82
  67. data/features/command_line/format_option.feature +0 -75
  68. data/features/command_line/init.feature +0 -18
  69. data/features/command_line/line_number_appended_to_path.feature +0 -140
  70. data/features/command_line/line_number_option.feature +0 -53
  71. data/features/command_line/order.feature +0 -26
  72. data/features/command_line/pattern_option.feature +0 -49
  73. data/features/command_line/rake_task.feature +0 -122
  74. data/features/command_line/require_option.feature +0 -43
  75. data/features/command_line/ruby.feature +0 -22
  76. data/features/command_line/tag.feature +0 -98
  77. data/features/command_line/warnings_option.feature +0 -29
  78. data/features/configuration/alias_example_to.feature +0 -48
  79. data/features/configuration/backtrace_clean_patterns.feature +0 -102
  80. data/features/configuration/custom_settings.feature +0 -84
  81. data/features/configuration/default_path.feature +0 -38
  82. data/features/configuration/deprecation_stream.feature +0 -58
  83. data/features/configuration/fail_fast.feature +0 -77
  84. data/features/configuration/failure_exit_code.feature +0 -36
  85. data/features/configuration/order_and_seed.feature +0 -3
  86. data/features/configuration/output_stream.feature +0 -24
  87. data/features/configuration/pattern.feature +0 -38
  88. data/features/configuration/profile.feature +0 -220
  89. data/features/configuration/read_options_from_file.feature +0 -90
  90. data/features/configuration/run_all_when_everything_filtered.feature +0 -76
  91. data/features/configuration/show_failures_in_pending_blocks.feature +0 -61
  92. data/features/configuration/treat_symbols_as_metadata_keys_with_true_values.feature +0 -52
  93. data/features/example_groups/basic_structure.feature +0 -55
  94. data/features/example_groups/shared_context.feature +0 -74
  95. data/features/example_groups/shared_examples.feature +0 -294
  96. data/features/expectation_framework_integration/configure_expectation_framework.feature +0 -197
  97. data/features/filtering/exclusion_filters.feature +0 -138
  98. data/features/filtering/if_and_unless.feature +0 -168
  99. data/features/filtering/inclusion_filters.feature +0 -105
  100. data/features/formatters/configurable_colors.feature +0 -31
  101. data/features/formatters/custom_formatter.feature +0 -36
  102. data/features/formatters/json_formatter.feature +0 -30
  103. data/features/formatters/text_formatter.feature +0 -46
  104. data/features/helper_methods/arbitrary_methods.feature +0 -40
  105. data/features/helper_methods/let.feature +0 -50
  106. data/features/helper_methods/modules.feature +0 -149
  107. data/features/hooks/around_hooks.feature +0 -343
  108. data/features/hooks/before_and_after_hooks.feature +0 -427
  109. data/features/hooks/filtering.feature +0 -234
  110. data/features/metadata/current_example.feature +0 -56
  111. data/features/metadata/described_class.feature +0 -17
  112. data/features/metadata/user_defined.feature +0 -113
  113. data/features/mock_framework_integration/use_any_framework.feature +0 -106
  114. data/features/mock_framework_integration/use_flexmock.feature +0 -96
  115. data/features/mock_framework_integration/use_mocha.feature +0 -97
  116. data/features/mock_framework_integration/use_rr.feature +0 -98
  117. data/features/mock_framework_integration/use_rspec.feature +0 -97
  118. data/features/pending/pending_examples.feature +0 -229
  119. data/features/spec_files/arbitrary_file_suffix.feature +0 -13
  120. data/features/step_definitions/additional_cli_steps.rb +0 -49
  121. data/features/subject/attribute_of_subject.feature +0 -124
  122. data/features/subject/explicit_subject.feature +0 -101
  123. data/features/subject/implicit_subject.feature +0 -63
  124. data/features/subject/one_liner_syntax.feature +0 -71
  125. data/features/support/env.rb +0 -14
  126. data/features/support/rubinius.rb +0 -6
  127. data/lib/autotest/discover.rb +0 -10
  128. data/lib/autotest/rspec2.rb +0 -77
  129. data/lib/rspec/core/backtrace_cleaner.rb +0 -46
  130. data/lib/rspec/core/backward_compatibility.rb +0 -55
  131. data/lib/rspec/core/caller_filter.rb +0 -60
  132. data/lib/rspec/core/command_line.rb +0 -47
  133. data/lib/rspec/core/deprecated_mutable_array_proxy.rb +0 -32
  134. data/lib/rspec/core/deprecation.rb +0 -26
  135. data/lib/rspec/core/drb_command_line.rb +0 -26
  136. data/lib/rspec/core/drb_options.rb +0 -87
  137. data/lib/rspec/core/extensions/instance_eval_with_args.rb +0 -44
  138. data/lib/rspec/core/extensions/kernel.rb +0 -9
  139. data/lib/rspec/core/extensions/module_eval_with_args.rb +0 -38
  140. data/lib/rspec/core/extensions/ordered.rb +0 -27
  141. data/lib/rspec/core/formatters/text_mate_formatter.rb +0 -34
  142. data/lib/rspec/core/metadata_hash_builder.rb +0 -97
  143. data/lib/rspec/core/mocking/with_absolutely_nothing.rb +0 -11
  144. data/lib/rspec/core/mocking/with_flexmock.rb +0 -27
  145. data/lib/rspec/core/mocking/with_rr.rb +0 -27
  146. data/lib/rspec/core/mocking/with_rspec.rb +0 -27
  147. data/lib/rspec/core/shared_example_group/collection.rb +0 -45
  148. data/spec/autotest/discover_spec.rb +0 -49
  149. data/spec/autotest/failed_results_re_spec.rb +0 -45
  150. data/spec/autotest/rspec_spec.rb +0 -133
  151. data/spec/command_line/order_spec.rb +0 -204
  152. data/spec/rspec/core/backtrace_cleaner_spec.rb +0 -68
  153. data/spec/rspec/core/caller_filter_spec.rb +0 -58
  154. data/spec/rspec/core/command_line_spec.rb +0 -127
  155. data/spec/rspec/core/command_line_spec_output.txt +0 -0
  156. data/spec/rspec/core/configuration_options_spec.rb +0 -417
  157. data/spec/rspec/core/configuration_spec.rb +0 -2072
  158. data/spec/rspec/core/deprecation_spec.rb +0 -27
  159. data/spec/rspec/core/deprecations_spec.rb +0 -59
  160. data/spec/rspec/core/drb_command_line_spec.rb +0 -102
  161. data/spec/rspec/core/drb_options_spec.rb +0 -193
  162. data/spec/rspec/core/dsl_spec.rb +0 -25
  163. data/spec/rspec/core/example_group_spec.rb +0 -1337
  164. data/spec/rspec/core/example_spec.rb +0 -502
  165. data/spec/rspec/core/filter_manager_spec.rb +0 -246
  166. data/spec/rspec/core/formatters/base_formatter_spec.rb +0 -108
  167. data/spec/rspec/core/formatters/base_text_formatter_spec.rb +0 -524
  168. data/spec/rspec/core/formatters/console_codes_spec.rb +0 -50
  169. data/spec/rspec/core/formatters/deprecation_formatter_spec.rb +0 -263
  170. data/spec/rspec/core/formatters/documentation_formatter_spec.rb +0 -89
  171. data/spec/rspec/core/formatters/helpers_spec.rb +0 -104
  172. data/spec/rspec/core/formatters/html_formatted.html +0 -397
  173. data/spec/rspec/core/formatters/html_formatter_spec.rb +0 -131
  174. data/spec/rspec/core/formatters/json_formatter_spec.rb +0 -115
  175. data/spec/rspec/core/formatters/progress_formatter_spec.rb +0 -30
  176. data/spec/rspec/core/formatters/snippet_extractor_spec.rb +0 -26
  177. data/spec/rspec/core/formatters/text_mate_formatted.html +0 -397
  178. data/spec/rspec/core/formatters/text_mate_formatter_spec.rb +0 -107
  179. data/spec/rspec/core/hooks_filtering_spec.rb +0 -227
  180. data/spec/rspec/core/hooks_spec.rb +0 -269
  181. data/spec/rspec/core/kernel_extensions_spec.rb +0 -9
  182. data/spec/rspec/core/memoized_helpers_spec.rb +0 -776
  183. data/spec/rspec/core/metadata_spec.rb +0 -514
  184. data/spec/rspec/core/option_parser_spec.rb +0 -297
  185. data/spec/rspec/core/pending_example_spec.rb +0 -260
  186. data/spec/rspec/core/pending_spec.rb +0 -27
  187. data/spec/rspec/core/project_initializer_spec.rb +0 -130
  188. data/spec/rspec/core/rake_task_spec.rb +0 -202
  189. data/spec/rspec/core/reporter_spec.rb +0 -167
  190. data/spec/rspec/core/resources/a_bar.rb +0 -0
  191. data/spec/rspec/core/resources/a_foo.rb +0 -0
  192. data/spec/rspec/core/resources/a_spec.rb +0 -1
  193. data/spec/rspec/core/resources/custom_example_group_runner.rb +0 -14
  194. data/spec/rspec/core/resources/formatter_specs.rb +0 -60
  195. data/spec/rspec/core/resources/utf8_encoded.rb +0 -8
  196. data/spec/rspec/core/rspec_matchers_spec.rb +0 -45
  197. data/spec/rspec/core/ruby_project_spec.rb +0 -26
  198. data/spec/rspec/core/runner_spec.rb +0 -82
  199. data/spec/rspec/core/shared_context_spec.rb +0 -114
  200. data/spec/rspec/core/shared_example_group/collection_spec.rb +0 -70
  201. data/spec/rspec/core/shared_example_group_spec.rb +0 -138
  202. data/spec/rspec/core/world_spec.rb +0 -142
  203. data/spec/rspec/core_spec.rb +0 -108
  204. data/spec/spec_helper.rb +0 -135
  205. data/spec/support/config_options_helper.rb +0 -15
  206. data/spec/support/helper_methods.rb +0 -55
  207. data/spec/support/in_sub_process.rb +0 -37
  208. data/spec/support/isolate_load_path_mutation.rb +0 -6
  209. data/spec/support/isolated_directory.rb +0 -10
  210. data/spec/support/isolated_home_directory.rb +0 -16
  211. data/spec/support/matchers.rb +0 -65
  212. data/spec/support/mathn_integration_support.rb +0 -12
  213. data/spec/support/sandboxed_mock_space.rb +0 -116
  214. data/spec/support/shared_example_groups.rb +0 -42
  215. data/spec/support/silence_dsl_deprecations.rb +0 -32
  216. data/spec/support/spec_files.rb +0 -44
@@ -1,8 +1,8 @@
1
1
  require 'fileutils'
2
- require 'rspec/core/backtrace_cleaner'
3
- require 'rspec/core/ruby_project'
4
- require 'rspec/core/deprecated_mutable_array_proxy'
5
- require 'rspec/core/formatters/deprecation_formatter'
2
+
3
+ RSpec::Support.require_rspec_core "backtrace_formatter"
4
+ RSpec::Support.require_rspec_core "ruby_project"
5
+ RSpec::Support.require_rspec_core "formatters/deprecation_formatter"
6
6
 
7
7
  module RSpec
8
8
  module Core
@@ -22,9 +22,9 @@ module RSpec
22
22
  #
23
23
  # @example Hooks
24
24
  # RSpec.configure do |c|
25
- # c.before(:suite) { establish_connection }
26
- # c.before(:each) { log_in_as :authorized }
27
- # c.around(:each) { |ex| Database.transaction(&ex) }
25
+ # c.before(:suite) { establish_connection }
26
+ # c.before(:example) { log_in_as :authorized }
27
+ # c.around(:example) { |ex| Database.transaction(&ex) }
28
28
  # end
29
29
  #
30
30
  # @see RSpec.configure
@@ -32,6 +32,7 @@ module RSpec
32
32
  class Configuration
33
33
  include RSpec::Core::Hooks
34
34
 
35
+ # @private
35
36
  class MustBeConfiguredBeforeExampleGroupsError < StandardError; end
36
37
 
37
38
  # @private
@@ -42,11 +43,6 @@ module RSpec
42
43
  end
43
44
  end
44
45
 
45
- # @private
46
- def self.deprecate_alias_key
47
- RSpec.deprecate("add_setting with :alias option", :replacement => ":alias_with")
48
- end
49
-
50
46
  # @private
51
47
  def self.define_aliases(name, alias_name)
52
48
  alias_method alias_name, name
@@ -65,39 +61,76 @@ module RSpec
65
61
  # `Configuration` instance rather than this class method.
66
62
  def self.add_setting(name, opts={})
67
63
  raise "Use the instance add_setting method if you want to set a default" if opts.has_key?(:default)
68
- if opts[:alias]
69
- deprecate_alias_key
70
- define_aliases(opts[:alias], name)
71
- else
72
- attr_writer name
73
- define_reader name
74
- define_predicate_for name
75
- end
76
- [opts[:alias_with]].flatten.compact.each do |alias_name|
64
+ attr_writer name
65
+ add_read_only_setting name
66
+
67
+ Array(opts[:alias_with]).each do |alias_name|
77
68
  define_aliases(name, alias_name)
78
69
  end
79
70
  end
80
71
 
72
+ # @private
73
+ #
74
+ # As `add_setting` but only add the reader
75
+ def self.add_read_only_setting(name, opts={})
76
+ raise "Use the instance add_setting method if you want to set a default" if opts.has_key?(:default)
77
+ define_reader name
78
+ define_predicate_for name
79
+ end
80
+
81
81
  # @macro [attach] add_setting
82
- # @attribute $1
82
+ # @!attribute [rw] $1
83
+ # @!method $1=(value)
84
+ #
85
+ # @macro [attach] define_reader
86
+ # @!attribute [r] $1
83
87
 
88
+ # @macro add_setting
84
89
  # Path to use if no path is provided to the `rspec` command (default:
85
90
  # `"spec"`). Allows you to just type `rspec` instead of `rspec spec` to
86
91
  # run all the examples in the `spec` directory.
87
92
  add_setting :default_path
88
93
 
94
+ # @macro add_setting
89
95
  # Run examples over DRb (default: `false`). RSpec doesn't supply the DRb
90
96
  # server, but you can use tools like spork.
91
97
  add_setting :drb
92
98
 
99
+ # @macro add_setting
93
100
  # The drb_port (default: nil).
94
101
  add_setting :drb_port
95
102
 
103
+ # @macro add_setting
96
104
  # Default: `$stderr`.
97
105
  add_setting :error_stream
98
106
 
99
- # Default: `$stderr`.
107
+ # Indicates if the DSL has been exposed off of modules and `main`.
108
+ # Default: true
109
+ def expose_dsl_globally?
110
+ Core::DSL.exposed_globally?
111
+ end
112
+
113
+ # Use this to expose the core RSpec DSL via `Module` and the `main`
114
+ # object. It will be set automatically but you can override it to
115
+ # remove the DSL.
116
+ # Default: true
117
+ def expose_dsl_globally=(value)
118
+ if value
119
+ Core::DSL.expose_globally!
120
+ Core::SharedExampleGroup::TopLevelDSL.expose_globally!
121
+ else
122
+ Core::DSL.remove_globally!
123
+ Core::SharedExampleGroup::TopLevelDSL.remove_globally!
124
+ end
125
+ end
126
+
127
+ # Determines where deprecation warnings are printed.
128
+ # Defaults to `$stderr`.
129
+ # @return [IO, String] IO to write to or filename to write to
100
130
  define_reader :deprecation_stream
131
+
132
+ # Determines where deprecation warnings are printed.
133
+ # @param value [IO, String] IO to write to or filename to write to
101
134
  def deprecation_stream=(value)
102
135
  if @reporter && !value.equal?(@deprecation_stream)
103
136
  warn "RSpec's reporter has already been initialized with " +
@@ -110,21 +143,34 @@ module RSpec
110
143
  end
111
144
  end
112
145
 
146
+ # @macro add_setting
113
147
  # Clean up and exit after the first failure (default: `false`).
114
148
  add_setting :fail_fast
115
149
 
150
+ # @macro add_setting
151
+ # Prints the formatter output of your suite without running any
152
+ # examples or hooks.
153
+ add_setting :dry_run
154
+
155
+ # @macro add_setting
116
156
  # The exit code to return if there are any failures (default: 1).
117
157
  add_setting :failure_exit_code
118
158
 
159
+ # @macro define_reader
119
160
  # Indicates files configured to be required
120
161
  define_reader :requires
121
162
 
122
- # Returns dirs that have been prepended to the load path by #lib=
163
+ # @macro define_reader
164
+ # Returns dirs that have been prepended to the load path by the `-I` command line option
123
165
  define_reader :libs
124
166
 
167
+ # @macro add_setting
168
+ # Determines where RSpec will send its output.
125
169
  # Default: `$stdout`.
126
- # Also known as `output` and `out`
127
170
  define_reader :output_stream
171
+
172
+ # Set the output stream for reporter
173
+ # @attr value [IO] value for output, defaults to $stdout
128
174
  def output_stream=(value)
129
175
  if @reporter && !value.equal?(@output_stream)
130
176
  warn "RSpec's reporter has already been initialized with " +
@@ -136,170 +182,116 @@ module RSpec
136
182
  end
137
183
  end
138
184
 
139
- # @deprecated use RSpec::Core::Configuration#output_stream instead.
140
- def output
141
- RSpec.deprecate("RSpec::Core::Configuration#output", :replacement => "RSpec::Core::Configuration#output_stream")
142
- output_stream
143
- end
144
-
145
- # @deprecated use RSpec::Core::Configuration#output_stream= instead.
146
- def output=(value)
147
- RSpec.deprecate("RSpec::Core::Configuration#output=", :replacement => "RSpec::Core::Configuration#output_stream=")
148
- self.output_stream = value
149
- end
150
-
151
- # @deprecated use RSpec::Core::Configuration#output_stream instead.
152
- def out
153
- RSpec.deprecate("RSpec::Core::Configuration#out", :replacement => "RSpec::Core::Configuration#output_stream")
154
- output_stream
155
- end
156
-
157
- # @deprecated use RSpec::Core::Configuration#output_stream= instead.
158
- def out=(value)
159
- RSpec.deprecate("RSpec::Core::Configuration#out=", :replacement => "RSpec::Core::Configuration#output_stream=")
160
- self.output_stream = value
161
- end
162
-
185
+ # @macro add_setting
163
186
  # Load files matching this pattern (default: `'**/*_spec.rb'`)
164
187
  add_setting :pattern
165
188
 
166
- def filename_pattern
167
- RSpec.deprecate "`RSpec::Core::Configuration#filename_pattern`",
168
- :replacement => "`RSpec::Core::Configuration#pattern`"
169
- pattern
170
- end
171
-
172
- def pattern= value
189
+ # Set pattern to match files to load
190
+ # @attr value [String] the filename pattern to filter spec files by
191
+ def pattern=(value)
173
192
  if @spec_files_loaded
174
- Kernel.warn "WARNING: Configuring `pattern` to #{value} has no effect since RSpec has already loaded the spec files. Called from #{CallerFilter.first_non_rspec_line}"
193
+ RSpec.warning "Configuring `pattern` to #{value} has no effect since RSpec has already loaded the spec files."
175
194
  end
176
195
  @pattern = value
177
196
  end
178
197
 
179
- def filename_pattern=(value)
180
- RSpec.deprecate "`RSpec::Core::Configuration#filename_pattern=`",
181
- :replacement => "`RSpec::Core::Configuration#pattern=`"
182
- self.pattern = value
183
- end
184
-
185
-
198
+ # @macro add_setting
186
199
  # Report the times for the slowest examples (default: `false`).
187
200
  # Use this to specify the number of examples to include in the profile.
188
201
  add_setting :profile_examples
189
202
 
203
+ # @macro add_setting
190
204
  # Run all examples if none match the configured filters (default: `false`).
191
205
  add_setting :run_all_when_everything_filtered
192
206
 
193
- # Allow user to configure their own success/pending/failure colors
194
- # @param [Symbol] should be one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
207
+ # @macro add_setting
208
+ # Color to use to indicate success.
209
+ # @param color [Symbol] defaults to `:green` but can be set to one of the
210
+ # following: `[:black, :white, :red, :green, :yellow,
211
+ # :blue, :magenta, :cyan]`
195
212
  add_setting :success_color
196
- add_setting :pending_color
197
- add_setting :failure_color
198
- add_setting :default_color
199
- add_setting :fixed_color
200
- add_setting :detail_color
201
213
 
202
- # Seed for random ordering (default: generated randomly each run).
203
- #
204
- # When you run specs with `--order random`, RSpec generates a random seed
205
- # for the randomization and prints it to the `output_stream` (assuming
206
- # you're using RSpec's built-in formatters). If you discover an ordering
207
- # dependency (i.e. examples fail intermittently depending on order), set
208
- # this (on Configuration or on the command line with `--seed`) to run
209
- # using the same seed while you debug the issue.
210
- #
211
- # We recommend, actually, that you use the command line approach so you
212
- # don't accidentally leave the seed encoded.
213
- define_reader :seed
214
-
215
- # When a block passed to pending fails (as expected), display the failure
216
- # without reporting it as a failure (default: false).
217
- def show_failures_in_pending_blocks=(value)
218
- RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\|/, ''))
219
- |RSpec.configuration.show_failures_in_pending_blocks is being removed
220
- |with no replacement. Called from #{CallerFilter.first_non_rspec_line}.
221
- EOS
222
-
223
- @show_failures_in_pending_blocks = value
224
- end
214
+ # @macro add_setting
215
+ # Color to use to print pending examples.
216
+ # @param color [Symbol] defaults to `:yellow` but can be set to one of the
217
+ # following: `[:black, :white, :red, :green, :yellow,
218
+ # :blue, :magenta, :cyan]`
219
+ add_setting :pending_color
225
220
 
226
- def show_failures_in_pending_blocks
227
- RSpec.warn_deprecation(<<-EOS.gsub(/^\s+\|/, ''))
228
- |RSpec.configuration.show_failures_in_pending_blocks is being removed
229
- |with no replacement. Called from #{CallerFilter.first_non_rspec_line}.
230
- EOS
221
+ # @macro add_setting
222
+ # Color to use to indicate failure.
223
+ # @param color [Symbol] defaults to `:red` but can be set to one of the
224
+ # following: `[:black, :white, :red, :green, :yellow,
225
+ # :blue, :magenta, :cyan]`
226
+ add_setting :failure_color
231
227
 
232
- @show_failures_in_pending_blocks
233
- end
228
+ # @macro add_setting
229
+ # The default output color.
230
+ # @param color [Symbol] defaults to `:white` but can be set to one of the
231
+ # following:`[:black, :white, :red, :green, :yellow,
232
+ # :blue, :magenta, :cyan]`
233
+ add_setting :default_color
234
234
 
235
- def show_failures_in_pending_blocks?
236
- !!show_failures_in_pending_blocks
237
- end
235
+ # @macro add_setting
236
+ # Color used when a pending example is fixed.
237
+ # @param color [Symbol] defaults to `:blue` but can be set to one of the
238
+ # following: `[:black, :white, :red, :green, :yellow,
239
+ # :blue, :magenta, :cyan]`
240
+ add_setting :fixed_color
238
241
 
239
- # Convert symbols to hashes with the symbol as a key with a value of
240
- # `true` (default: false).
241
- #
242
- # This allows you to tag a group or example like this:
243
- #
244
- # describe "something slow", :slow do
245
- # # ...
246
- # end
247
- #
248
- # ... instead of having to type:
249
- #
250
- # describe "something slow", :slow => true do
251
- # # ...
252
- # end
253
- add_setting :treat_symbols_as_metadata_keys_with_true_values
242
+ # @macro add_setting
243
+ # Color used to print details.
244
+ # @param color [Symbol] defaults to `:cyan` but can be set to one of the
245
+ # following: `[:black, :white, :red, :green, :yellow,
246
+ # :blue, :magenta, :cyan]`
247
+ add_setting :detail_color
254
248
 
249
+ # Deprecated. This config option was added in RSpec 2 to pave the way
250
+ # for this being the default behavior in RSpec 3. Now this option is
251
+ # a no-op.
255
252
  def treat_symbols_as_metadata_keys_with_true_values=(value)
256
- unless value
257
- RSpec.deprecate("RSpec.configuration.treat_symbols_as_metadata_keys_with_true_values = false")
258
- end
259
-
260
- @treat_symbols_as_metadata_keys_with_true_values = value
253
+ RSpec.deprecate("RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values=",
254
+ :message => "RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values= " +
255
+ "is deprecated, it is now set to true as default and setting it to false has no effect.")
261
256
  end
262
257
 
258
+ # Record the start time of the spec suite to measure load time
259
+ add_setting :start_time
260
+
263
261
  # @private
264
262
  add_setting :tty
265
263
  # @private
266
264
  add_setting :include_or_extend_modules
267
265
  # @private
268
- add_setting :files_to_run
266
+ attr_writer :files_to_run
269
267
  # @private
270
268
  add_setting :expecting_with_rspec
271
269
  # @private
272
270
  attr_accessor :filter_manager
273
-
274
- attr_reader :backtrace_formatter
275
-
276
- def backtrace_cleaner
277
- RSpec.deprecate "`RSpec::Core::Configuration#backtrace_cleaner`",
278
- :replacement => "`RSpec::Core::Configuration#backtrace_formatter`"
279
- @backtrace_formatter
280
- end
271
+ # @private
272
+ attr_reader :backtrace_formatter, :ordering_manager
281
273
 
282
274
  def initialize
275
+ @start_time = $_rspec_core_load_started_at || ::RSpec::Core::Time.now
283
276
  @expectation_frameworks = []
284
277
  @include_or_extend_modules = []
285
278
  @mock_framework = nil
286
- @files_to_run = []
279
+ @files_or_directories_to_run = []
287
280
  @color = false
288
- @order = nil
289
281
  @pattern = '**/*_spec.rb'
290
282
  @failure_exit_code = 1
291
283
  @spec_files_loaded = false
292
284
 
293
- @backtrace_formatter = BacktraceCleaner.new
285
+ @backtrace_formatter = BacktraceFormatter.new
294
286
 
295
287
  @default_path = 'spec'
296
288
  @deprecation_stream = $stderr
297
289
  @output_stream = $stdout
298
290
  @reporter = nil
291
+ @reporter_buffer = nil
299
292
  @filter_manager = FilterManager.new
293
+ @ordering_manager = Ordering::ConfigurationManager.new
300
294
  @preferred_options = {}
301
- @seed = srand % 0xFFFF
302
- @ordering_already_forced = false
303
295
  @failure_color = :red
304
296
  @success_color = :green
305
297
  @pending_color = :yellow
@@ -309,20 +301,15 @@ module RSpec
309
301
  @profile_examples = false
310
302
  @requires = []
311
303
  @libs = []
312
- @show_failures_in_pending_blocks = false
304
+ @derived_metadata_blocks = []
313
305
  end
314
306
 
315
307
  # @private
316
308
  #
317
309
  # Used to set higher priority option values from the command line.
318
310
  def force(hash)
319
- if hash.has_key?(:seed)
320
- hash[:order], hash[:seed] = order_and_seed_from_seed(hash[:seed], true)
321
- elsif hash.has_key?(:order)
322
- set_order_and_seed(hash, true)
323
- end
311
+ ordering_manager.force(hash)
324
312
  @preferred_options.merge!(hash)
325
- self.warnings = value_for :warnings, nil
326
313
  end
327
314
 
328
315
  # @private
@@ -369,10 +356,10 @@ module RSpec
369
356
  # RSpec.configuration.foo? # returns true if foo returns anything but nil or false
370
357
  def add_setting(name, opts={})
371
358
  default = opts.delete(:default)
372
- (class << self; self; end).class_eval do
359
+ (class << self; self; end).class_exec do
373
360
  add_setting(name, opts)
374
361
  end
375
- send("#{name}=", default) if default
362
+ __send__("#{name}=", default) if default
376
363
  end
377
364
 
378
365
  # Returns the configured mock framework adapter module
@@ -386,61 +373,53 @@ module RSpec
386
373
  mock_with framework
387
374
  end
388
375
 
389
- # The patterns to discard from backtraces. Deprecated, use
390
- # Configuration#backtrace_exclusion_patterns instead
376
+ # Regexps used to exclude lines from backtraces.
391
377
  #
392
- # Defaults to RSpec::Core::BacktraceCleaner::DEFAULT_EXCLUSION_PATTERNS
378
+ # Excludes lines from ruby (and jruby) source, installed gems, anything
379
+ # in any "bin" directory, and any of the rspec libs (outside gem
380
+ # installs) by default.
393
381
  #
394
- # One can replace the list by using the setter or modify it through the
395
- # getter
382
+ # You can modify the list via the getter, or replace it with the setter.
396
383
  #
397
384
  # To override this behaviour and display a full backtrace, use
398
385
  # `--backtrace`on the command line, in a `.rspec` file, or in the
399
386
  # `rspec_options` attribute of RSpec's rake task.
400
- def backtrace_clean_patterns
401
- RSpec.deprecate("RSpec::Core::Configuration#backtrace_clean_patterns",
402
- :replacement => "RSpec::Core::Configuration#backtrace_exclusion_patterns")
387
+ def backtrace_exclusion_patterns
403
388
  @backtrace_formatter.exclusion_patterns
404
389
  end
405
390
 
406
- def backtrace_clean_patterns=(patterns)
407
- RSpec.deprecate("RSpec::Core::Configuration#backtrace_clean_patterns",
408
- :replacement => "RSpec::Core::Configuration#backtrace_exclusion_patterns")
391
+ # Set regular expressions used to exclude lines in backtrace
392
+ # @param patterns [Regexp] set the backtrace exlusion pattern
393
+ def backtrace_exclusion_patterns=(patterns)
409
394
  @backtrace_formatter.exclusion_patterns = patterns
410
395
  end
411
396
 
412
- # The patterns to always include to backtraces.
397
+ # Regexps used to include lines in backtraces.
398
+ #
399
+ # Defaults to [Regexp.new Dir.getwd].
413
400
  #
414
- # Defaults to [Regexp.new Dir.getwd] if the current working directory
415
- # matches any of the exclusion patterns. Otherwise it defaults to empty.
401
+ # Lines that match an exclusion _and_ an inclusion pattern
402
+ # will be included.
416
403
  #
417
- # One can replace the list by using the setter or modify it through the
418
- # getter
404
+ # You can modify the list via the getter, or replace it with the setter.
419
405
  def backtrace_inclusion_patterns
420
406
  @backtrace_formatter.inclusion_patterns
421
407
  end
422
408
 
409
+ # Set regular expressions used to include lines in backtrace
410
+ # @attr patterns [Regexp] set backtrace_formatter inclusion_patterns
423
411
  def backtrace_inclusion_patterns=(patterns)
424
412
  @backtrace_formatter.inclusion_patterns = patterns
425
413
  end
426
414
 
427
- # The patterns to discard from backtraces.
428
- #
429
- # Defaults to RSpec::Core::BacktraceCleaner::DEFAULT_EXCLUSION_PATTERNS
430
- #
431
- # One can replace the list by using the setter or modify it through the
432
- # getter
433
- #
434
- # To override this behaviour and display a full backtrace, use
435
- # `--backtrace`on the command line, in a `.rspec` file, or in the
436
- # `rspec_options` attribute of RSpec's rake task.
437
- def backtrace_exclusion_patterns
438
- @backtrace_formatter.exclusion_patterns
439
- end
440
-
441
- def backtrace_exclusion_patterns=(patterns)
442
- @backtrace_formatter.exclusion_patterns = patterns
443
- end
415
+ # @private
416
+ MOCKING_ADAPTERS = {
417
+ :rspec => :RSpec,
418
+ :flexmock => :Flexmock,
419
+ :rr => :RR,
420
+ :mocha => :Mocha,
421
+ :nothing => :Null
422
+ }
444
423
 
445
424
  # Sets the mock framework adapter module.
446
425
  #
@@ -459,8 +438,8 @@ module RSpec
459
438
  # - called before each example
460
439
  #
461
440
  # verify_mocks_for_rspec
462
- # - called after each example. Framework should raise an exception
463
- # when expectations fail
441
+ # - called after each example if the example hasn't yet failed.
442
+ # Framework should raise an exception when expectations fail
464
443
  #
465
444
  # teardown_mocks_for_rspec
466
445
  # - called after verify_mocks_for_rspec (even if there are errors)
@@ -472,28 +451,17 @@ module RSpec
472
451
  # mod_config.custom_setting = true
473
452
  # end
474
453
  def mock_with(framework)
475
- framework_module = case framework
476
- when Module
477
- framework
478
- when String, Symbol
479
- require case framework.to_s
480
- when /rspec/i
481
- deprecate_unless_mock_adapter_name_is_exact(framework, :rspec)
482
- 'rspec/core/mocking/with_rspec'
483
- when /mocha/i
484
- deprecate_unless_mock_adapter_name_is_exact(framework, :mocha)
485
- 'rspec/core/mocking/with_mocha'
486
- when /rr/i
487
- deprecate_unless_mock_adapter_name_is_exact(framework, :rr)
488
- 'rspec/core/mocking/with_rr'
489
- when /flexmock/i
490
- deprecate_unless_mock_adapter_name_is_exact(framework, :flexmock)
491
- 'rspec/core/mocking/with_flexmock'
492
- else
493
- deprecate_unless_mock_adapter_name_is_exact(framework, :nothing)
494
- 'rspec/core/mocking/with_absolutely_nothing'
495
- end
496
- RSpec::Core::MockFrameworkAdapter
454
+ framework_module = if framework.is_a?(Module)
455
+ framework
456
+ else
457
+ const_name = MOCKING_ADAPTERS.fetch(framework) do
458
+ raise ArgumentError,
459
+ "Unknown mocking framework: #{framework.inspect}. " +
460
+ "Pass a module or one of #{MOCKING_ADAPTERS.keys.inspect}"
461
+ end
462
+
463
+ RSpec::Support.require_rspec_core "mocking_adapters/#{const_name.to_s.downcase}"
464
+ RSpec::Core::MockingAdapters.const_get(const_name)
497
465
  end
498
466
 
499
467
  new_name, old_name = [framework_module, @mock_framework].map do |mod|
@@ -555,10 +523,6 @@ module RSpec
555
523
  require 'rspec/expectations'
556
524
  self.expecting_with_rspec = true
557
525
  ::RSpec::Matchers
558
- when :stdlib
559
- RSpec.deprecate ':stdlib', :replacement => ":test_unit or :minitest"
560
- require 'test/unit/assertions'
561
- ::Test::Unit::Assertions
562
526
  when :test_unit
563
527
  require 'rspec/core/test_unit_assertions_adapter'
564
528
  ::RSpec::Core::TestUnitAssertionsAdapter
@@ -583,40 +547,41 @@ module RSpec
583
547
  @expectation_frameworks.push(*modules)
584
548
  end
585
549
 
550
+ # Check if full backtrace is enabled
551
+ # @return [Boolean] is full backtrace enabled
586
552
  def full_backtrace?
587
553
  @backtrace_formatter.full_backtrace?
588
554
  end
589
555
 
556
+ # Toggle full backtrace
557
+ # @attr true_or_false [Boolean] toggle full backtrace display
590
558
  def full_backtrace=(true_or_false)
591
559
  @backtrace_formatter.full_backtrace = true_or_false
592
560
  end
593
561
 
594
- NoArgument = "No such argument"
595
- def color(output = NoArgument)
596
- if output == NoArgument
597
- output = output_stream
598
- if !output_to_tty?(output) && value_for(:color, @color)
599
- RSpec.warn_deprecation <<-MSG.gsub(/\s+|/,'')
600
- | Calling `RSpec::Core::Configuration#color` in RSpec 3 will
601
- | return the value of the configuration setting, in RSpec 2
602
- | this value is `false` as your output doesn't support color.
603
- | Use `RSpec::Core::Configuration#color_enabled?` if you depend
604
- | on this behavior.
605
- | Called from #{CallerFilter.first_non_rspec_line}.
606
- MSG
607
- end
608
- else
609
- RSpec.deprecate '`RSpec::Core::Configuration#color(output)`',
610
- :replacement => '`RSpec::Core::Configuration#color_enabled?(output)`'
611
- end
562
+ # Returns the configuration option for color, but should not
563
+ # be used to check if color is supported.
564
+ #
565
+ # @see color_enabled?
566
+ # @return [Boolean]
567
+ def color
568
+ value_for(:color, @color)
569
+ end
612
570
 
613
- color_enabled? output
571
+ # Check if color is enabled for a particular output
572
+ # @param output [IO] an output stream to use, defaults to the current
573
+ # `output_stream`
574
+ # @return [Boolean]
575
+ def color_enabled?(output = output_stream)
576
+ output_to_tty?(output) && color
614
577
  end
615
578
 
616
- def color=(bool)
617
- if bool
618
- if RSpec.windows_os? and not ENV['ANSICON']
619
- warn "You must use ANSICON 1.31 or later (http://adoxa.3eeweb.com/ansicon/) to use colour on Windows"
579
+ # Toggle output color
580
+ # @attr true_or_false [Boolean] toggle color enabled
581
+ def color=(true_or_false)
582
+ if true_or_false
583
+ if RSpec.world.windows_os? and not ENV['ANSICON']
584
+ RSpec.warning "You must use ANSICON 1.31 or later (http://adoxa.3eeweb.com/ansicon/) to use colour on Windows"
620
585
  @color = false
621
586
  else
622
587
  @color = true
@@ -624,32 +589,7 @@ module RSpec
624
589
  end
625
590
  end
626
591
 
627
- def color_enabled?(output=output_stream)
628
- output_to_tty?(output) && value_for(:color, @color)
629
- end
630
-
631
- def color_enabled(output=output_stream)
632
- RSpec.deprecate "`RSpec::Core::Configuration#color_enabled`",
633
- :replacement =>
634
- "`RSpec::Core::Configuration#color` if you want the configuration " +
635
- "value, or `RSpec::Core::Configuration#color_enabled?(output)` if " +
636
- " you want to know if color output is supported."
637
-
638
- color_enabled? output
639
- end
640
-
641
- def color_enabled=(bool)
642
- RSpec.deprecate "RSpec::Core::Configuration#color_enabled=",
643
- :replacement => "RSpec::Core::Configuration#color="
644
- self.color = bool
645
- end
646
-
647
- def color?(output=output_stream)
648
- RSpec.deprecate "RSpec::Core::Configuration#color?",
649
- :replacement => "RSpec::Core::Configuration#color_enabled?"
650
- color_enabled? output_stream
651
- end
652
-
592
+ # @private
653
593
  def libs=(libs)
654
594
  libs.map do |lib|
655
595
  @libs.unshift lib
@@ -657,69 +597,13 @@ module RSpec
657
597
  end
658
598
  end
659
599
 
660
- def requires=(paths)
661
- RSpec.deprecate("RSpec::Core::Configuration#requires=(paths)",
662
- :replacement => "paths.each {|path| require path}")
663
- paths.map {|path| require path}
664
- @requires += paths
665
- end
666
-
667
- def debug=(bool)
668
- if bool == :cli
669
- RSpec.deprecate("RSpec's built-in debugger support",
670
- :replacement => "a CLI option like `-rruby-debug` or `-rdebugger`",
671
- :call_site => nil)
672
- bool = true
673
- elsif bool
674
- RSpec.deprecate("RSpec::Core::Configuration#debug=",
675
- :replacement => "a CLI option like `-rruby-debug` or `-rdebugger`")
676
- else
677
- # ...but the only way to call this with a false value is to
678
- # call it directly, so here we mention the method name.
679
- # There's no replacement for it since it's a no-op, though.
680
- RSpec.deprecate("RSpec::Core::Configuration#debug=")
681
- end
682
-
683
- return unless bool
684
- begin
685
- require 'ruby-debug'
686
- Debugger.start
687
- rescue LoadError => e
688
- raise <<-EOM
689
-
690
- #{'*'*50}
691
- #{e.message}
692
-
693
- If you have it installed as a ruby gem, then you need to either require
694
- 'rubygems' or configure the RUBYOPT environment variable with the value
695
- 'rubygems'.
696
-
697
- #{e.backtrace.join("\n")}
698
- #{'*'*50}
699
- EOM
700
- end
701
- end
702
-
703
- def debug?
704
- RSpec.deprecate("RSpec::Core::Configuration#debug?",
705
- :replacement => "defined?(Debugger)")
706
-
707
- !!defined?(Debugger)
708
- end
709
-
710
- # Run examples defined on `line_numbers` in all files to run.
711
- def line_numbers=(line_numbers)
712
- filter_run :line_numbers => line_numbers.map{|l| l.to_i}
713
- end
714
-
715
- def line_numbers
716
- filter.fetch(:line_numbers,[])
717
- end
718
-
600
+ # Run examples matching on `description` in all files to run.
601
+ # @param description [String, Regexp] the pattern to filter on
719
602
  def full_description=(description)
720
603
  filter_run :full_description => Regexp.union(*Array(description).map {|d| Regexp.new(d) })
721
604
  end
722
605
 
606
+ # @return [Array] full description filter
723
607
  def full_description
724
608
  filter.fetch :full_description, nil
725
609
  end
@@ -741,20 +625,70 @@ EOM
741
625
  end
742
626
  alias_method :formatter=, :add_formatter
743
627
 
628
+ # The formatter that will be used if no formatter has been set.
629
+ # Defaults to 'progress'.
630
+ def default_formatter
631
+ formatter_loader.default_formatter
632
+ end
633
+
634
+ # Sets a fallback formatter to use if none other has been set.
635
+ #
636
+ # @example
637
+ #
638
+ # RSpec.configure do |rspec|
639
+ # rspec.default_formatter = 'doc'
640
+ # end
641
+ def default_formatter=(value)
642
+ formatter_loader.default_formatter = value
643
+ end
644
+
645
+ # Returns a duplicate of the formatters currently loaded in
646
+ # the `FormatterLoader` for introspection.
647
+ #
648
+ # Note as this is a duplicate, any mutations will be disregarded.
649
+ #
650
+ # @return [Array] the formatters currently loaded
744
651
  def formatters
745
- DeprecatedMutableArrayProxy.new(formatter_loader.formatters)
652
+ formatter_loader.formatters.dup
746
653
  end
747
654
 
748
655
  # @private
749
656
  def formatter_loader
750
- @formatter_loader ||= Formatters::Loader.new(Reporter.new)
657
+ @formatter_loader ||= Formatters::Loader.new(Reporter.new(self))
658
+ end
659
+
660
+ # @private
661
+ #
662
+ # This buffer is used to capture all messages sent to the reporter during
663
+ # reporter initialization. It can then replay those messages after the
664
+ # formatter is correctly initialized. Otherwise, deprecation warnings
665
+ # during formatter initialization can cause an infinite loop.
666
+ class DeprecationReporterBuffer
667
+ def initialize
668
+ @calls = []
669
+ end
670
+
671
+ def deprecation(*args)
672
+ @calls << args
673
+ end
674
+
675
+ def play_onto(reporter)
676
+ @calls.each do |args|
677
+ reporter.deprecation(*args)
678
+ end
679
+ end
751
680
  end
752
681
 
753
682
  # @private
754
683
  def reporter
755
- @reporter ||=
684
+ # @reporter_buffer should only ever be set in this method to cover
685
+ # initialization of @reporter.
686
+ @reporter_buffer || @reporter ||=
756
687
  begin
688
+ @reporter_buffer = DeprecationReporterBuffer.new
757
689
  formatter_loader.setup_default output_stream, deprecation_stream
690
+ @reporter_buffer.play_onto(formatter_loader.reporter)
691
+ @reporter_buffer = nil
758
692
  formatter_loader.reporter
759
693
  end
760
694
  end
@@ -776,66 +710,119 @@ EOM
776
710
  def files_or_directories_to_run=(*files)
777
711
  files = files.flatten
778
712
  files << default_path if (command == 'rspec' || Runner.running_in_drb?) && default_path && files.empty?
779
- self.files_to_run = get_files_to_run(files)
713
+ @files_or_directories_to_run = files
714
+ @files_to_run = nil
715
+ end
716
+
717
+ # The spec files RSpec will run
718
+ # @return [Array] specified files about to run
719
+ def files_to_run
720
+ @files_to_run ||= get_files_to_run(@files_or_directories_to_run)
780
721
  end
781
722
 
782
723
  # Creates a method that delegates to `example` including the submitted
783
724
  # `args`. Used internally to add variants of `example` like `pending`:
725
+ # @param name [String] example name alias
726
+ # @param args [Array<Symbol>, Hash] metadata for the generated example
727
+ #
728
+ # @note The specific example alias below (`pending`) is already
729
+ # defined for you.
730
+ # @note Use with caution. This extends the language used in your
731
+ # specs, but does not add any additional documentation. We use this
732
+ # in rspec to define methods like `focus` and `xit`, but we also add
733
+ # docs for those methods.
784
734
  #
785
735
  # @example
786
- # alias_example_to :pending, :pending => true
736
+ # RSpec.configure do |config|
737
+ # config.alias_example_to :pending, :pending => true
738
+ # end
787
739
  #
788
- # # This lets you do this:
740
+ # # This lets you do this:
789
741
  #
790
- # describe Thing do
791
- # pending "does something" do
792
- # thing = Thing.new
793
- # end
742
+ # describe Thing do
743
+ # pending "does something" do
744
+ # thing = Thing.new
794
745
  # end
746
+ # end
795
747
  #
796
- # # ... which is the equivalent of
748
+ # # ... which is the equivalent of
797
749
  #
798
- # describe Thing do
799
- # it "does something", :pending => true do
800
- # thing = Thing.new
801
- # end
750
+ # describe Thing do
751
+ # it "does something", :pending => true do
752
+ # thing = Thing.new
802
753
  # end
803
- def alias_example_to(new_name, *args)
804
- extra_options = build_metadata_hash_from(args)
805
- RSpec::Core::ExampleGroup.define_example_method(new_name, extra_options)
754
+ # end
755
+ def alias_example_to(name, *args)
756
+ extra_options = Metadata.build_hash_from(args)
757
+ RSpec::Core::ExampleGroup.define_example_method(name, extra_options)
758
+ end
759
+
760
+ # Creates a method that defines an example group with the provided
761
+ # metadata. Can be used to define example group/metadata shortcuts.
762
+ #
763
+ # @example
764
+ # RSpec.configure do |config|
765
+ # config.alias_example_group_to :describe_model, :type => :model
766
+ # end
767
+ #
768
+ # shared_context_for "model tests", :type => :model do
769
+ # # define common model test helper methods, `let` declarations, etc
770
+ # end
771
+ #
772
+ # # This lets you do this:
773
+ #
774
+ # RSpec.describe_model User do
775
+ # end
776
+ #
777
+ # # ... which is the equivalent of
778
+ #
779
+ # RSpec.describe User, :type => :model do
780
+ # end
781
+ #
782
+ # @note The defined aliased will also be added to the top level
783
+ # (e.g. `main` and from within modules) if
784
+ # `expose_dsl_globally` is set to true.
785
+ # @see #alias_example_to
786
+ # @see #expose_dsl_globally=
787
+ def alias_example_group_to(new_name, *args)
788
+ extra_options = Metadata.build_hash_from(args)
789
+ RSpec::Core::ExampleGroup.define_example_group_method(new_name, extra_options)
806
790
  end
807
791
 
808
792
  # Define an alias for it_should_behave_like that allows different
809
793
  # language (like "it_has_behavior" or "it_behaves_like") to be
810
794
  # employed when including shared examples.
811
795
  #
812
- # Example:
813
- #
814
- # alias_it_behaves_like_to(:it_has_behavior, 'has behavior:')
796
+ # @example
797
+ # RSpec.configure do |config|
798
+ # config.alias_it_behaves_like_to(:it_has_behavior, 'has behavior:')
799
+ # end
815
800
  #
816
- # allows the user to include a shared example group like:
801
+ # # allows the user to include a shared example group like:
817
802
  #
818
- # describe Entity do
819
- # it_has_behavior 'sortability' do
820
- # let(:sortable) { Entity.new }
821
- # end
803
+ # describe Entity do
804
+ # it_has_behavior 'sortability' do
805
+ # let(:sortable) { Entity.new }
822
806
  # end
807
+ # end
823
808
  #
824
- # which is reported in the output as:
809
+ # # which is reported in the output as:
810
+ # # Entity
811
+ # # has behavior: sortability
812
+ # # ...sortability examples here
825
813
  #
826
- # Entity
827
- # has behavior: sortability
828
- # # sortability examples here
814
+ # @note Use with caution. This extends the language used in your
815
+ # specs, but does not add any additional documentation. We use this
816
+ # in rspec to define `it_should_behave_like` (for backward
817
+ # compatibility), but we also add docs for that method.
829
818
  def alias_it_behaves_like_to(new_name, report_label = '')
830
819
  RSpec::Core::ExampleGroup.define_nested_shared_group_method(new_name, report_label)
831
820
  end
832
-
833
821
  alias_method :alias_it_should_behave_like_to, :alias_it_behaves_like_to
834
822
 
835
- # Adds key/value pairs to the `inclusion_filter`. If the
836
- # `treat_symbols_as_metadata_keys_with_true_values` config option is set
837
- # to true and `args` includes any symbols that are not part of a hash,
838
- # each symbol is treated as a key in the hash with the value `true`.
823
+ # Adds key/value pairs to the `inclusion_filter`. If `args`
824
+ # includes any symbols that are not part of the hash, each symbol
825
+ # is treated as a key in the hash with the value `true`.
839
826
  #
840
827
  # ### Note
841
828
  #
@@ -861,15 +848,12 @@ EOM
861
848
  # # and the metadata itself e.g.
862
849
  # config.filter_run_including :foo => lambda {|v,m| m[:foo] == 'bar'}
863
850
  #
864
- # # with treat_symbols_as_metadata_keys_with_true_values = true
865
851
  # filter_run_including :foo # same as filter_run_including :foo => true
866
852
  def filter_run_including(*args)
867
- __filter_run(__method__, *args)
853
+ filter_manager.include_with_low_priority Metadata.build_hash_from(args)
868
854
  end
869
855
 
870
- def filter_run(*args)
871
- __filter_run(__method__, *args)
872
- end
856
+ alias_method :filter_run, :filter_run_including
873
857
 
874
858
  # Clears and reassigns the `inclusion_filter`. Set to `nil` if you don't
875
859
  # want any inclusion filter at all.
@@ -879,7 +863,7 @@ EOM
879
863
  # This overrides any inclusion filters/tags set on the command line or in
880
864
  # configuration files.
881
865
  def inclusion_filter=(filter)
882
- filter_manager.include_only build_metadata_hash_from([filter])
866
+ filter_manager.include_only Metadata.build_hash_from([filter])
883
867
  end
884
868
 
885
869
  alias_method :filter=, :inclusion_filter=
@@ -892,10 +876,9 @@ EOM
892
876
 
893
877
  alias_method :filter, :inclusion_filter
894
878
 
895
- # Adds key/value pairs to the `exclusion_filter`. If the
896
- # `treat_symbols_as_metadata_keys_with_true_values` config option is set
897
- # to true and `args` excludes any symbols that are not part of a hash,
898
- # each symbol is treated as a key in the hash with the value `true`.
879
+ # Adds key/value pairs to the `exclusion_filter`. If `args`
880
+ # includes any symbols that are not part of the hash, each symbol
881
+ # is treated as a key in the hash with the value `true`.
899
882
  #
900
883
  # ### Note
901
884
  #
@@ -921,10 +904,9 @@ EOM
921
904
  # # and the metadata itself e.g.
922
905
  # config.filter_run_excluding :foo => lambda {|v,m| m[:foo] == 'bar'}
923
906
  #
924
- # # with treat_symbols_as_metadata_keys_with_true_values = true
925
907
  # filter_run_excluding :foo # same as filter_run_excluding :foo => true
926
908
  def filter_run_excluding(*args)
927
- filter_manager.exclude_with_low_priority build_metadata_hash_from(args)
909
+ filter_manager.exclude_with_low_priority Metadata.build_hash_from(args)
928
910
  end
929
911
 
930
912
  # Clears and reassigns the `exclusion_filter`. Set to `nil` if you don't
@@ -935,7 +917,7 @@ EOM
935
917
  # This overrides any exclusion filters/tags set on the command line or in
936
918
  # configuration files.
937
919
  def exclusion_filter=(filter)
938
- filter_manager.exclude_only build_metadata_hash_from([filter])
920
+ filter_manager.exclude_only Metadata.build_hash_from([filter])
939
921
  end
940
922
 
941
923
  # Returns the `exclusion_filter`. If none has been set, returns an empty
@@ -977,7 +959,7 @@ EOM
977
959
  #
978
960
  # @see #extend
979
961
  def include(mod, *filters)
980
- include_or_extend_modules << [:include, mod, build_metadata_hash_from(filters)]
962
+ include_or_extend_modules << [:include, mod, Metadata.build_hash_from(filters)]
981
963
  end
982
964
 
983
965
  # Tells RSpec to extend example groups with `mod`. Methods defined in
@@ -1010,7 +992,7 @@ EOM
1010
992
  #
1011
993
  # @see #include
1012
994
  def extend(mod, *filters)
1013
- include_or_extend_modules << [:extend, mod, build_metadata_hash_from(filters)]
995
+ include_or_extend_modules << [:extend, mod, Metadata.build_hash_from(filters)]
1014
996
  end
1015
997
 
1016
998
  # @private
@@ -1020,17 +1002,17 @@ EOM
1020
1002
  def configure_group(group)
1021
1003
  include_or_extend_modules.each do |include_or_extend, mod, filters|
1022
1004
  next unless filters.empty? || group.any_apply?(filters)
1023
- send("safe_#{include_or_extend}", mod, group)
1005
+ __send__("safe_#{include_or_extend}", mod, group)
1024
1006
  end
1025
1007
  end
1026
1008
 
1027
1009
  # @private
1028
1010
  def safe_include(mod, host)
1029
- host.send(:include,mod) unless host < mod
1011
+ host.__send__(:include, mod) unless host < mod
1030
1012
  end
1031
1013
 
1032
1014
  # @private
1033
- def setup_load_path_and_require(paths)
1015
+ def requires=(paths)
1034
1016
  directories = ['lib', default_path].select { |p| File.directory? p }
1035
1017
  RSpec::Core::RubyProject.add_to_load_path(*directories)
1036
1018
  paths.each {|path| require path}
@@ -1039,10 +1021,12 @@ EOM
1039
1021
 
1040
1022
  # @private
1041
1023
  if RUBY_VERSION.to_f >= 1.9
1024
+ # @private
1042
1025
  def safe_extend(mod, host)
1043
- host.extend(mod) unless (class << host; self; end) < mod
1026
+ host.extend(mod) unless host.singleton_class < mod
1044
1027
  end
1045
1028
  else
1029
+ # @private
1046
1030
  def safe_extend(mod, host)
1047
1031
  host.extend(mod) unless (class << host; self; end).included_modules.include?(mod)
1048
1032
  end
@@ -1050,21 +1034,22 @@ EOM
1050
1034
 
1051
1035
  # @private
1052
1036
  def configure_mock_framework
1053
- RSpec::Core::ExampleGroup.send(:include, mock_framework)
1037
+ RSpec::Core::ExampleGroup.__send__(:include, mock_framework)
1038
+ conditionally_disable_mocks_monkey_patching
1054
1039
  end
1055
1040
 
1056
1041
  # @private
1057
1042
  def configure_expectation_framework
1058
1043
  expectation_frameworks.each do |framework|
1059
- RSpec::Core::ExampleGroup.send(:include, framework)
1044
+ RSpec::Core::ExampleGroup.__send__(:include, framework)
1060
1045
  end
1046
+ conditionally_disable_expectations_monkey_patching
1061
1047
  end
1062
1048
 
1063
1049
  # @private
1064
1050
  def load_spec_files
1065
1051
  files_to_run.uniq.each {|f| load File.expand_path(f) }
1066
1052
  @spec_files_loaded = true
1067
- raise_if_rspec_1_is_loaded
1068
1053
  end
1069
1054
 
1070
1055
  # @private
@@ -1086,131 +1071,49 @@ EOM
1086
1071
  @format_docstrings_block ||= DEFAULT_FORMATTER
1087
1072
  end
1088
1073
 
1089
- # @api
1090
- #
1091
- # Sets the seed value and sets `order='rand'`
1092
- def seed=(seed)
1093
- order_and_seed_from_seed(seed)
1094
- end
1095
-
1096
- # @api
1097
- #
1098
- # Sets the order and, if order is `'rand:<seed>'`, also sets the seed.
1099
- def order=(type)
1100
- order_and_seed_from_order(type)
1101
- end
1102
-
1103
- # Determines the order in which examples are run (default: OS standard
1104
- # load order for files, declaration order for groups and examples).
1105
- def order
1106
- RSpec.warn_deprecation(
1107
- "RSpec::Core::Configuration#order is deprecated with no replacement. " +
1108
- "In RSpec 3 individal example groups can use a particular ordering, " +
1109
- "so `order` is no longer a global property of the entire suite. " +
1110
- "Called from #{CallerFilter.first_non_rspec_line}."
1111
- )
1112
-
1113
- value_for(:order, @order)
1114
- end
1115
-
1116
- def randomize?
1117
- RSpec.warn_deprecation(
1118
- "RSpec::Core::Configuration#randomize? is deprecated with no replacement. " +
1119
- "In RSpec 3 individal example groups can use a particular ordering, " +
1120
- "so `randomize?` is no longer a binary property of the entire suite. " +
1121
- "Called from #{CallerFilter.first_non_rspec_line}."
1122
- )
1123
-
1124
- value_for(:order, @order).to_s.match(/rand/)
1125
- end
1126
-
1127
- # @private
1128
- DEFAULT_ORDERING = lambda { |list| list }
1129
-
1130
1074
  # @private
1131
- RANDOM_ORDERING = lambda do |list|
1132
- Kernel.srand RSpec.configuration.seed
1133
- ordering = list.sort_by { Kernel.rand(list.size) }
1134
- Kernel.srand # reset random generation
1135
- ordering
1075
+ # @macro [attach] delegate_to_ordering_manager
1076
+ # @!method $1
1077
+ def self.delegate_to_ordering_manager(*methods)
1078
+ methods.each do |method|
1079
+ define_method method do |*args, &block|
1080
+ ordering_manager.__send__(method, *args, &block)
1081
+ end
1082
+ end
1136
1083
  end
1137
1084
 
1138
- # Sets a strategy by which to order examples.
1085
+ # @macro delegate_to_ordering_manager
1139
1086
  #
1140
- # @example
1141
- # RSpec.configure do |config|
1142
- # config.order_examples do |examples|
1143
- # examples.reverse
1144
- # end
1145
- # end
1146
- #
1147
- # @see #order_groups
1148
- # @see #order_groups_and_examples
1149
- # @see #order=
1150
- # @see #seed=
1151
- def order_examples(&block)
1152
- RSpec.deprecate("RSpec::Configuration#order_examples", :replacement => "RSpec::Configuration#register_ordering(:global)")
1153
- @example_ordering_block = block
1154
- @order = "custom" unless built_in_orderer?(block)
1155
- end
1156
-
1157
- # @private
1158
- def example_ordering_block
1159
- @example_ordering_block ||= DEFAULT_ORDERING
1160
- end
1087
+ # Sets the seed value and sets the default global ordering to random.
1088
+ delegate_to_ordering_manager :seed=
1161
1089
 
1162
- # Sets a strategy by which to order groups.
1090
+ # @macro delegate_to_ordering_manager
1091
+ # Seed for random ordering (default: generated randomly each run).
1163
1092
  #
1164
- # @example
1165
- # RSpec.configure do |config|
1166
- # config.order_groups do |groups|
1167
- # groups.reverse
1168
- # end
1169
- # end
1093
+ # When you run specs with `--order random`, RSpec generates a random seed
1094
+ # for the randomization and prints it to the `output_stream` (assuming
1095
+ # you're using RSpec's built-in formatters). If you discover an ordering
1096
+ # dependency (i.e. examples fail intermittently depending on order), set
1097
+ # this (on Configuration or on the command line with `--seed`) to run
1098
+ # using the same seed while you debug the issue.
1170
1099
  #
1171
- # @see #order_examples
1172
- # @see #order_groups_and_examples
1173
- # @see #order=
1174
- # @see #seed=
1175
- def order_groups(&block)
1176
- RSpec.deprecate("RSpec::Configuration#order_groups", :replacement => "RSpec::Configuration#register_ordering(:global)")
1177
- @group_ordering_block = block
1178
- @order = "custom" unless built_in_orderer?(block)
1179
- end
1180
-
1181
- # @private
1182
- def group_ordering_block
1183
- @group_ordering_block ||= DEFAULT_ORDERING
1184
- end
1100
+ # We recommend, actually, that you use the command line approach so you
1101
+ # don't accidentally leave the seed encoded.
1102
+ delegate_to_ordering_manager :seed
1185
1103
 
1186
- # Sets a strategy by which to order groups and examples.
1104
+ # @macro delegate_to_ordering_manager
1187
1105
  #
1188
- # @example
1189
- # RSpec.configure do |config|
1190
- # config.order_groups_and_examples do |groups_or_examples|
1191
- # groups_or_examples.reverse
1192
- # end
1193
- # end
1194
- #
1195
- # @see #order_groups
1196
- # @see #order_examples
1197
- # @see #order=
1198
- # @see #seed=
1199
- def order_groups_and_examples(&block)
1200
- order_groups(&block)
1201
- order_examples(&block)
1202
- end
1106
+ # Sets the default global order and, if order is `'rand:<seed>'`, also sets the seed.
1107
+ delegate_to_ordering_manager :order=
1203
1108
 
1204
- # In RSpec 3, this registers a named ordering strategy that can later be
1109
+ # @macro delegate_to_ordering_manager
1110
+ # Registers a named ordering strategy that can later be
1205
1111
  # used to order an example group's subgroups by adding
1206
1112
  # `:order => <name>` metadata to the example group.
1207
1113
  #
1208
- # In RSpec 2.99, only `register_ordering(:global)` is supported,
1209
- # to set the global ordering.
1210
- #
1211
1114
  # @param name [Symbol] The name of the ordering.
1212
1115
  # @yield Block that will order the given examples or example groups
1213
- # @yieldparam list [Array<RSpec::Core::Example>, Array<RSpec::Core::ExampleGropu>] The examples or groups to order
1116
+ # @yieldparam list [Array<RSpec::Core::Example>, Array<RSpec::Core::ExampleGroup>] The examples or groups to order
1214
1117
  # @yieldreturn [Array<RSpec::Core::Example>, Array<RSpec::Core::ExampleGroup>] The re-ordered examples or groups
1215
1118
  #
1216
1119
  # @example
@@ -1227,35 +1130,21 @@ EOM
1227
1130
  # @note Pass the symbol `:global` to set the ordering strategy that
1228
1131
  # will be used to order the top-level example groups and any example
1229
1132
  # groups that do not have declared `:order` metadata.
1230
- def register_ordering(name, &block)
1231
- unless name == :global
1232
- raise ArgumentError,
1233
- "Ordering name `#{name.inspect}` given, `:global` expected. " +
1234
- "RSpec 3 will support named orderings (that can be used for " +
1235
- "individual example groups) but 2.99 only supports using this " +
1236
- "to set the global order."
1237
- end
1133
+ delegate_to_ordering_manager :register_ordering
1238
1134
 
1239
- @group_ordering_block = block
1240
- @example_ordering_block = block
1241
- @order = "custom"
1242
- end
1135
+ # @private
1136
+ delegate_to_ordering_manager :seed_used?, :ordering_registry
1243
1137
 
1244
1138
  # Set Ruby warnings on or off
1245
- def warnings= value
1139
+ def warnings=(value)
1246
1140
  $VERBOSE = !!value
1247
1141
  end
1248
1142
 
1143
+ # @return [Boolean] Whether or not ruby warnings are enabled.
1249
1144
  def warnings?
1250
1145
  $VERBOSE
1251
1146
  end
1252
1147
 
1253
- def warnings
1254
- RSpec.deprecate("`RSpec::Core::Configuration#warnings`",
1255
- :replacement => "`RSpec::Core::Configuration#warnings?`")
1256
- warnings?
1257
- end
1258
-
1259
1148
  # Exposes the current running example via the named
1260
1149
  # helper method. RSpec 2.x exposed this via `example`,
1261
1150
  # but in RSpec 3.0, the example is instead exposed via
@@ -1279,7 +1168,7 @@ EOM
1279
1168
  # end
1280
1169
  # end
1281
1170
  def expose_current_running_example_as(method_name)
1282
- ExposeCurrentExample.module_eval do
1171
+ ExposeCurrentExample.module_exec do
1283
1172
  extend RSpec::SharedContext
1284
1173
  let(method_name) { |ex| ex }
1285
1174
  end
@@ -1287,6 +1176,7 @@ EOM
1287
1176
  include ExposeCurrentExample
1288
1177
  end
1289
1178
 
1179
+ # @private
1290
1180
  module ExposeCurrentExample; end
1291
1181
 
1292
1182
  # Turns deprecation warnings into errors, in order to surface
@@ -1303,17 +1193,85 @@ EOM
1303
1193
  self.deprecation_stream = Formatters::DeprecationFormatter::RaiseErrorStream.new
1304
1194
  end
1305
1195
 
1306
- private
1196
+ # Enables zero monkey patching mode for RSpec. It removes monkey
1197
+ # patching of the top-level DSL methods (`describe`,
1198
+ # `shared_examples_for`, etc) onto `main` and `Module`, instead
1199
+ # requiring you to prefix these methods with `RSpec.`. It enables
1200
+ # expect-only syntax for rspec-mocks and rspec-expectations. It
1201
+ # simply disables monkey patching on whatever pieces of rspec
1202
+ # the user is using.
1203
+ #
1204
+ # @note It configures rspec-mocks and rspec-expectations only
1205
+ # if the user is using those (either explicitly or implicitly
1206
+ # by not setting `mock_with` or `expect_with` to anything else).
1207
+ #
1208
+ # @note If the user uses this options with `mock_with :mocha`
1209
+ # (or similiar) they will still have monkey patching active
1210
+ # in their test environment from mocha.
1211
+ #
1212
+ # @example
1213
+ #
1214
+ # # It disables all monkey patching
1215
+ # RSpec.configure do |config|
1216
+ # config.disable_monkey_patching!
1217
+ # end
1218
+ #
1219
+ # # Is an equivalent to
1220
+ # RSpec.configure do |config|
1221
+ # config.expose_dsl_globally = false
1222
+ #
1223
+ # config.mock_with :rspec do |mocks|
1224
+ # mocks.syntax = :expect
1225
+ # mocks.patch_marshal_to_support_partial_doubles = false
1226
+ # end
1227
+ #
1228
+ # config.mock_with :rspec do |expectations|
1229
+ # expectations.syntax = :expect
1230
+ # end
1231
+ # end
1232
+ def disable_monkey_patching!
1233
+ self.expose_dsl_globally = false
1234
+ self.disable_monkey_patching = true
1235
+ conditionally_disable_mocks_monkey_patching
1236
+ conditionally_disable_expectations_monkey_patching
1237
+ end
1238
+
1239
+ # @private
1240
+ attr_accessor :disable_monkey_patching
1241
+
1242
+ # Defines a callback that can assign derived metadata values.
1243
+ #
1244
+ # @param filters [Array<Symbol>, Hash] metadata filters that determine which example
1245
+ # or group metadata hashes the callback will be triggered for. If none are given,
1246
+ # the callback will be run against the metadata hashes of all groups and examples.
1247
+ # @yieldparam metadata [Hash] original metadata hash from an example or group. Mutate this in
1248
+ # your block as needed.
1249
+ #
1250
+ # @example
1251
+ # RSpec.configure do |config|
1252
+ # # Tag all groups and examples in the spec/unit directory with :type => :unit
1253
+ # config.define_derived_metadata(:file_path => %r{/spec/unit/}) do |metadata|
1254
+ # metadata[:type] = :unit
1255
+ # end
1256
+ # end
1257
+ def define_derived_metadata(*filters, &block)
1258
+ @derived_metadata_blocks << [Metadata.build_hash_from(filters), block]
1259
+ end
1307
1260
 
1308
- def _randomize?
1309
- value_for(:order, @order).to_s.match(/rand/)
1261
+ # @private
1262
+ def apply_derived_metadata_to(metadata)
1263
+ @derived_metadata_blocks.each do |filter, block|
1264
+ block.call(metadata) if filter.empty? || MetadataFilter.any_apply?(filter, metadata)
1265
+ end
1310
1266
  end
1311
1267
 
1268
+ private
1269
+
1312
1270
  def get_files_to_run(paths)
1313
- paths.map do |path|
1271
+ FlatMap.flat_map(paths) do |path|
1314
1272
  path = path.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
1315
1273
  File.directory?(path) ? gather_directories(path) : extract_location(path)
1316
- end.flatten.sort
1274
+ end.sort
1317
1275
  end
1318
1276
 
1319
1277
  def gather_directories(path)
@@ -1347,88 +1305,32 @@ EOM
1347
1305
  end
1348
1306
  end
1349
1307
 
1350
- def raise_if_rspec_1_is_loaded
1351
- if defined?(Spec) && defined?(Spec::VERSION::MAJOR) && Spec::VERSION::MAJOR == 1
1352
- raise <<-MESSAGE
1353
-
1354
- #{'*'*80}
1355
- You are running rspec-2, but it seems as though rspec-1 has been loaded as
1356
- well. This is likely due to a statement like this somewhere in the specs:
1357
-
1358
- require 'spec'
1359
-
1360
- Please locate that statement, remove it, and try again.
1361
- #{'*'*80}
1362
- MESSAGE
1363
- end
1364
- end
1365
-
1366
1308
  def output_to_tty?(output=output_stream)
1367
1309
  tty? || (output.respond_to?(:tty?) && output.tty?)
1368
1310
  end
1369
1311
 
1370
- def order_and_seed_from_seed(value, force = false)
1371
- order_and_seed_from_order "rand:#{value}", force
1372
- end
1373
-
1374
- def set_order_and_seed(hash, force = false)
1375
- hash[:order], seed = order_and_seed_from_order(hash[:order], force)
1376
- hash[:seed] = seed if seed
1377
- end
1378
-
1379
- def order_and_seed_from_order(type, force = false)
1380
- order, seed = type.to_s.split(':')
1381
- @order = order
1382
- @seed = seed = seed.to_i if seed
1383
-
1384
- if order.to_s.match(/rand/)
1385
- ordering = RANDOM_ORDERING
1386
- elsif %w[ default defined ].include?(order)
1387
- if order == 'default'
1388
- RSpec.deprecate("RSpec::Core::Configuration#order = 'default'",
1389
- :replacement => "RSpec::Core::Configuration#order = 'defined'")
1390
- end
1391
-
1392
- @order, @seed = nil, nil
1393
- ordering = DEFAULT_ORDERING
1394
- end
1312
+ def conditionally_disable_mocks_monkey_patching
1313
+ return unless disable_monkey_patching && rspec_mocks_loaded?
1395
1314
 
1396
- unless @ordering_already_forced
1397
- @group_ordering_block = ordering
1398
- @example_ordering_block = ordering
1315
+ RSpec::Mocks.configuration.tap do |config|
1316
+ config.syntax = :expect
1317
+ config.patch_marshal_to_support_partial_doubles = false
1399
1318
  end
1400
- @ordering_already_forced = true if force
1401
-
1402
- return order, seed
1403
1319
  end
1404
1320
 
1405
- def built_in_orderer?(block)
1406
- [DEFAULT_ORDERING, RANDOM_ORDERING].include?(block)
1407
- end
1321
+ def conditionally_disable_expectations_monkey_patching
1322
+ return unless disable_monkey_patching && rspec_expectations_loaded?
1408
1323
 
1409
- def deprecate_unless_mock_adapter_name_is_exact(name, expected)
1410
- return if name == expected
1411
- RSpec.deprecate("`config.mock_with #{name.inspect}`", :replacement => "`config.mock_with :#{expected}`")
1324
+ RSpec::Expectations.configuration.syntax = :expect
1412
1325
  end
1413
1326
 
1414
- def __filter_run(method_name, *args)
1415
- metadata_hash = build_metadata_hash_from(args)
1416
-
1417
- if metadata_hash[:focused]
1418
- RSpec.warn_deprecation(<<-EOS.gsub(/^\s*\|/, ''))
1419
- |In RSpec 2.x, `config.#{method_name} :focused => true` filters
1420
- |examples defined using `focus` or `fit` since those example aliases
1421
- |have attached `:focus => true, :focused => true` metadata. In RSpec 3,
1422
- |the metadata for those example aliases will only have `:focus => true`,
1423
- |so if you want to continue filtering examples defined with those example
1424
- |aliases you should update to `config.#{method_name} :focus => true`.
1425
- |(Called from #{CallerFilter.first_non_rspec_line}).
1426
- EOS
1427
- end
1428
-
1429
- filter_manager.include_with_low_priority metadata_hash
1327
+ def rspec_mocks_loaded?
1328
+ defined?(RSpec::Mocks.configuration)
1430
1329
  end
1431
1330
 
1331
+ def rspec_expectations_loaded?
1332
+ defined?(RSpec::Expectations.configuration)
1333
+ end
1432
1334
  end
1433
1335
  end
1434
1336
  end