opal-rspec 0.4.0.beta3 → 0.4.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.gitmodules +15 -0
  4. data/.travis.yml +12 -0
  5. data/.yardopts +5 -0
  6. data/CHANGELOG.md +3 -1
  7. data/Gemfile +6 -7
  8. data/README.md +2 -0
  9. data/Rakefile +12 -50
  10. data/lib/opal/rspec/version.rb +1 -1
  11. data/lib/opal/rspec.rb +14 -0
  12. data/opal/opal/rspec/async.rb +146 -11
  13. data/opal/opal/rspec/fixes.rb +18 -8
  14. data/opal/opal/rspec/requires.rb +45 -0
  15. data/opal/opal/rspec.rb +1 -24
  16. data/opal-rspec.gemspec +1 -1
  17. data/spec/async_spec.rb +4 -5
  18. data/spec/matchers_spec.rb +20 -0
  19. data/spec/named_subject_spec.rb +11 -0
  20. data/spec/should_syntax_spec.rb +17 -0
  21. data/vendor_lib/rspec/autorun.rb +2 -0
  22. data/vendor_lib/rspec/core/backport_random.rb +302 -0
  23. data/vendor_lib/rspec/core/backtrace_formatter.rb +65 -0
  24. data/vendor_lib/rspec/core/command_line.rb +36 -0
  25. data/vendor_lib/rspec/core/configuration.rb +1129 -0
  26. data/vendor_lib/rspec/core/configuration_options.rb +143 -0
  27. data/vendor_lib/rspec/core/drb_command_line.rb +26 -0
  28. data/vendor_lib/rspec/core/drb_options.rb +87 -0
  29. data/vendor_lib/rspec/core/dsl.rb +26 -0
  30. data/vendor_lib/rspec/core/example.rb +312 -0
  31. data/vendor_lib/rspec/core/example_group.rb +540 -0
  32. data/vendor_lib/rspec/core/filter_manager.rb +224 -0
  33. data/vendor_lib/rspec/core/flat_map.rb +17 -0
  34. data/vendor_lib/rspec/core/formatters/base_formatter.rb +291 -0
  35. data/vendor_lib/rspec/core/formatters/base_text_formatter.rb +307 -0
  36. data/vendor_lib/rspec/core/formatters/deprecation_formatter.rb +193 -0
  37. data/vendor_lib/rspec/core/formatters/documentation_formatter.rb +67 -0
  38. data/vendor_lib/rspec/core/formatters/helpers.rb +82 -0
  39. data/vendor_lib/rspec/core/formatters/html_formatter.rb +155 -0
  40. data/vendor_lib/rspec/core/formatters/html_printer.rb +408 -0
  41. data/vendor_lib/rspec/core/formatters/json_formatter.rb +99 -0
  42. data/vendor_lib/rspec/core/formatters/progress_formatter.rb +32 -0
  43. data/vendor_lib/rspec/core/formatters/snippet_extractor.rb +101 -0
  44. data/vendor_lib/rspec/core/formatters.rb +54 -0
  45. data/vendor_lib/rspec/core/hooks.rb +535 -0
  46. data/vendor_lib/rspec/core/memoized_helpers.rb +431 -0
  47. data/vendor_lib/rspec/core/metadata.rb +313 -0
  48. data/vendor_lib/rspec/core/mocking/with_absolutely_nothing.rb +11 -0
  49. data/vendor_lib/rspec/core/mocking/with_flexmock.rb +27 -0
  50. data/vendor_lib/rspec/core/mocking/with_mocha.rb +52 -0
  51. data/vendor_lib/rspec/core/mocking/with_rr.rb +27 -0
  52. data/vendor_lib/rspec/core/mocking/with_rspec.rb +27 -0
  53. data/vendor_lib/rspec/core/option_parser.rb +234 -0
  54. data/vendor_lib/rspec/core/ordering.rb +154 -0
  55. data/vendor_lib/rspec/core/pending.rb +110 -0
  56. data/vendor_lib/rspec/core/project_initializer.rb +88 -0
  57. data/vendor_lib/rspec/core/rake_task.rb +128 -0
  58. data/vendor_lib/rspec/core/reporter.rb +132 -0
  59. data/vendor_lib/rspec/core/ruby_project.rb +44 -0
  60. data/vendor_lib/rspec/core/runner.rb +97 -0
  61. data/vendor_lib/rspec/core/shared_context.rb +53 -0
  62. data/vendor_lib/rspec/core/shared_example_group/collection.rb +27 -0
  63. data/vendor_lib/rspec/core/shared_example_group.rb +146 -0
  64. data/vendor_lib/rspec/core/version.rb +7 -0
  65. data/vendor_lib/rspec/core/warnings.rb +22 -0
  66. data/vendor_lib/rspec/core/world.rb +131 -0
  67. data/vendor_lib/rspec/core.rb +203 -0
  68. data/vendor_lib/rspec/expectations/differ.rb +154 -0
  69. data/vendor_lib/rspec/expectations/errors.rb +9 -0
  70. data/vendor_lib/rspec/expectations/expectation_target.rb +87 -0
  71. data/vendor_lib/rspec/expectations/extensions/object.rb +29 -0
  72. data/vendor_lib/rspec/expectations/extensions.rb +1 -0
  73. data/vendor_lib/rspec/expectations/fail_with.rb +79 -0
  74. data/vendor_lib/rspec/expectations/handler.rb +68 -0
  75. data/vendor_lib/rspec/expectations/syntax.rb +182 -0
  76. data/vendor_lib/rspec/expectations/version.rb +8 -0
  77. data/vendor_lib/rspec/expectations.rb +75 -0
  78. data/vendor_lib/rspec/matchers/built_in/base_matcher.rb +68 -0
  79. data/vendor_lib/rspec/matchers/built_in/be.rb +213 -0
  80. data/vendor_lib/rspec/matchers/built_in/be_instance_of.rb +15 -0
  81. data/vendor_lib/rspec/matchers/built_in/be_kind_of.rb +11 -0
  82. data/vendor_lib/rspec/matchers/built_in/be_within.rb +55 -0
  83. data/vendor_lib/rspec/matchers/built_in/change.rb +141 -0
  84. data/vendor_lib/rspec/matchers/built_in/cover.rb +21 -0
  85. data/vendor_lib/rspec/matchers/built_in/eq.rb +22 -0
  86. data/vendor_lib/rspec/matchers/built_in/eql.rb +23 -0
  87. data/vendor_lib/rspec/matchers/built_in/equal.rb +48 -0
  88. data/vendor_lib/rspec/matchers/built_in/exist.rb +26 -0
  89. data/vendor_lib/rspec/matchers/built_in/has.rb +48 -0
  90. data/vendor_lib/rspec/matchers/built_in/include.rb +61 -0
  91. data/vendor_lib/rspec/matchers/built_in/match.rb +17 -0
  92. data/vendor_lib/rspec/matchers/built_in/match_array.rb +51 -0
  93. data/vendor_lib/rspec/matchers/built_in/raise_error.rb +154 -0
  94. data/vendor_lib/rspec/matchers/built_in/respond_to.rb +74 -0
  95. data/vendor_lib/rspec/matchers/built_in/satisfy.rb +30 -0
  96. data/vendor_lib/rspec/matchers/built_in/start_and_end_with.rb +48 -0
  97. data/vendor_lib/rspec/matchers/built_in/throw_symbol.rb +94 -0
  98. data/vendor_lib/rspec/matchers/built_in/yield.rb +297 -0
  99. data/vendor_lib/rspec/matchers/built_in.rb +39 -0
  100. data/vendor_lib/rspec/matchers/compatibility.rb +14 -0
  101. data/vendor_lib/rspec/matchers/configuration.rb +113 -0
  102. data/vendor_lib/rspec/matchers/dsl.rb +23 -0
  103. data/vendor_lib/rspec/matchers/generated_descriptions.rb +35 -0
  104. data/vendor_lib/rspec/matchers/matcher.rb +301 -0
  105. data/vendor_lib/rspec/matchers/method_missing.rb +12 -0
  106. data/vendor_lib/rspec/matchers/operator_matcher.rb +99 -0
  107. data/vendor_lib/rspec/matchers/pretty.rb +70 -0
  108. data/vendor_lib/rspec/matchers/test_unit_integration.rb +11 -0
  109. data/vendor_lib/rspec/matchers.rb +633 -0
  110. data/vendor_lib/rspec/mocks/any_instance/chain.rb +92 -0
  111. data/vendor_lib/rspec/mocks/any_instance/expectation_chain.rb +47 -0
  112. data/vendor_lib/rspec/mocks/any_instance/message_chains.rb +75 -0
  113. data/vendor_lib/rspec/mocks/any_instance/recorder.rb +200 -0
  114. data/vendor_lib/rspec/mocks/any_instance/stub_chain.rb +45 -0
  115. data/vendor_lib/rspec/mocks/any_instance/stub_chain_chain.rb +23 -0
  116. data/vendor_lib/rspec/mocks/argument_list_matcher.rb +104 -0
  117. data/vendor_lib/rspec/mocks/argument_matchers.rb +264 -0
  118. data/vendor_lib/rspec/mocks/arity_calculator.rb +66 -0
  119. data/vendor_lib/rspec/mocks/configuration.rb +111 -0
  120. data/vendor_lib/rspec/mocks/error_generator.rb +203 -0
  121. data/vendor_lib/rspec/mocks/errors.rb +12 -0
  122. data/vendor_lib/rspec/mocks/example_methods.rb +201 -0
  123. data/vendor_lib/rspec/mocks/extensions/marshal.rb +17 -0
  124. data/vendor_lib/rspec/mocks/framework.rb +36 -0
  125. data/vendor_lib/rspec/mocks/instance_method_stasher.rb +112 -0
  126. data/vendor_lib/rspec/mocks/matchers/have_received.rb +99 -0
  127. data/vendor_lib/rspec/mocks/matchers/receive.rb +112 -0
  128. data/vendor_lib/rspec/mocks/matchers/receive_messages.rb +72 -0
  129. data/vendor_lib/rspec/mocks/message_expectation.rb +643 -0
  130. data/vendor_lib/rspec/mocks/method_double.rb +209 -0
  131. data/vendor_lib/rspec/mocks/method_reference.rb +95 -0
  132. data/vendor_lib/rspec/mocks/mock.rb +7 -0
  133. data/vendor_lib/rspec/mocks/mutate_const.rb +406 -0
  134. data/vendor_lib/rspec/mocks/object_reference.rb +90 -0
  135. data/vendor_lib/rspec/mocks/order_group.rb +82 -0
  136. data/vendor_lib/rspec/mocks/proxy.rb +269 -0
  137. data/vendor_lib/rspec/mocks/proxy_for_nil.rb +37 -0
  138. data/vendor_lib/rspec/mocks/space.rb +95 -0
  139. data/vendor_lib/rspec/mocks/standalone.rb +3 -0
  140. data/vendor_lib/rspec/mocks/stub_chain.rb +51 -0
  141. data/vendor_lib/rspec/mocks/syntax.rb +374 -0
  142. data/vendor_lib/rspec/mocks/targets.rb +90 -0
  143. data/vendor_lib/rspec/mocks/test_double.rb +109 -0
  144. data/vendor_lib/rspec/mocks/verifying_double.rb +77 -0
  145. data/vendor_lib/rspec/mocks/verifying_message_expecation.rb +60 -0
  146. data/vendor_lib/rspec/mocks/verifying_proxy.rb +151 -0
  147. data/vendor_lib/rspec/mocks/version.rb +7 -0
  148. data/vendor_lib/rspec/mocks.rb +100 -0
  149. data/vendor_lib/rspec/support/caller_filter.rb +56 -0
  150. data/vendor_lib/rspec/support/spec/deprecation_helpers.rb +29 -0
  151. data/vendor_lib/rspec/support/spec/in_sub_process.rb +40 -0
  152. data/vendor_lib/rspec/support/spec/stderr_splitter.rb +50 -0
  153. data/vendor_lib/rspec/support/spec.rb +14 -0
  154. data/vendor_lib/rspec/support/version.rb +7 -0
  155. data/vendor_lib/rspec/support/warnings.rb +41 -0
  156. data/vendor_lib/rspec/support.rb +6 -0
  157. data/vendor_lib/rspec/version.rb +5 -0
  158. data/vendor_lib/rspec-expectations.rb +1 -0
  159. data/vendor_lib/rspec.rb +3 -0
  160. metadata +163 -4
  161. data/opal/opal/rspec/rspec.js +0 -20384
