Class: RSpec::Core::Configuration
- Inherits:
-
Object
- Object
- RSpec::Core::Configuration
- Includes:
- Module.new, Hooks
- Defined in:
- lib/rspec/core/configuration.rb
Overview
Stores runtime configuration information.
Configuration options are loaded from ~/.rspec
, .rspec
,
.rspec-local
, command line switches, and the SPEC_OPTS
environment
variable (listed in lowest to highest precedence; for example, an option
in ~/.rspec
can be overridden by an option in .rspec-local
).
Constant Summary
Instance Attribute Summary (collapse)
-
- (Boolean) color
Returns the configuration option for color, but should not be used to check if color is supported.
-
- (void) default_color
The default output color.
-
- (void) default_path
Path to use if no path is provided to the
rspec
command (default:"spec"
). -
- (void) detail_color
Color used to print details.
-
- (void) drb
Run examples over DRb (default:
false
). -
- (void) drb_port
The drb_port (default: nil).
-
- (void) dry_run
Prints the formatter output of your suite without running any examples or hooks.
-
- (void) error_stream
Default:
$stderr
. -
- (void) example_status_persistence_file_path
The file path to use for persisting example statuses.
-
- (void) exclude_pattern
Exclude files matching this pattern.
-
- (void) fail_fast
If specified, indicates the number of failures required before cleaning up and exit (default:
nil
). -
- (void) failure_color
Color to use to indicate failure.
-
- (void) failure_exit_code
The exit code to return if there are any failures (default: 1).
-
- (Array) files_to_run
readonly
The spec files RSpec will run.
-
- (void) fixed_color
Color used when a pending example is fixed.
-
- (void) libs
readonly
Returns dirs that have been prepended to the load path by the
-I
command line option. -
- (void) max_displayed_failure_line_count
Maximum count of failed source lines to display in the failure reports.
-
- (void) only_failures
(also: #only_failures?)
readonly
Indicates if the
--only-failures
(or--next-failure
) flag is being used. -
- (void) output_stream
Determines where RSpec will send its output.
-
- (void) pattern
Load files matching this pattern (default:
'**{,/*/**}/*_spec.rb'
). -
- (void) pending_color
Color to use to print pending examples.
-
- (void) profile_examples
private
Defaults
profile_examples
to 10 examples when@profile_examples
istrue
. -
- (Array<String>) project_source_dirs
Specifies which directories contain the source code for your project.
-
- (void) requires
readonly
Indicates files configured to be required.
-
- (void) run_all_when_everything_filtered
Run all examples if none match the configured filters (default:
false
). -
- (void) silence_filter_announcements
Don't print filter info i.e.
-
- (void) success_color
Color to use to indicate success.
-
- (void) threadsafe
Use threadsafe options where available.
Instance Method Summary (collapse)
-
- (void) add_formatter(formatter)
(also: #formatter=)
Adds a formatter to the formatters collection.
-
- (void) add_setting(name, opts = {})
Adds a custom setting to the RSpec.configuration object.
-
- (void) after(*args, &block)
(also: #prepend_after)
Defines a
after
hook. -
- (void) alias_example_group_to(new_name, *args)
Creates a method that defines an example group with the provided metadata.
-
- (void) alias_example_to(name, *args)
Creates a method that delegates to
example
including the submittedargs
. -
- (void) alias_it_behaves_like_to(new_name, report_label = '')
(also: #alias_it_should_behave_like_to)
Define an alias for it_should_behave_like that allows different language (like "it_has_behavior" or "it_behaves_like") to be employed when including shared examples.
-
- (void) append_after(*args, &block)
Adds
block
to the end of the list ofafter
blocks in the same scope (:example
,:context
, or:suite
), in contrast to #after, which adds the hook to the start of the list. -
- (void) backtrace_exclusion_patterns
Regexps used to exclude lines from backtraces.
-
- (void) backtrace_exclusion_patterns=(patterns)
Set regular expressions used to exclude lines in backtrace.
-
- (void) backtrace_inclusion_patterns
Regexps used to include lines in backtraces.
-
- (void) backtrace_inclusion_patterns=(patterns)
Set regular expressions used to include lines in backtrace.
-
- (void) before(*args, &block)
(also: #append_before)
Defines a
before
hook. -
- (Boolean) color_enabled?(output = output_stream)
Check if color is enabled for a particular output.
-
- (void) default_formatter
The formatter that will be used if no formatter has been set.
-
- (void) default_formatter=(value)
Sets a fallback formatter to use if none other has been set.
-
- (void) define_derived_metadata(*filters) {|metadata| ... }
Defines a callback that can assign derived metadata values.
-
- (IO, String) deprecation_stream
Determines where deprecation warnings are printed.
-
- (void) deprecation_stream=(value)
Determines where deprecation warnings are printed.
-
- (void) disable_monkey_patching!
Enables zero monkey patching mode for RSpec.
-
- (void) exclusion_filter
Returns the
exclusion_filter
. -
- (void) exclusion_filter=(filter)
Clears and reassigns the
exclusion_filter
. -
- (void) expect_with(*frameworks)
Sets the expectation framework module(s) to be included in each example group.
-
- (void) expectation_framework=(framework)
Delegates to expect_with(framework).
-
- (void) expectation_frameworks
Returns the configured expectation framework adapter module(s).
-
- (void) expose_current_running_example_as(method_name)
Exposes the current running example via the named helper method.
-
- (void) expose_dsl_globally=(value)
Use this to expose the core RSpec DSL via
Module
and themain
object. -
- (Boolean) expose_dsl_globally?
Indicates if the DSL has been exposed off of modules and
main
. -
- (void) extend(mod, *filters)
Tells RSpec to extend example groups with
mod
. -
- (void) filter_gems_from_backtrace(*gem_names)
Adds #backtrace_exclusion_patterns that will filter lines from the named gems from backtraces.
-
- (void) filter_run_excluding(*args)
Adds key/value pairs to the
exclusion_filter
. -
- (void) filter_run_including(*args)
(also: #filter_run)
Adds key/value pairs to the
inclusion_filter
. -
- (void) format_docstrings(&block)
Formats the docstring output using the block provided.
-
- (Array) formatters
Returns a duplicate of the formatters currently loaded in the
FormatterLoader
for introspection. -
- (void) full_backtrace=(true_or_false)
Toggle full backtrace.
-
- (Boolean) full_backtrace?
Check if full backtrace is enabled.
-
- (Array) full_description
Full description filter.
-
- (void) full_description=(description)
Run examples matching on
description
in all files to run. -
- (void) include(mod, *filters)
Tells RSpec to include
mod
in example groups. -
- (void) inclusion_filter
(also: #filter)
Returns the
inclusion_filter
. -
- (void) inclusion_filter=(filter)
(also: #filter=)
Clears and reassigns the
inclusion_filter
. -
- (Configuration) initialize
constructor
A new instance of Configuration.
-
- (void) mock_framework
Returns the configured mock framework adapter module.
-
- (void) mock_framework=(framework)
Delegates to mock_framework=(framework).
-
- (void) mock_with(framework)
Sets the mock framework adapter module.
-
- (void) on_example_group_definition(&block)
Invokes block before defining an example group.
-
- (void) on_example_group_definition_callbacks
private
Returns an array of blocks to call before defining an example group.
-
- (void) order=
Sets the default global order and, if order is
'rand:'
, also sets the seed. -
- (void) prepend(mod, *filters)
Tells RSpec to prepend example groups with
mod
. -
- (void) prepend_before(*args, &block)
Adds
block
to the start of the list ofbefore
blocks in the same scope (:example
,:context
, or:suite
), in contrast to #before, which adds the hook to the end of the list. -
- (void) raise_errors_for_deprecations!
Turns deprecation warnings into errors, in order to surface the full backtrace of the call site.
-
- (void) raise_on_warning=(value)
Turns warnings into errors.
-
- (void) register_ordering {|list| ... }
Registers a named ordering strategy that can later be used to order an example group's subgroups by adding
:order =>
metadata to the example group. -
- (void) seed
Seed for random ordering (default: generated randomly each run).
-
- (void) seed=
Sets the seed value and sets the default global ordering to random.
-
- (void) treat_symbols_as_metadata_keys_with_true_values=(_value)
Deprecated.
-
- (void) warnings=(value)
Set Ruby warnings on or off.
-
- (Boolean) warnings?
Whether or not ruby warnings are enabled.
Methods included from Hooks
Constructor Details
- (Configuration) initialize
Returns a new instance of Configuration
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/rspec/core/configuration.rb', line 352 def initialize # rubocop:disable Style/GlobalVars @start_time = $_rspec_core_load_started_at || ::RSpec::Core::Time.now # rubocop:enable Style/GlobalVars @expectation_frameworks = [] @include_modules = FilterableItemRepository::QueryOptimized.new(:any?) @extend_modules = FilterableItemRepository::QueryOptimized.new(:any?) @prepend_modules = FilterableItemRepository::QueryOptimized.new(:any?) @before_suite_hooks = [] @after_suite_hooks = [] @mock_framework = nil @files_or_directories_to_run = [] @loaded_spec_files = Set.new @color = false @pattern = '**{,/*/**}/*_spec.rb' @exclude_pattern = '' @failure_exit_code = 1 @spec_files_loaded = false @backtrace_formatter = BacktraceFormatter.new @default_path = 'spec' @project_source_dirs = %w[ spec lib app ] @deprecation_stream = $stderr @output_stream = $stdout @reporter = nil @reporter_buffer = nil @filter_manager = FilterManager.new @static_config_filter_manager = FilterManager.new @ordering_manager = Ordering::ConfigurationManager.new @preferred_options = {} @failure_color = :red @success_color = :green @pending_color = :yellow @default_color = :white @fixed_color = :blue @detail_color = :cyan @profile_examples = false @requires = [] @libs = [] @derived_metadata_blocks = FilterableItemRepository::QueryOptimized.new(:any?) @threadsafe = true @max_displayed_failure_line_count = 10 define_built_in_hooks end |
Instance Attribute Details
- (Boolean) color
Returns the configuration option for color, but should not be used to check if color is supported.
720 721 722 |
# File 'lib/rspec/core/configuration.rb', line 720 def color value_for(:color) { @color } end |
- (void) default_color
The default output color.
295 |
# File 'lib/rspec/core/configuration.rb', line 295 add_setting :default_color |
- (void) default_path
Other scripts invoking rspec
indirectly will ignore this
setting.
Path to use if no path is provided to the rspec
command (default:
"spec"
). Allows you to just type rspec
instead of rspec spec
to
run all the examples in the spec
directory.
103 |
# File 'lib/rspec/core/configuration.rb', line 103 add_read_only_setting :default_path |
- (void) detail_color
Color used to print details.
309 |
# File 'lib/rspec/core/configuration.rb', line 309 add_setting :detail_color |
- (void) drb
Run examples over DRb (default: false
). RSpec doesn't supply the DRb
server, but you can use tools like spork.
112 |
# File 'lib/rspec/core/configuration.rb', line 112 add_setting :drb |
- (void) drb_port
The drb_port (default: nil).
116 |
# File 'lib/rspec/core/configuration.rb', line 116 add_setting :drb_port |
- (void) dry_run
Prints the formatter output of your suite without running any examples or hooks.
196 |
# File 'lib/rspec/core/configuration.rb', line 196 add_setting :dry_run |
- (void) error_stream
Default: $stderr
.
120 |
# File 'lib/rspec/core/configuration.rb', line 120 add_setting :error_stream |
- (String) example_status_persistence_file_path - (void) example_status_persistence_file_path=(value)
The file path to use for persisting example statuses. Necessary for the
--only-failures
and --next-failures
CLI options.
169 |
# File 'lib/rspec/core/configuration.rb', line 169 define_reader :example_status_persistence_file_path |
- (void) exclude_pattern
Exclude files matching this pattern.
241 |
# File 'lib/rspec/core/configuration.rb', line 241 define_reader :exclude_pattern |
- (void) fail_fast
If specified, indicates the number of failures required before cleaning
up and exit (default: nil
).
191 |
# File 'lib/rspec/core/configuration.rb', line 191 add_setting :fail_fast |
- (void) failure_color
Color to use to indicate failure.
288 |
# File 'lib/rspec/core/configuration.rb', line 288 add_setting :failure_color |
- (void) failure_exit_code
The exit code to return if there are any failures (default: 1).
200 |
# File 'lib/rspec/core/configuration.rb', line 200 add_setting :failure_exit_code |
- (Array) files_to_run
The spec files RSpec will run.
866 867 868 |
# File 'lib/rspec/core/configuration.rb', line 866 def files_to_run @files_to_run ||= get_files_to_run(@files_or_directories_to_run) end |
- (void) fixed_color
Color used when a pending example is fixed.
302 |
# File 'lib/rspec/core/configuration.rb', line 302 add_setting :fixed_color |
- (void) libs
Returns dirs that have been prepended to the load path by the -I
command line option.
209 |
# File 'lib/rspec/core/configuration.rb', line 209 define_reader :libs |
- (void) max_displayed_failure_line_count
Maximum count of failed source lines to display in the failure reports.
(default 10
).
339 |
# File 'lib/rspec/core/configuration.rb', line 339 add_setting :max_displayed_failure_line_count |
- (void) only_failures (readonly) Also known as: only_failures?
Indicates if the --only-failures
(or --next-failure
) flag is being used.
180 |
# File 'lib/rspec/core/configuration.rb', line 180 define_reader :only_failures |
- (void) output_stream
Determines where RSpec will send its output.
Default: $stdout
.
214 |
# File 'lib/rspec/core/configuration.rb', line 214 define_reader :output_stream |
- (void) pattern
Load files matching this pattern (default: '**{,/*/**}/*_spec.rb'
).
231 |
# File 'lib/rspec/core/configuration.rb', line 231 define_reader :pattern |
- (void) pending_color
Color to use to print pending examples.
281 |
# File 'lib/rspec/core/configuration.rb', line 281 add_setting :pending_color |
- (void) profile_examples
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Defaults profile_examples
to 10 examples when @profile_examples
is
true
.
262 |
# File 'lib/rspec/core/configuration.rb', line 262 add_setting :profile_examples |
- (Array<String>) project_source_dirs
Specifies which directories contain the source code for your project. When a failure occurs, RSpec looks through the backtrace to find a a line of source to print. It first looks for a line coming from one of the project source directories so that, for example, it prints the expectation or assertion call rather than the source code from the expectation or assertion framework.
257 |
# File 'lib/rspec/core/configuration.rb', line 257 add_setting :project_source_dirs |
- (void) requires
Indicates files configured to be required.
204 |
# File 'lib/rspec/core/configuration.rb', line 204 define_reader :requires |
- (void) run_all_when_everything_filtered
Run all examples if none match the configured filters
(default: false
).
267 |
# File 'lib/rspec/core/configuration.rb', line 267 add_setting :run_all_when_everything_filtered |
- (void) silence_filter_announcements
Don't print filter info i.e. "Run options: include :focus=>true"
(default false
).
314 |
# File 'lib/rspec/core/configuration.rb', line 314 add_setting :silence_filter_announcements |
- (void) success_color
Color to use to indicate success.
274 |
# File 'lib/rspec/core/configuration.rb', line 274 add_setting :success_color |
- (void) threadsafe
Use threadsafe options where available. Currently this will place a mutex around memoized values such as let blocks.
334 |
# File 'lib/rspec/core/configuration.rb', line 334 add_setting :threadsafe |
Instance Method Details
- (void) add_formatter(formatter) Also known as: formatter=
Adds a formatter to the formatters collection. formatter
can be a
string representing any of the built-in formatters (see
built_in_formatter
), or a custom formatter class.
Note
For internal purposes, add_formatter
also accepts the name of a class
and paths to use for output streams, but you should consider that a
private api that may change at any time without notice.
765 766 767 768 |
# File 'lib/rspec/core/configuration.rb', line 765 def add_formatter(formatter_to_use, *paths) paths << output_stream if paths.empty? formatter_loader.add formatter_to_use, *paths end |
- (void) add_setting(name) - (void) add_setting(name, opts)
Adds a custom setting to the RSpec.configuration object.
RSpec.configuration.add_setting :foo
Used internally and by extension frameworks like rspec-rails, so they can add config settings that are domain specific. For example:
RSpec.configure do |c|
c.add_setting :use_transactional_fixtures,
:default => true,
:alias_with => :use_transactional_examples
end
add_setting
creates three methods on the configuration object, a
setter, a getter, and a predicate:
RSpec.configuration.foo=(value)
RSpec.configuration.foo
RSpec.configuration.foo? # Returns true if foo returns anything but nil or false.
465 466 467 468 469 470 471 |
# File 'lib/rspec/core/configuration.rb', line 465 def add_setting(name, opts={}) default = opts.delete(:default) (class << self; self; end).class_exec do add_setting(name, opts) end __send__("#{name}=", default) if default end |
- (void) after(*args, &block) Also known as: prepend_after
Defines a after
hook. See Hooks#after for full docs.
This method differs from Hooks#after in only one way: it supports
the :suite
scope. Hooks with the :suite
scope will be run once after
the last example of the entire suite is executed.
1649 1650 1651 1652 |
# File 'lib/rspec/core/configuration.rb', line 1649 def after(*args, &block) handle_suite_hook(args, @after_suite_hooks, :unshift, Hooks::AfterHook, block) || super(*args, &block) end |
- (void) alias_example_group_to(new_name, *args)
The defined aliased will also be added to the top level
(e.g. main
and from within modules) if
expose_dsl_globally
is set to true.
Creates a method that defines an example group with the provided metadata. Can be used to define example group/metadata shortcuts.
968 969 970 971 |
# File 'lib/rspec/core/configuration.rb', line 968 def alias_example_group_to(new_name, *args) = Metadata.build_hash_from(args) RSpec::Core::ExampleGroup.define_example_group_method(new_name, ) end |
- (void) alias_example_to(name, *args)
The specific example alias below (pending
) is already
defined for you.
Use with caution. This extends the language used in your
specs, but does not add any additional documentation. We use this
in RSpec to define methods like focus
and xit
, but we also add
docs for those methods.
Creates a method that delegates to example
including the submitted
args
. Used internally to add variants of example
like pending
:
936 937 938 939 |
# File 'lib/rspec/core/configuration.rb', line 936 def alias_example_to(name, *args) = Metadata.build_hash_from(args) RSpec::Core::ExampleGroup.define_example_method(name, ) end |
- (void) alias_it_behaves_like_to(new_name, report_label = '') Also known as: alias_it_should_behave_like_to
Use with caution. This extends the language used in your
specs, but does not add any additional documentation. We use this
in RSpec to define it_should_behave_like
(for backward
compatibility), but we also add docs for that method.
Define an alias for it_should_behave_like that allows different language (like "it_has_behavior" or "it_behaves_like") to be employed when including shared examples.
999 1000 1001 |
# File 'lib/rspec/core/configuration.rb', line 999 def alias_it_behaves_like_to(new_name, report_label='') RSpec::Core::ExampleGroup.define_nested_shared_group_method(new_name, report_label) end |
- (void) append_after(*args, &block)
Adds block
to the end of the list of after
blocks in the same
scope (:example
, :context
, or :suite
), in contrast to #after,
which adds the hook to the start of the list.
See Hooks#after for full after
hook docs.
This method differs from Hooks#append_after in only one way: it supports
the :suite
scope. Hooks with the :suite
scope will be run once after
the last example of the entire suite is executed.
1668 1669 1670 1671 |
# File 'lib/rspec/core/configuration.rb', line 1668 def append_after(*args, &block) handle_suite_hook(args, @after_suite_hooks, :push, Hooks::AfterHook, block) || super(*args, &block) end |
- (void) backtrace_exclusion_patterns
Regexps used to exclude lines from backtraces.
Excludes lines from ruby (and jruby) source, installed gems, anything in any "bin" directory, and any of the RSpec libs (outside gem installs) by default.
You can modify the list via the getter, or replace it with the setter.
To override this behaviour and display a full backtrace, use
--backtrace
on the command line, in a .rspec
file, or in the
rspec_options
attribute of RSpec's rake task.
501 502 503 |
# File 'lib/rspec/core/configuration.rb', line 501 def backtrace_exclusion_patterns @backtrace_formatter.exclusion_patterns end |
- (void) backtrace_exclusion_patterns=(patterns)
Set regular expressions used to exclude lines in backtrace.
507 508 509 |
# File 'lib/rspec/core/configuration.rb', line 507 def backtrace_exclusion_patterns=(patterns) @backtrace_formatter.exclusion_patterns = patterns end |
- (void) backtrace_inclusion_patterns
Regexps used to include lines in backtraces.
Defaults to [Regexp.new Dir.getwd].
Lines that match an exclusion and an inclusion pattern will be included.
You can modify the list via the getter, or replace it with the setter.
519 520 521 |
# File 'lib/rspec/core/configuration.rb', line 519 def backtrace_inclusion_patterns @backtrace_formatter.inclusion_patterns end |
- (void) backtrace_inclusion_patterns=(patterns)
Set regular expressions used to include lines in backtrace.
525 526 527 |
# File 'lib/rspec/core/configuration.rb', line 525 def backtrace_inclusion_patterns=(patterns) @backtrace_formatter.inclusion_patterns = patterns end |
- (void) before(*args, &block) Also known as: append_before
Defines a before
hook. See Hooks#before for full docs.
This method differs from Hooks#before in only one way: it supports
the :suite
scope. Hooks with the :suite
scope will be run once before
the first example of the entire suite is executed.
1616 1617 1618 1619 |
# File 'lib/rspec/core/configuration.rb', line 1616 def before(*args, &block) handle_suite_hook(args, @before_suite_hooks, :push, Hooks::BeforeHook, block) || super(*args, &block) end |
- (Boolean) color_enabled?(output = output_stream)
Check if color is enabled for a particular output.
728 729 730 |
# File 'lib/rspec/core/configuration.rb', line 728 def color_enabled?(output=output_stream) output_to_tty?(output) && color end |
- (void) default_formatter
The formatter that will be used if no formatter has been set. Defaults to 'progress'.
773 774 775 |
# File 'lib/rspec/core/configuration.rb', line 773 def default_formatter formatter_loader.default_formatter end |
- (void) default_formatter=(value)
Sets a fallback formatter to use if none other has been set.
784 785 786 |
# File 'lib/rspec/core/configuration.rb', line 784 def default_formatter=(value) formatter_loader.default_formatter = value end |
- (void) define_derived_metadata(*filters) {|metadata| ... }
Defines a callback that can assign derived metadata values.
1595 1596 1597 1598 |
# File 'lib/rspec/core/configuration.rb', line 1595 def (*filters, &block) = Metadata.build_hash_from(filters, :warn_about_example_group_filtering) @derived_metadata_blocks.append(block, ) end |
- (IO, String) deprecation_stream
Determines where deprecation warnings are printed.
Defaults to $stderr
.
145 |
# File 'lib/rspec/core/configuration.rb', line 145 define_reader :deprecation_stream |
- (void) deprecation_stream=(value)
Determines where deprecation warnings are printed.
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/rspec/core/configuration.rb', line 149 def deprecation_stream=(value) if @reporter && !value.equal?(@deprecation_stream) warn "RSpec's reporter has already been initialized with " \ "#{deprecation_stream.inspect} as the deprecation stream, so your change to "\ "`deprecation_stream` will be ignored. You should configure it earlier for " \ "it to take effect, or use the `--deprecation-out` CLI option. " \ "(Called from #{CallerFilter.first_non_rspec_line})" else @deprecation_stream = value end end |
- (void) disable_monkey_patching!
It configures rspec-mocks and rspec-expectations only
if the user is using those (either explicitly or implicitly
by not setting mock_with
or expect_with
to anything else).
If the user uses this options with mock_with :mocha
(or similiar) they will still have monkey patching active
in their test environment from mocha.
Enables zero monkey patching mode for RSpec. It removes monkey
patching of the top-level DSL methods (describe
,
shared_examples_for
, etc) onto main
and Module
, instead
requiring you to prefix these methods with RSpec.
. It enables
expect-only syntax for rspec-mocks and rspec-expectations. It
simply disables monkey patching on whatever pieces of RSpec
the user is using.
1568 1569 1570 1571 1572 1573 |
# File 'lib/rspec/core/configuration.rb', line 1568 def disable_monkey_patching! self.expose_dsl_globally = false self.disable_monkey_patching = true conditionally_disable_mocks_monkey_patching conditionally_disable_expectations_monkey_patching end |
- (void) exclusion_filter
Returns the exclusion_filter
. If none has been set, returns an empty
hash.
1114 1115 1116 |
# File 'lib/rspec/core/configuration.rb', line 1114 def exclusion_filter filter_manager.exclusions end |
- (void) exclusion_filter=(filter)
Clears and reassigns the exclusion_filter
. Set to nil
if you don't
want any exclusion filter at all.
Warning
This overrides any exclusion filters/tags set on the command line or in configuration files.
1107 1108 1109 1110 |
# File 'lib/rspec/core/configuration.rb', line 1107 def exclusion_filter=(filter) = Metadata.build_hash_from([filter], :warn_about_example_group_filtering) filter_manager.exclude_only end |
- (void) expect_with(*frameworks)
Sets the expectation framework module(s) to be included in each example group.
frameworks
can be :rspec
, :test_unit
, :minitest
, a custom
module, or any combination thereof:
config.expect_with :rspec
config.expect_with :test_unit
config.expect_with :minitest
config.expect_with :rspec, :minitest
config.expect_with OtherExpectationFramework
RSpec will translate :rspec
, :minitest
, and :test_unit
into the
appropriate modules.
Configuration
If the module responds to configuration
, expect_with
will
yield the configuration
object if given a block:
config.expect_with OtherExpectationFramework do |custom_config|
custom_config.custom_setting = true
end
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 |
# File 'lib/rspec/core/configuration.rb', line 661 def expect_with(*frameworks) modules = frameworks.map do |framework| case framework when Module framework when :rspec require 'rspec/expectations' # Tag this exception class so our exception formatting logic knows # that it satisfies the `MultipleExceptionError` interface. ::RSpec::Expectations::MultipleExpectationsNotMetError.__send__( :include, MultipleExceptionError::InterfaceTag ) ::RSpec::Matchers when :test_unit require 'rspec/core/test_unit_assertions_adapter' ::RSpec::Core::TestUnitAssertionsAdapter when :minitest require 'rspec/core/minitest_assertions_adapter' ::RSpec::Core::MinitestAssertionsAdapter else raise ArgumentError, "#{framework.inspect} is not supported" end end if (modules - @expectation_frameworks).any? assert_no_example_groups_defined(:expect_with) end if block_given? 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 raise "#{modules.first} must respond to `configuration` so that " \ "expect_with can yield it." unless modules.first.respond_to?(:configuration) yield modules.first.configuration end @expectation_frameworks.push(*modules) end |
- (void) expectation_framework=(framework)
Delegates to expect_with(framework).
634 635 636 |
# File 'lib/rspec/core/configuration.rb', line 634 def expectation_framework=(framework) expect_with(framework) end |
- (void) expectation_frameworks
Returns the configured expectation framework adapter module(s)
622 623 624 625 626 627 628 629 630 631 |
# File 'lib/rspec/core/configuration.rb', line 622 def expectation_frameworks if @expectation_frameworks.empty? begin expect_with :rspec rescue LoadError expect_with Module.new end end @expectation_frameworks end |
- (void) expose_current_running_example_as(method_name)
Exposes the current running example via the named
helper method. RSpec 2.x exposed this via example
,
but in RSpec 3.0, the example is instead exposed via
an arg yielded to it
, before
, let
, etc. However,
some extension gems (such as Capybara) depend on the
RSpec 2.x's example
method, so this config option
can be used to maintain compatibility.
1506 1507 1508 1509 1510 1511 1512 1513 |
# File 'lib/rspec/core/configuration.rb', line 1506 def expose_current_running_example_as(method_name) ExposeCurrentExample.module_exec do extend RSpec::SharedContext let(method_name) { |ex| ex } end include ExposeCurrentExample end |
- (void) expose_dsl_globally=(value)
Use this to expose the core RSpec DSL via Module
and the main
object. It will be set automatically but you can override it to
remove the DSL.
Default: true
132 133 134 135 136 137 138 139 140 |
# File 'lib/rspec/core/configuration.rb', line 132 def expose_dsl_globally=(value) if value Core::DSL.expose_globally! Core::SharedExampleGroup::TopLevelDSL.expose_globally! else Core::DSL.remove_globally! Core::SharedExampleGroup::TopLevelDSL.remove_globally! end end |
- (Boolean) expose_dsl_globally?
Indicates if the DSL has been exposed off of modules and main
.
Default: true
124 125 126 |
# File 'lib/rspec/core/configuration.rb', line 124 def expose_dsl_globally? Core::DSL.exposed_globally? end |
- (void) extend(mod, *filters)
Tells RSpec to extend example groups with mod
. Methods defined in
mod
are exposed to example groups (not examples). Use filters
to
constrain the groups to extend.
Similar to include
, but behavior is added to example groups, which
are classes, rather than the examples, which are instances of those
classes.
1194 1195 1196 1197 1198 |
# File 'lib/rspec/core/configuration.rb', line 1194 def extend(mod, *filters) = Metadata.build_hash_from(filters, :warn_about_example_group_filtering) @extend_modules.append(mod, ) configure_existing_groups(mod, , :safe_extend) end |
- (void) filter_gems_from_backtrace(*gem_names)
The patterns this adds will match the named gems in their common locations (e.g. system gems, vendored with bundler, installed as a :git dependency with bundler, etc) but is not guaranteed to work for all possible gem locations. For example, if you have the gem source in a directory with a completely unrelated name, and use bundler's :path option, this will not filter it.
Adds #backtrace_exclusion_patterns that will filter lines from the named gems from backtraces.
545 546 547 548 549 |
# File 'lib/rspec/core/configuration.rb', line 545 def filter_gems_from_backtrace(*gem_names) gem_names.each do |name| @backtrace_formatter.filter_gem(name) end end |
- (void) filter_run_excluding(*args)
Adds key/value pairs to the exclusion_filter
. If args
includes any symbols that are not part of the hash, each symbol
is treated as a key in the hash with the value true
.
Note
Filters set using this method can be overridden from the command line
or config files (e.g. .rspec
).
1094 1095 1096 1097 1098 |
# File 'lib/rspec/core/configuration.rb', line 1094 def filter_run_excluding(*args) = Metadata.build_hash_from(args, :warn_about_example_group_filtering) filter_manager.exclude_with_low_priority static_config_filter_manager.exclude_with_low_priority Metadata.deep_hash_dup() end |
- (void) filter_run_including(*args) Also known as: filter_run
Adds key/value pairs to the inclusion_filter
. If args
includes any symbols that are not part of the hash, each symbol
is treated as a key in the hash with the value true
.
Note
Filters set using this method can be overridden from the command line
or config files (e.g. .rspec
).
1034 1035 1036 1037 1038 |
# File 'lib/rspec/core/configuration.rb', line 1034 def filter_run_including(*args) = Metadata.build_hash_from(args, :warn_about_example_group_filtering) filter_manager.include_with_low_priority static_config_filter_manager.include_with_low_priority Metadata.deep_hash_dup() end |
- (void) format_docstrings(&block)
Formats the docstring output using the block provided.
1379 1380 1381 |
# File 'lib/rspec/core/configuration.rb', line 1379 def format_docstrings(&block) @format_docstrings_block = block_given? ? block : DEFAULT_FORMATTER end |
- (Array) formatters
Returns a duplicate of the formatters currently loaded in
the FormatterLoader
for introspection.
Note as this is a duplicate, any mutations will be disregarded.
794 795 796 |
# File 'lib/rspec/core/configuration.rb', line 794 def formatters formatter_loader.formatters.dup end |
- (void) full_backtrace=(true_or_false)
Toggle full backtrace.
711 712 713 |
# File 'lib/rspec/core/configuration.rb', line 711 def full_backtrace=(true_or_false) @backtrace_formatter.full_backtrace = true_or_false end |
- (Boolean) full_backtrace?
Check if full backtrace is enabled.
705 706 707 |
# File 'lib/rspec/core/configuration.rb', line 705 def full_backtrace? @backtrace_formatter.full_backtrace? end |
- (Array) full_description
Returns full description filter
750 751 752 |
# File 'lib/rspec/core/configuration.rb', line 750 def full_description filter.fetch :full_description, nil end |
- (void) full_description=(description)
Run examples matching on description
in all files to run.
745 746 747 |
# File 'lib/rspec/core/configuration.rb', line 745 def full_description=(description) filter_run :full_description => Regexp.union(*Array(description).map { |d| Regexp.new(d) }) end |
- (void) include(mod, *filters)
Filtered module inclusions can also be applied to individual examples that have matching metadata. Just like Ruby's object model is that every object has a singleton class which has only a single instance, RSpec's model is that every example has a singleton example group containing just the one example.
Tells RSpec to include mod
in example groups. Methods defined in
mod
are exposed to examples (not example groups). Use filters
to
constrain the groups or examples in which to include the module.
1158 1159 1160 1161 1162 |
# File 'lib/rspec/core/configuration.rb', line 1158 def include(mod, *filters) = Metadata.build_hash_from(filters, :warn_about_example_group_filtering) @include_modules.append(mod, ) configure_existing_groups(mod, , :safe_include) end |
- (void) inclusion_filter Also known as: filter
Returns the inclusion_filter
. If none has been set, returns an empty
hash.
1058 1059 1060 |
# File 'lib/rspec/core/configuration.rb', line 1058 def inclusion_filter filter_manager.inclusions end |
- (void) inclusion_filter=(filter) Also known as: filter=
Clears and reassigns the inclusion_filter
. Set to nil
if you don't
want any inclusion filter at all.
Warning
This overrides any inclusion filters/tags set on the command line or in configuration files.
1049 1050 1051 1052 |
# File 'lib/rspec/core/configuration.rb', line 1049 def inclusion_filter=(filter) = Metadata.build_hash_from([filter], :warn_about_example_group_filtering) filter_manager.include_only end |
- (void) mock_framework
Returns the configured mock framework adapter module.
474 475 476 477 478 479 480 481 482 483 |
# File 'lib/rspec/core/configuration.rb', line 474 def mock_framework if @mock_framework.nil? begin mock_with :rspec rescue LoadError mock_with :nothing end end @mock_framework end |
- (void) mock_framework=(framework)
Delegates to mock_framework=(framework).
486 487 488 |
# File 'lib/rspec/core/configuration.rb', line 486 def mock_framework=(framework) mock_with framework end |
- (void) mock_with(framework)
Sets the mock framework adapter module.
framework
can be a Symbol or a Module.
Given any of :rspec
, :mocha
, :flexmock
, or :rr
, configures the
named framework.
Given :nothing
, configures no framework. Use this if you don't use
any mocking framework to save a little bit of overhead.
Given a Module, includes that module in every example group. The module should adhere to RSpec's mock framework adapter API:
setup_mocks_for_rspec
- called before each example
verify_mocks_for_rspec
- called after each example if the example hasn't yet failed.
Framework should raise an exception when expectations fail
teardown_mocks_for_rspec
- called after verify_mocks_for_rspec (even if there are errors)
If the module responds to configuration
and mock_with
receives a
block, it will yield the configuration object to the block e.g.
config.mock_with OtherMockFrameworkAdapter do |mod_config|
mod_config.custom_setting = true
end
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 |
# File 'lib/rspec/core/configuration.rb', line 589 def mock_with(framework) framework_module = if framework.is_a?(Module) framework else const_name = MOCKING_ADAPTERS.fetch(framework) do raise ArgumentError, "Unknown mocking framework: #{framework.inspect}. " \ "Pass a module or one of #{MOCKING_ADAPTERS.keys.inspect}" end RSpec::Support.require_rspec_core "mocking_adapters/#{const_name.to_s.downcase}" RSpec::Core::MockingAdapters.const_get(const_name) end new_name, old_name = [framework_module, @mock_framework].map do |mod| mod.respond_to?(:framework_name) ? mod.framework_name : :unnamed end unless new_name == old_name assert_no_example_groups_defined(:mock_framework) end if block_given? raise "#{framework_module} must respond to `configuration` so that " \ "mock_with can yield it." unless framework_module.respond_to?(:configuration) yield framework_module.configuration end @mock_framework = framework_module end |
- (void) on_example_group_definition(&block)
Invokes block before defining an example group
1695 1696 1697 |
# File 'lib/rspec/core/configuration.rb', line 1695 def on_example_group_definition(&block) on_example_group_definition_callbacks << block end |
- (void) on_example_group_definition_callbacks
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns an array of blocks to call before defining an example group
1701 1702 1703 |
# File 'lib/rspec/core/configuration.rb', line 1701 def on_example_group_definition_callbacks @on_example_group_definition_callbacks ||= [] end |
- (void) order=
Sets the default global order and, if order is 'rand:<seed>'
, also
sets the seed.
1422 |
# File 'lib/rspec/core/configuration.rb', line 1422 delegate_to_ordering_manager :order= |
- (void) prepend(mod, *filters)
Tells RSpec to prepend example groups with mod
. Methods defined in
mod
are exposed to examples (not example groups). Use filters
to
constrain the groups in which to prepend the module.
Similar to include
, but module is included before the example group's class
in the ancestor chain.
1233 1234 1235 1236 1237 |
# File 'lib/rspec/core/configuration.rb', line 1233 def prepend(mod, *filters) = Metadata.build_hash_from(filters, :warn_about_example_group_filtering) @prepend_modules.append(mod, ) configure_existing_groups(mod, , :safe_prepend) end |
- (void) prepend_before(*args, &block)
Adds block
to the start of the list of before
blocks in the same
scope (:example
, :context
, or :suite
), in contrast to #before,
which adds the hook to the end of the list.
See Hooks#before for full before
hook docs.
This method differs from Hooks#prepend_before in only one way: it supports
the :suite
scope. Hooks with the :suite
scope will be run once before
the first example of the entire suite is executed.
1635 1636 1637 1638 |
# File 'lib/rspec/core/configuration.rb', line 1635 def prepend_before(*args, &block) handle_suite_hook(args, @before_suite_hooks, :unshift, Hooks::BeforeHook, block) || super(*args, &block) end |
- (void) raise_errors_for_deprecations!
Turns deprecation warnings into errors, in order to surface the full backtrace of the call site. This can be useful when you need more context to address a deprecation than the single-line call site normally provided.
1528 1529 1530 |
# File 'lib/rspec/core/configuration.rb', line 1528 def raise_errors_for_deprecations! self.deprecation_stream = Formatters::DeprecationFormatter::RaiseErrorStream.new end |
- (void) raise_on_warning=(value)
Turns warnings into errors. This can be useful when you want RSpec to run in a 'strict' no warning situation.
1476 1477 1478 1479 1480 1481 1482 |
# File 'lib/rspec/core/configuration.rb', line 1476 def raise_on_warning=(value) if value RSpec::Support.warning_notifier = RAISE_ERROR_WARNING_NOTIFIER else RSpec::Support.warning_notifier = RSpec::Support::DEFAULT_WARNING_NOTIFIER end end |
- (void) register_ordering {|list| ... }
Pass the symbol :global
to set the ordering strategy that
will be used to order the top-level example groups and any example
groups that do not have declared :order
metadata.
Registers a named ordering strategy that can later be
used to order an example group's subgroups by adding
:order => <name>
metadata to the example group.
1450 |
# File 'lib/rspec/core/configuration.rb', line 1450 delegate_to_ordering_manager :register_ordering |
- (void) seed
Seed for random ordering (default: generated randomly each run).
When you run specs with --order random
, RSpec generates a random seed
for the randomization and prints it to the output_stream
(assuming
you're using RSpec's built-in formatters). If you discover an ordering
dependency (i.e. examples fail intermittently depending on order), set
this (on Configuration or on the command line with --seed
) to run
using the same seed while you debug the issue.
We recommend, actually, that you use the command line approach so you don't accidentally leave the seed encoded.
1416 |
# File 'lib/rspec/core/configuration.rb', line 1416 delegate_to_ordering_manager :seed |
- (void) seed=
Sets the seed value and sets the default global ordering to random.
1402 |
# File 'lib/rspec/core/configuration.rb', line 1402 delegate_to_ordering_manager :seed= |
- (void) treat_symbols_as_metadata_keys_with_true_values=(_value)
Deprecated. This config option was added in RSpec 2 to pave the way for this being the default behavior in RSpec 3. Now this option is a no-op.
319 320 321 322 323 324 325 326 |
# File 'lib/rspec/core/configuration.rb', line 319 def (_value) RSpec.deprecate( "RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values=", :message => "RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values= " \ "is deprecated, it is now set to true as default and " \ "setting it to false has no effect." ) end |
- (void) warnings=(value)
Set Ruby warnings on or off.
1456 1457 1458 |
# File 'lib/rspec/core/configuration.rb', line 1456 def warnings=(value) $VERBOSE = !!value end |
- (Boolean) warnings?
Returns Whether or not ruby warnings are enabled.
1461 1462 1463 |
# File 'lib/rspec/core/configuration.rb', line 1461 def warnings? $VERBOSE end |