@@ -0,0 +1,1129 @@
1
+ require 'fileutils'
2
+ require 'rspec/core/backtrace_formatter'
3
+ require 'rspec/core/ruby_project'
4
+ require 'rspec/core/formatters/deprecation_formatter'
5
+
6
+ module RSpec
7
+ module Core
8
+ # Stores runtime configuration information.
9
+ #
10
+ # Configuration options are loaded from `~/.rspec`, `.rspec`,
11
+ # `.rspec-local`, command line switches, and the `SPEC_OPTS` environment
12
+ # variable (listed in lowest to highest precedence; for example, an option
13
+ # in `~/.rspec` can be overridden by an option in `.rspec-local`).
14
+ #
15
+ # @example Standard settings
16
+ # RSpec.configure do |c|
17
+ # c.drb = true
18
+ # c.drb_port = 1234
19
+ # c.default_path = 'behavior'
20
+ # end
21
+ #
22
+ # @example Hooks
23
+ # RSpec.configure do |c|
24
+ # c.before(:suite) { establish_connection }
25
+ # c.before(:each) { log_in_as :authorized }
26
+ # c.around(:each) { |ex| Database.transaction(&ex) }
27
+ # end
28
+ #
29
+ # @see RSpec.configure
30
+ # @see Hooks
31
+ class Configuration
32
+ include RSpec::Core::Hooks
33
+
34
+ class MustBeConfiguredBeforeExampleGroupsError < StandardError; end
35
+
36
+ # @private
37
+ def self.define_reader(name)
38
+ define_method(name) do
39
+ variable = instance_variable_defined?("@#{name}") ? instance_variable_get("@#{name}") : nil
40
+ value_for(name, variable)
41
+ end
42
+ end
43
+
44
+ # @private
45
+ def self.deprecate_alias_key
46
+ RSpec.deprecate("add_setting with :alias option", :replacement => ":alias_with")
47
+ end
48
+
49
+ # @private
50
+ def self.define_aliases(name, alias_name)
51
+ alias_method alias_name, name
52
+ alias_method "#{alias_name}=", "#{name}="
53
+ define_predicate_for alias_name
54
+ end
55
+
56
+ # @private
57
+ def self.define_predicate_for(*names)
58
+ names.each {|name| alias_method "#{name}?", name}
59
+ end
60
+
61
+ # @private
62
+ #
63
+ # Invoked by the `add_setting` instance method. Use that method on a
64
+ # `Configuration` instance rather than this class method.
65
+ def self.add_setting(name, opts={})
66
+ raise "Use the instance add_setting method if you want to set a default" if opts.has_key?(:default)
67
+ if opts[:alias]
68
+ deprecate_alias_key
69
+ define_aliases(opts[:alias], name)
70
+ else
71
+ attr_writer name
72
+ define_reader name
73
+ define_predicate_for name
74
+ end
75
+ Array(opts[:alias_with]).each do |alias_name|
76
+ define_aliases(name, alias_name)
77
+ end
78
+ end
79
+
80
+ # @macro [attach] add_setting
81
+ # @attribute $1
82
+ #
83
+ # @macro [attach] define_reader
84
+ # @attribute $1
85
+
86
+ # @macro add_setting
87
+ # Path to use if no path is provided to the `rspec` command (default:
88
+ # `"spec"`). Allows you to just type `rspec` instead of `rspec spec` to
89
+ # run all the examples in the `spec` directory.
90
+ add_setting :default_path
91
+
92
+ # @macro add_setting
93
+ # Run examples over DRb (default: `false`). RSpec doesn't supply the DRb
94
+ # server, but you can use tools like spork.
95
+ add_setting :drb
96
+
97
+ # @macro add_setting
98
+ # The drb_port (default: nil).
99
+ add_setting :drb_port
100
+
101
+ # @macro add_setting
102
+ # Default: `$stderr`.
103
+ add_setting :error_stream
104
+
105
+ # @macro add_setting
106
+ # Default: `$stderr`.
107
+ add_setting :deprecation_stream
108
+
109
+ # @macro add_setting
110
+ # Clean up and exit after the first failure (default: `false`).
111
+ add_setting :fail_fast
112
+
113
+ # @macro add_setting
114
+ # Prints the formatter output of your suite without running any
115
+ # examples or hooks.
116
+ add_setting :dry_run
117
+
118
+ # @macro add_setting
119
+ # The exit code to return if there are any failures (default: 1).
120
+ add_setting :failure_exit_code
121
+
122
+ # @macro define_reader
123
+ # Indicates files configured to be required
124
+ define_reader :requires
125
+
126
+ # @macro define_reader
127
+ # Returns dirs that have been prepended to the load path by #lib=
128
+ define_reader :libs
129
+
130
+ # @macro add_setting
131
+ # Default: `$stdout`.
132
+ # Also known as `output` and `out`
133
+ define_reader :output_stream
134
+ def output_stream=(value)
135
+ if @reporter && !value.equal?(@output_stream)
136
+ warn "RSpec's reporter has already been initialized with " +
137
+ "#{output_stream.inspect} as the output stream, so your change to "+
138
+ "`output_stream` will be ignored. You should configure it earlier for " +
139
+ "it to take effect. (Called from #{CallerFilter.first_non_rspec_line})"
140
+ else
141
+ @output_stream = value
142
+ end
143
+ end
144
+
145
+ # @macro add_setting
146
+ # Load files matching this pattern (default: `'**/*_spec.rb'`)
147
+ add_setting :pattern, :alias_with => :filename_pattern
148
+
149
+ def pattern= value
150
+ if @spec_files_loaded
151
+ RSpec.warning "Configuring `pattern` to #{value} has no effect since RSpec has already loaded the spec files."
152
+ end
153
+ @pattern = value
154
+ end
155
+ alias :filename_pattern= :pattern=
156
+
157
+ # @macro add_setting
158
+ # Report the times for the slowest examples (default: `false`).
159
+ # Use this to specify the number of examples to include in the profile.
160
+ add_setting :profile_examples
161
+
162
+ # @macro add_setting
163
+ # Run all examples if none match the configured filters (default: `false`).
164
+ add_setting :run_all_when_everything_filtered
165
+
166
+ # @macro add_setting
167
+ # Color to use to indicate success.
168
+ # @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
169
+ add_setting :success_color
170
+
171
+ # @macro add_setting
172
+ # Color to use to print pending examples.
173
+ # @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
174
+ add_setting :pending_color
175
+
176
+ # @macro add_setting
177
+ # Color to use to indicate failure.
178
+ # @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
179
+ add_setting :failure_color
180
+
181
+ # @macro add_setting
182
+ # The default output color.
183
+ # @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
184
+ add_setting :default_color
185
+
186
+ # @macro add_setting
187
+ # Color used when a pending example is fixed.
188
+ # @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
189
+ add_setting :fixed_color
190
+
191
+ # @macro add_setting
192
+ # Color used to print details.
193
+ # @param [Symbol] color one of the following: [:black, :white, :red, :green, :yellow, :blue, :magenta, :cyan]
194
+ add_setting :detail_color
195
+
196
+ # @macro add_setting
197
+ # When a block passed to pending fails (as expected), display the failure
198
+ # without reporting it as a failure (default: false).
199
+ add_setting :show_failures_in_pending_blocks
200
+
201
+ # Deprecated. This config option was added in RSpec 2 to pave the way
202
+ # for this being the default behavior in RSpec 3. Now this option is
203
+ # a no-op.
204
+ def treat_symbols_as_metadata_keys_with_true_values=(value)
205
+ RSpec.deprecate("RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values=")
206
+ end
207
+
208
+ # @private
209
+ add_setting :tty
210
+ # @private
211
+ add_setting :include_or_extend_modules
212
+ # @private
213
+ add_setting :files_to_run
214
+ # @private
215
+ add_setting :expecting_with_rspec
216
+ # @private
217
+ attr_accessor :filter_manager
218
+ # @private
219
+ attr_reader :backtrace_formatter, :ordering_manager
220
+
221
+ # Alias for rspec-2.x's backtrace_cleaner (now backtrace_formatter)
222
+ #
223
+ # TODO: consider deprecating and removing this rather than aliasing in rspec-3?
224
+ alias backtrace_cleaner backtrace_formatter
225
+
226
+ def initialize
227
+ @expectation_frameworks = []
228
+ @include_or_extend_modules = []
229
+ @mock_framework = nil
230
+ @files_to_run = []
231
+ @formatters = []
232
+ @color = false
233
+ @pattern = '**/*_spec.rb'
234
+ @failure_exit_code = 1
235
+ @spec_files_loaded = false
236
+
237
+ @backtrace_formatter = BacktraceFormatter.new
238
+
239
+ @default_path = 'spec'
240
+ @deprecation_stream = $stderr
241
+ @output_stream = $stdout
242
+ @reporter = nil
243
+ @filter_manager = FilterManager.new
244
+ @ordering_manager = Ordering::ConfigurationManager.new
245
+ @preferred_options = {}
246
+ @failure_color = :red
247
+ @success_color = :green
248
+ @pending_color = :yellow
249
+ @default_color = :white
250
+ @fixed_color = :blue
251
+ @detail_color = :cyan
252
+ @profile_examples = false
253
+ @requires = []
254
+ @libs = []
255
+ end
256
+
257
+ # @private
258
+ #
259
+ # Used to set higher priority option values from the command line.
260
+ def force(hash)
261
+ ordering_manager.force(hash)
262
+ @preferred_options.merge!(hash)
263
+ self.warnings = value_for :warnings, nil
264
+ end
265
+
266
+ # @private
267
+ def reset
268
+ @spec_files_loaded = false
269
+ @reporter = nil
270
+ @formatters.clear
271
+ end
272
+
273
+ # @overload add_setting(name)
274
+ # @overload add_setting(name, opts)
275
+ # @option opts [Symbol] :default
276
+ #
277
+ # set a default value for the generated getter and predicate methods:
278
+ #
279
+ # add_setting(:foo, :default => "default value")
280
+ #
281
+ # @option opts [Symbol] :alias_with
282
+ #
283
+ # Use `:alias_with` to alias the setter, getter, and predicate to another
284
+ # name, or names:
285
+ #
286
+ # add_setting(:foo, :alias_with => :bar)
287
+ # add_setting(:foo, :alias_with => [:bar, :baz])
288
+ #
289
+ # Adds a custom setting to the RSpec.configuration object.
290
+ #
291
+ # RSpec.configuration.add_setting :foo
292
+ #
293
+ # Used internally and by extension frameworks like rspec-rails, so they
294
+ # can add config settings that are domain specific. For example:
295
+ #
296
+ # RSpec.configure do |c|
297
+ # c.add_setting :use_transactional_fixtures,
298
+ # :default => true,
299
+ # :alias_with => :use_transactional_examples
300
+ # end
301
+ #
302
+ # `add_setting` creates three methods on the configuration object, a
303
+ # setter, a getter, and a predicate:
304
+ #
305
+ # RSpec.configuration.foo=(value)
306
+ # RSpec.configuration.foo
307
+ # RSpec.configuration.foo? # returns true if foo returns anything but nil or false
308
+ def add_setting(name, opts={})
309
+ default = opts.delete(:default)
310
+ (class << self; self; end).class_eval do
311
+ add_setting(name, opts)
312
+ end
313
+ send("#{name}=", default) if default
314
+ end
315
+
316
+ # Returns the configured mock framework adapter module
317
+ def mock_framework
318
+ mock_with :rspec unless @mock_framework
319
+ @mock_framework
320
+ end
321
+
322
+ # Delegates to mock_framework=(framework)
323
+ def mock_framework=(framework)
324
+ mock_with framework
325
+ end
326
+
327
+ # Regexps used to exclude lines from backtraces.
328
+ #
329
+ # Excludes lines from ruby (and jruby) source, installed gems, anything
330
+ # in any "bin" directory, and any of the rspec libs (outside gem
331
+ # installs) by default.
332
+ #
333
+ # You can modify the list via the getter, or replace it with the setter.
334
+ #
335
+ # To override this behaviour and display a full backtrace, use
336
+ # `--backtrace`on the command line, in a `.rspec` file, or in the
337
+ # `rspec_options` attribute of RSpec's rake task.
338
+ def backtrace_exclusion_patterns
339
+ @backtrace_formatter.exclusion_patterns
340
+ end
341
+
342
+ def backtrace_exclusion_patterns=(patterns)
343
+ @backtrace_formatter.exclusion_patterns = patterns
344
+ end
345
+
346
+ # Regexps used to include lines in backtraces.
347
+ #
348
+ # Defaults to [Regexp.new Dir.getwd].
349
+ #
350
+ # Lines that match an exclusion _and_ an inclusion pattern
351
+ # will be included.
352
+ #
353
+ # You can modify the list via the getter, or replace it with the setter.
354
+ def backtrace_inclusion_patterns
355
+ @backtrace_formatter.inclusion_patterns
356
+ end
357
+
358
+ def backtrace_inclusion_patterns=(patterns)
359
+ @backtrace_formatter.inclusion_patterns = patterns
360
+ end
361
+
362
+ # Sets the mock framework adapter module.
363
+ #
364
+ # `framework` can be a Symbol or a Module.
365
+ #
366
+ # Given any of `:rspec`, `:mocha`, `:flexmock`, or `:rr`, configures the
367
+ # named framework.
368
+ #
369
+ # Given `:nothing`, configures no framework. Use this if you don't use
370
+ # any mocking framework to save a little bit of overhead.
371
+ #
372
+ # Given a Module, includes that module in every example group. The module
373
+ # should adhere to RSpec's mock framework adapter API:
374
+ #
375
+ # setup_mocks_for_rspec
376
+ # - called before each example
377
+ #
378
+ # verify_mocks_for_rspec
379
+ # - called after each example. Framework should raise an exception
380
+ # when expectations fail
381
+ #
382
+ # teardown_mocks_for_rspec
383
+ # - called after verify_mocks_for_rspec (even if there are errors)
384
+ #
385
+ # If the module responds to `configuration` and `mock_with` receives a block,
386
+ # it will yield the configuration object to the block e.g.
387
+ #
388
+ # config.mock_with OtherMockFrameworkAdapter do |mod_config|
389
+ # mod_config.custom_setting = true
390
+ # end
391
+ def mock_with(framework)
392
+ framework_module = case framework
393
+ when Module
394
+ framework
395
+ when String, Symbol
396
+ require case framework.to_s
397
+ when /rspec/i
398
+ 'rspec/core/mocking/with_rspec'
399
+ when /mocha/i
400
+ 'rspec/core/mocking/with_mocha'
401
+ when /rr/i
402
+ 'rspec/core/mocking/with_rr'
403
+ when /flexmock/i
404
+ 'rspec/core/mocking/with_flexmock'
405
+ else
406
+ 'rspec/core/mocking/with_absolutely_nothing'
407
+ end
408
+ RSpec::Core::MockFrameworkAdapter
409
+ end
410
+
411
+ new_name, old_name = [framework_module, @mock_framework].map do |mod|
412
+ mod.respond_to?(:framework_name) ? mod.framework_name : :unnamed
413
+ end
414
+
415
+ unless new_name == old_name
416
+ assert_no_example_groups_defined(:mock_framework)
417
+ end
418
+
419
+ if block_given?
420
+ raise "#{framework_module} must respond to `configuration` so that mock_with can yield it." unless framework_module.respond_to?(:configuration)
421
+ yield framework_module.configuration
422
+ end
423
+
424
+ @mock_framework = framework_module
425
+ end
426
+
427
+ # Returns the configured expectation framework adapter module(s)
428
+ def expectation_frameworks
429
+ expect_with :rspec if @expectation_frameworks.empty?
430
+ @expectation_frameworks
431
+ end
432
+
433
+ # Delegates to expect_with(framework)
434
+ def expectation_framework=(framework)
435
+ expect_with(framework)
436
+ end
437
+
438
+ # Sets the expectation framework module(s) to be included in each example
439
+ # group.
440
+ #
441
+ # `frameworks` can be `:rspec`, `:stdlib`, a custom module, or any
442
+ # combination thereof:
443
+ #
444
+ # config.expect_with :rspec
445
+ # config.expect_with :stdlib
446
+ # config.expect_with :rspec, :stdlib
447
+ # config.expect_with OtherExpectationFramework
448
+ #
449
+ # RSpec will translate `:rspec` and `:stdlib` into the appropriate
450
+ # modules.
451
+ #
452
+ # ## Configuration
453
+ #
454
+ # If the module responds to `configuration`, `expect_with` will
455
+ # yield the `configuration` object if given a block:
456
+ #
457
+ # config.expect_with OtherExpectationFramework do |custom_config|
458
+ # custom_config.custom_setting = true
459
+ # end
460
+ def expect_with(*frameworks)
461
+ modules = frameworks.map do |framework|
462
+ case framework
463
+ when Module
464
+ framework
465
+ when :rspec
466
+ require 'rspec/expectations'
467
+ self.expecting_with_rspec = true
468
+ ::RSpec::Matchers
469
+ when :stdlib
470
+ require 'test/unit/assertions'
471
+ ::Test::Unit::Assertions
472
+ else
473
+ raise ArgumentError, "#{framework.inspect} is not supported"
474
+ end
475
+ end
476
+
477
+ if (modules - @expectation_frameworks).any?
478
+ assert_no_example_groups_defined(:expect_with)
479
+ end
480
+
481
+ if block_given?
482
+ raise "expect_with only accepts a block with a single argument. Call expect_with #{modules.length} times, once with each argument, instead." if modules.length > 1
483
+ raise "#{modules.first} must respond to `configuration` so that expect_with can yield it." unless modules.first.respond_to?(:configuration)
484
+ yield modules.first.configuration
485
+ end
486
+
487
+ @expectation_frameworks.push(*modules)
488
+ end
489
+
490
+ def full_backtrace?
491
+ @backtrace_formatter.full_backtrace?
492
+ end
493
+
494
+ def full_backtrace=(true_or_false)
495
+ @backtrace_formatter.full_backtrace = true_or_false
496
+ end
497
+
498
+ def color(output=output_stream)
499
+ # rspec's built-in formatters all call this with the output argument,
500
+ # but defaulting to output_stream for backward compatibility with
501
+ # formatters in extension libs
502
+ return false unless output_to_tty?(output)
503
+ value_for(:color, @color)
504
+ end
505
+
506
+ def color=(bool)
507
+ if bool
508
+ if RSpec.windows_os? and not ENV['ANSICON']
509
+ RSpec.warning "You must use ANSICON 1.31 or later (http://adoxa.3eeweb.com/ansicon/) to use colour on Windows"
510
+ @color = false
511
+ else
512
+ @color = true
513
+ end
514
+ end
515
+ end
516
+
517
+ # TODO - deprecate color_enabled - probably not until the last 2.x
518
+ # release before 3.0
519
+ alias_method :color_enabled, :color
520
+ alias_method :color_enabled=, :color=
521
+ define_predicate_for :color_enabled, :color
522
+
523
+ def libs=(libs)
524
+ libs.map do |lib|
525
+ @libs.unshift lib
526
+ $LOAD_PATH.unshift lib
527
+ end
528
+ end
529
+
530
+ def requires=(paths)
531
+ RSpec.deprecate("RSpec::Core::Configuration#requires=(paths)",
532
+ :replacement => "paths.each {|path| require path}")
533
+ paths.map {|path| require path}
534
+ @requires += paths
535
+ end
536
+
537
+ # Run examples defined on `line_numbers` in all files to run.
538
+ def line_numbers=(line_numbers)
539
+ filter_run :line_numbers => line_numbers.map{|l| l.to_i}
540
+ end
541
+
542
+ def line_numbers
543
+ filter.fetch(:line_numbers,[])
544
+ end
545
+
546
+ def full_description=(description)
547
+ filter_run :full_description => Regexp.union(*Array(description).map {|d| Regexp.new(d) })
548
+ end
549
+
550
+ def full_description
551
+ filter.fetch :full_description, nil
552
+ end
553
+
554
+ # @overload add_formatter(formatter)
555
+ #
556
+ # Adds a formatter to the formatters collection. `formatter` can be a
557
+ # string representing any of the built-in formatters (see
558
+ # `built_in_formatter`), or a custom formatter class.
559
+ #
560
+ # ### Note
561
+ #
562
+ # For internal purposes, `add_formatter` also accepts the name of a class
563
+ # and paths to use for output streams, but you should consider that a
564
+ # private api that may change at any time without notice.
565
+ def add_formatter(formatter_to_use, *paths)
566
+ formatter_class =
567
+ built_in_formatter(formatter_to_use) ||
568
+ custom_formatter(formatter_to_use) ||
569
+ (raise ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?.")
570
+
571
+ paths << output_stream if paths.empty?
572
+ formatters << formatter_class.new(*paths.map {|p| String === p ? file_at(p) : p})
573
+ end
574
+
575
+ alias_method :formatter=, :add_formatter
576
+
577
+ def formatters
578
+ @formatters ||= []
579
+ end
580
+
581
+ def reporter
582
+ @reporter ||= begin
583
+ add_formatter('progress') if formatters.empty?
584
+ add_formatter(RSpec::Core::Formatters::DeprecationFormatter, deprecation_stream, output_stream)
585
+ Reporter.new(self, *formatters)
586
+ end
587
+ end
588
+
589
+ # @api private
590
+ #
591
+ # Defaults `profile_examples` to 10 examples when `@profile_examples` is `true`.
592
+ #
593
+ def profile_examples
594
+ profile = value_for(:profile_examples, @profile_examples)
595
+ if profile && !profile.is_a?(Integer)
596
+ 10
597
+ else
598
+ profile
599
+ end
600
+ end
601
+
602
+ # @private
603
+ def files_or_directories_to_run=(*files)
604
+ files = files.flatten
605
+ files << default_path if (command == 'rspec' || Runner.running_in_drb?) && default_path && files.empty?
606
+ self.files_to_run = get_files_to_run(files)
607
+ end
608
+
609
+ # Creates a method that delegates to `example` including the submitted
610
+ # `args`. Used internally to add variants of `example` like `pending`:
611
+ #
612
+ # @example
613
+ # alias_example_to :pending, :pending => true
614
+ #
615
+ # # This lets you do this:
616
+ #
617
+ # describe Thing do
618
+ # pending "does something" do
619
+ # thing = Thing.new
620
+ # end
621
+ # end
622
+ #
623
+ # # ... which is the equivalent of
624
+ #
625
+ # describe Thing do
626
+ # it "does something", :pending => true do
627
+ # thing = Thing.new
628
+ # end
629
+ # end
630
+ def alias_example_to(new_name, *args)
631
+ extra_options = Metadata.build_hash_from(args)
632
+ RSpec::Core::ExampleGroup.alias_example_to(new_name, extra_options)
633
+ end
634
+
635
+ # Define an alias for it_should_behave_like that allows different
636
+ # language (like "it_has_behavior" or "it_behaves_like") to be
637
+ # employed when including shared examples.
638
+ #
639
+ # Example:
640
+ #
641
+ # alias_it_behaves_like_to(:it_has_behavior, 'has behavior:')
642
+ #
643
+ # allows the user to include a shared example group like:
644
+ #
645
+ # describe Entity do
646
+ # it_has_behavior 'sortability' do
647
+ # let(:sortable) { Entity.new }
648
+ # end
649
+ # end
650
+ #
651
+ # which is reported in the output as:
652
+ #
653
+ # Entity
654
+ # has behavior: sortability
655
+ # # sortability examples here
656
+ def alias_it_behaves_like_to(new_name, report_label = '')
657
+ RSpec::Core::ExampleGroup.alias_it_behaves_like_to(new_name, report_label)
658
+ end
659
+
660
+ alias_method :alias_it_should_behave_like_to, :alias_it_behaves_like_to
661
+
662
+ # Adds key/value pairs to the `inclusion_filter`. If `args`
663
+ # includes any symbols that are not part of the hash, each symbol
664
+ # is treated as a key in the hash with the value `true`.
665
+ #
666
+ # ### Note
667
+ #
668
+ # Filters set using this method can be overridden from the command line
669
+ # or config files (e.g. `.rspec`).
670
+ #
671
+ # @example
672
+ # # given this declaration
673
+ # describe "something", :foo => 'bar' do
674
+ # # ...
675
+ # end
676
+ #
677
+ # # any of the following will include that group
678
+ # config.filter_run_including :foo => 'bar'
679
+ # config.filter_run_including :foo => /^ba/
680
+ # config.filter_run_including :foo => lambda {|v| v == 'bar'}
681
+ # config.filter_run_including :foo => lambda {|v,m| m[:foo] == 'bar'}
682
+ #
683
+ # # given a proc with an arity of 1, the lambda is passed the value related to the key, e.g.
684
+ # config.filter_run_including :foo => lambda {|v| v == 'bar'}
685
+ #
686
+ # # given a proc with an arity of 2, the lambda is passed the value related to the key,
687
+ # # and the metadata itself e.g.
688
+ # config.filter_run_including :foo => lambda {|v,m| m[:foo] == 'bar'}
689
+ #
690
+ # filter_run_including :foo # same as filter_run_including :foo => true
691
+ def filter_run_including(*args)
692
+ filter_manager.include_with_low_priority Metadata.build_hash_from(args)
693
+ end
694
+
695
+ alias_method :filter_run, :filter_run_including
696
+
697
+ # Clears and reassigns the `inclusion_filter`. Set to `nil` if you don't
698
+ # want any inclusion filter at all.
699
+ #
700
+ # ### Warning
701
+ #
702
+ # This overrides any inclusion filters/tags set on the command line or in
703
+ # configuration files.
704
+ def inclusion_filter=(filter)
705
+ filter_manager.include! Metadata.build_hash_from([filter])
706
+ end
707
+
708
+ alias_method :filter=, :inclusion_filter=
709
+
710
+ # Returns the `inclusion_filter`. If none has been set, returns an empty
711
+ # hash.
712
+ def inclusion_filter
713
+ filter_manager.inclusions
714
+ end
715
+
716
+ alias_method :filter, :inclusion_filter
717
+
718
+ # Adds key/value pairs to the `exclusion_filter`. If `args`
719
+ # includes any symbols that are not part of the hash, each symbol
720
+ # is treated as a key in the hash with the value `true`.
721
+ #
722
+ # ### Note
723
+ #
724
+ # Filters set using this method can be overridden from the command line
725
+ # or config files (e.g. `.rspec`).
726
+ #
727
+ # @example
728
+ # # given this declaration
729
+ # describe "something", :foo => 'bar' do
730
+ # # ...
731
+ # end
732
+ #
733
+ # # any of the following will exclude that group
734
+ # config.filter_run_excluding :foo => 'bar'
735
+ # config.filter_run_excluding :foo => /^ba/
736
+ # config.filter_run_excluding :foo => lambda {|v| v == 'bar'}
737
+ # config.filter_run_excluding :foo => lambda {|v,m| m[:foo] == 'bar'}
738
+ #
739
+ # # given a proc with an arity of 1, the lambda is passed the value related to the key, e.g.
740
+ # config.filter_run_excluding :foo => lambda {|v| v == 'bar'}
741
+ #
742
+ # # given a proc with an arity of 2, the lambda is passed the value related to the key,
743
+ # # and the metadata itself e.g.
744
+ # config.filter_run_excluding :foo => lambda {|v,m| m[:foo] == 'bar'}
745
+ #
746
+ # filter_run_excluding :foo # same as filter_run_excluding :foo => true
747
+ def filter_run_excluding(*args)
748
+ filter_manager.exclude_with_low_priority Metadata.build_hash_from(args)
749
+ end
750
+
751
+ # Clears and reassigns the `exclusion_filter`. Set to `nil` if you don't
752
+ # want any exclusion filter at all.
753
+ #
754
+ # ### Warning
755
+ #
756
+ # This overrides any exclusion filters/tags set on the command line or in
757
+ # configuration files.
758
+ def exclusion_filter=(filter)
759
+ filter_manager.exclude! Metadata.build_hash_from([filter])
760
+ end
761
+
762
+ # Returns the `exclusion_filter`. If none has been set, returns an empty
763
+ # hash.
764
+ def exclusion_filter
765
+ filter_manager.exclusions
766
+ end
767
+
768
+ # Tells RSpec to include `mod` in example groups. Methods defined in
769
+ # `mod` are exposed to examples (not example groups). Use `filters` to
770
+ # constrain the groups in which to include the module.
771
+ #
772
+ # @example
773
+ #
774
+ # module AuthenticationHelpers
775
+ # def login_as(user)
776
+ # # ...
777
+ # end
778
+ # end
779
+ #
780
+ # module UserHelpers
781
+ # def users(username)
782
+ # # ...
783
+ # end
784
+ # end
785
+ #
786
+ # RSpec.configure do |config|
787
+ # config.include(UserHelpers) # included in all modules
788
+ # config.include(AuthenticationHelpers, :type => :request)
789
+ # end
790
+ #
791
+ # describe "edit profile", :type => :request do
792
+ # it "can be viewed by owning user" do
793
+ # login_as users(:jdoe)
794
+ # get "/profiles/jdoe"
795
+ # assert_select ".username", :text => 'jdoe'
796
+ # end
797
+ # end
798
+ #
799
+ # @see #extend
800
+ def include(mod, *filters)
801
+ include_or_extend_modules << [:include, mod, Metadata.build_hash_from(filters)]
802
+ end
803
+
804
+ # Tells RSpec to extend example groups with `mod`. Methods defined in
805
+ # `mod` are exposed to example groups (not examples). Use `filters` to
806
+ # constrain the groups to extend.
807
+ #
808
+ # Similar to `include`, but behavior is added to example groups, which
809
+ # are classes, rather than the examples, which are instances of those
810
+ # classes.
811
+ #
812
+ # @example
813
+ #
814
+ # module UiHelpers
815
+ # def run_in_browser
816
+ # # ...
817
+ # end
818
+ # end
819
+ #
820
+ # RSpec.configure do |config|
821
+ # config.extend(UiHelpers, :type => :request)
822
+ # end
823
+ #
824
+ # describe "edit profile", :type => :request do
825
+ # run_in_browser
826
+ #
827
+ # it "does stuff in the client" do
828
+ # # ...
829
+ # end
830
+ # end
831
+ #
832
+ # @see #include
833
+ def extend(mod, *filters)
834
+ include_or_extend_modules << [:extend, mod, Metadata.build_hash_from(filters)]
835
+ end
836
+
837
+ # @private
838
+ #
839
+ # Used internally to extend a group with modules using `include` and/or
840
+ # `extend`.
841
+ def configure_group(group)
842
+ include_or_extend_modules.each do |include_or_extend, mod, filters|
843
+ next unless filters.empty? || group.any_apply?(filters)
844
+ send("safe_#{include_or_extend}", mod, group)
845
+ end
846
+ end
847
+
848
+ # @private
849
+ def safe_include(mod, host)
850
+ host.send(:include,mod) unless host < mod
851
+ end
852
+
853
+ # @private
854
+ def setup_load_path_and_require(paths)
855
+ directories = ['lib', default_path].select { |p| File.directory? p }
856
+ RSpec::Core::RubyProject.add_to_load_path(*directories)
857
+ paths.each {|path| require path}
858
+ @requires += paths
859
+ end
860
+
861
+ # @private
862
+ if RUBY_VERSION.to_f >= 1.9
863
+ def safe_extend(mod, host)
864
+ host.extend(mod) unless (class << host; self; end) < mod
865
+ end
866
+ else
867
+ def safe_extend(mod, host)
868
+ host.extend(mod) unless (class << host; self; end).included_modules.include?(mod)
869
+ end
870
+ end
871
+
872
+ # @private
873
+ def configure_mock_framework
874
+ RSpec::Core::ExampleGroup.send(:include, mock_framework)
875
+ end
876
+
877
+ # @private
878
+ def configure_expectation_framework
879
+ expectation_frameworks.each do |framework|
880
+ RSpec::Core::ExampleGroup.send(:include, framework)
881
+ end
882
+ end
883
+
884
+ # @private
885
+ def load_spec_files
886
+ files_to_run.uniq.each {|f| load File.expand_path(f) }
887
+ @spec_files_loaded = true
888
+ end
889
+
890
+ # @private
891
+ DEFAULT_FORMATTER = lambda { |string| string }
892
+
893
+ # Formats the docstring output using the block provided.
894
+ #
895
+ # @example
896
+ # # This will strip the descriptions of both examples and example groups.
897
+ # RSpec.configure do |config|
898
+ # config.format_docstrings { |s| s.strip }
899
+ # end
900
+ def format_docstrings(&block)
901
+ @format_docstrings_block = block_given? ? block : DEFAULT_FORMATTER
902
+ end
903
+
904
+ # @private
905
+ def format_docstrings_block
906
+ @format_docstrings_block ||= DEFAULT_FORMATTER
907
+ end
908
+
909
+ # @private
910
+ def self.delegate_to_ordering_manager(*methods)
911
+ methods.each do |method|
912
+ define_method method do |*args, &block|
913
+ ordering_manager.__send__(method, *args, &block)
914
+ end
915
+ end
916
+ end
917
+
918
+ # @macro delegate_to_ordering_manager
919
+ #
920
+ # Sets the seed value and sets the default global ordering to random.
921
+ delegate_to_ordering_manager :seed=
922
+
923
+ # @macro delegate_to_ordering_manager
924
+ # Seed for random ordering (default: generated randomly each run).
925
+ #
926
+ # When you run specs with `--order random`, RSpec generates a random seed
927
+ # for the randomization and prints it to the `output_stream` (assuming
928
+ # you're using RSpec's built-in formatters). If you discover an ordering
929
+ # dependency (i.e. examples fail intermittently depending on order), set
930
+ # this (on Configuration or on the command line with `--seed`) to run
931
+ # using the same seed while you debug the issue.
932
+ #
933
+ # We recommend, actually, that you use the command line approach so you
934
+ # don't accidentally leave the seed encoded.
935
+ delegate_to_ordering_manager :seed
936
+
937
+ # @macro delegate_to_ordering_manager
938
+ #
939
+ # Sets the default global order and, if order is `'rand:<seed>'`, also sets the seed.
940
+ delegate_to_ordering_manager :order=
941
+
942
+ # @macro delegate_to_ordering_manager
943
+ # Registers a named ordering strategy that can later be
944
+ # used to order an example group's subgroups by adding
945
+ # `:order => <name>` metadata to the example group.
946
+ #
947
+ # @param name [Symbol] The name of the ordering.
948
+ # @yield Block that will order the given examples or example groups
949
+ # @yieldparam list [Array<RSpec::Core::Example>, Array<RSpec::Core::ExampleGroup>] The examples or groups to order
950
+ # @yieldreturn [Array<RSpec::Core::Example>, Array<RSpec::Core::ExampleGroup>] The re-ordered examples or groups
951
+ #
952
+ # @example
953
+ # RSpec.configure do |rspec|
954
+ # rspec.register_ordering :reverse do |list|
955
+ # list.reverse
956
+ # end
957
+ # end
958
+ #
959
+ # describe MyClass, :order => :reverse do
960
+ # # ...
961
+ # end
962
+ #
963
+ # @note Pass the symbol `:global` to set the ordering strategy that
964
+ # will be used to order the top-level example groups and any example
965
+ # groups that do not have declared `:order` metadata.
966
+ delegate_to_ordering_manager :register_ordering
967
+
968
+ # @private
969
+ delegate_to_ordering_manager :seed_used?, :ordering_registry
970
+
971
+ # Set Ruby warnings on or off
972
+ def warnings= value
973
+ $VERBOSE = !!value
974
+ end
975
+
976
+ def warnings
977
+ $VERBOSE
978
+ end
979
+
980
+ # Exposes the current running example via the named
981
+ # helper method. RSpec 2.x exposed this via `example`,
982
+ # but in RSpec 3.0, the example is instead exposed via
983
+ # an arg yielded to `it`, `before`, `let`, etc. However,
984
+ # some extension gems (such as Capybara) depend on the
985
+ # RSpec 2.x's `example` method, so this config option
986
+ # can be used to maintain compatibility.
987
+ #
988
+ # @param method_name [Symbol] the name of the helper method
989
+ #
990
+ # @example
991
+ #
992
+ # RSpec.configure do |rspec|
993
+ # rspec.expose_current_running_example_as :example
994
+ # end
995
+ #
996
+ # describe MyClass do
997
+ # before do
998
+ # # `example` can be used here because of the above config.
999
+ # do_something if example.metadata[:type] == "foo"
1000
+ # end
1001
+ # end
1002
+ def expose_current_running_example_as(method_name)
1003
+ ExposeCurrentExample.module_eval do
1004
+ extend RSpec::SharedContext
1005
+ let(method_name) { |ex| ex }
1006
+ end
1007
+
1008
+ include ExposeCurrentExample
1009
+ end
1010
+
1011
+ module ExposeCurrentExample; end
1012
+
1013
+ # Turns deprecation warnings into errors, in order to surface
1014
+ # the full backtrace of the call site. This can be useful when
1015
+ # you need more context to address a deprecation than the
1016
+ # single-line call site normally provided.
1017
+ #
1018
+ # @example
1019
+ #
1020
+ # RSpec.configure do |rspec|
1021
+ # rspec.raise_errors_for_deprecations!
1022
+ # end
1023
+ def raise_errors_for_deprecations!
1024
+ self.deprecation_stream = Formatters::DeprecationFormatter::RaiseErrorStream.new
1025
+ end
1026
+
1027
+ private
1028
+
1029
+ def get_files_to_run(paths)
1030
+ FlatMap.flat_map(paths) do |path|
1031
+ path = path.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
1032
+ File.directory?(path) ? gather_directories(path) : extract_location(path)
1033
+ end.sort
1034
+ end
1035
+
1036
+ def gather_directories(path)
1037
+ stripped = "{#{pattern.gsub(/\s*,\s*/, ',')}}"
1038
+ files = pattern =~ /^#{Regexp.escape path}/ ? Dir[stripped] : Dir["#{path}/#{stripped}"]
1039
+ files.sort
1040
+ end
1041
+
1042
+ def extract_location(path)
1043
+ if path =~ /^(.*?)((?:\:\d+)+)$/
1044
+ path, lines = $1, $2[1..-1].split(":").map{|n| n.to_i}
1045
+ filter_manager.add_location path, lines
1046
+ end
1047
+ path
1048
+ end
1049
+
1050
+ def command
1051
+ $0.split(File::SEPARATOR).last
1052
+ end
1053
+
1054
+ def value_for(key, default=nil)
1055
+ @preferred_options.has_key?(key) ? @preferred_options[key] : default
1056
+ end
1057
+
1058
+ def assert_no_example_groups_defined(config_option)
1059
+ if RSpec.world.example_groups.any?
1060
+ raise MustBeConfiguredBeforeExampleGroupsError.new(
1061
+ "RSpec's #{config_option} configuration option must be configured before " +
1062
+ "any example groups are defined, but you have already defined a group."
1063
+ )
1064
+ end
1065
+ end
1066
+
1067
+ def output_to_tty?(output=output_stream)
1068
+ tty? || (output.respond_to?(:tty?) && output.tty?)
1069
+ end
1070
+
1071
+ def built_in_formatter(key)
1072
+ case key.to_s
1073
+ when 'd', 'doc', 'documentation', 's', 'n', 'spec', 'nested'
1074
+ require 'rspec/core/formatters/documentation_formatter'
1075
+ RSpec::Core::Formatters::DocumentationFormatter
1076
+ when 'h', 'html'
1077
+ require 'rspec/core/formatters/html_formatter'
1078
+ RSpec::Core::Formatters::HtmlFormatter
1079
+ when 'p', 'progress'
1080
+ require 'rspec/core/formatters/progress_formatter'
1081
+ RSpec::Core::Formatters::ProgressFormatter
1082
+ when 'j', 'json'
1083
+ require 'rspec/core/formatters/json_formatter'
1084
+ RSpec::Core::Formatters::JsonFormatter
1085
+ end
1086
+ end
1087
+
1088
+ def custom_formatter(formatter_ref)
1089
+ if Class === formatter_ref
1090
+ formatter_ref
1091
+ elsif string_const?(formatter_ref)
1092
+ begin
1093
+ formatter_ref.gsub(/^::/,'').split('::').inject(Object) { |const,string| const.const_get string }
1094
+ rescue NameError
1095
+ require( path_for(formatter_ref) ) ? retry : raise
1096
+ end
1097
+ end
1098
+ end
1099
+
1100
+ def string_const?(str)
1101
+ str.is_a?(String) && /\A[A-Z][a-zA-Z0-9_:]*\z/ =~ str
1102
+ end
1103
+
1104
+ def path_for(const_ref)
1105
+ underscore_with_fix_for_non_standard_rspec_naming(const_ref)
1106
+ end
1107
+
1108
+ def underscore_with_fix_for_non_standard_rspec_naming(string)
1109
+ underscore(string).sub(%r{(^|/)r_spec($|/)}, '\\1rspec\\2')
1110
+ end
1111
+
1112
+ # activesupport/lib/active_support/inflector/methods.rb, line 48
1113
+ def underscore(camel_cased_word)
1114
+ word = camel_cased_word.to_s.dup
1115
+ word.gsub!(/::/, '/')
1116
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
1117
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
1118
+ word.tr!("-", "_")
1119
+ word.downcase!
1120
+ word
1121
+ end
1122
+
1123
+ def file_at(path)
1124
+ FileUtils.mkdir_p(File.dirname(path))
1125
+ File.new(path, 'w')
1126
+ end
1127
+ end
1128
+ end
1129
+ end