123456789_123456789_123456789_123456789_123456789_

Module: RSpec

Relationships & Source Files
Namespace Children
Modules:
Classes:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Defined in: rspec/lib/rspec/version.rb,
rspec-core/lib/rspec/core.rb,
rspec-core/lib/rspec/core/backtrace_formatter.rb,
rspec-core/lib/rspec/core/configuration.rb,
rspec-core/lib/rspec/core/configuration_options.rb,
rspec-core/lib/rspec/core/did_you_mean.rb,
rspec-core/lib/rspec/core/drb.rb,
rspec-core/lib/rspec/core/dsl.rb,
rspec-core/lib/rspec/core/example.rb,
rspec-core/lib/rspec/core/example_group.rb,
rspec-core/lib/rspec/core/example_status_persister.rb,
rspec-core/lib/rspec/core/filter_manager.rb,
rspec-core/lib/rspec/core/flat_map.rb,
rspec-core/lib/rspec/core/hooks.rb,
rspec-core/lib/rspec/core/invocations.rb,
rspec-core/lib/rspec/core/memoized_helpers.rb,
rspec-core/lib/rspec/core/metadata.rb,
rspec-core/lib/rspec/core/metadata_filter.rb,
rspec-core/lib/rspec/core/minitest_assertions_adapter.rb,
rspec-core/lib/rspec/core/ordering.rb,
rspec-core/lib/rspec/core/output_wrapper.rb,
rspec-core/lib/rspec/core/pending.rb,
rspec-core/lib/rspec/core/profiler.rb,
rspec-core/lib/rspec/core/project_initializer.rb,
rspec-core/lib/rspec/core/rake_task.rb,
rspec-core/lib/rspec/core/ruby_project.rb,
rspec-core/lib/rspec/core/runner.rb,
rspec-core/lib/rspec/core/sandbox.rb,
rspec-core/lib/rspec/core/set.rb,
rspec-core/lib/rspec/core/shared_context.rb,
rspec-core/lib/rspec/core/shared_example_group.rb,
rspec-core/lib/rspec/core/shell_escape.rb,
rspec-core/lib/rspec/core/test_unit_assertions_adapter.rb,
rspec-core/lib/rspec/core/version.rb,
rspec-core/lib/rspec/core/warnings.rb,
rspec-core/lib/rspec/core/world.rb,
rspec-core/lib/rspec/core/bisect/coordinator.rb,
rspec-core/lib/rspec/core/bisect/example_minimizer.rb,
rspec-core/lib/rspec/core/bisect/fork_runner.rb,
rspec-core/lib/rspec/core/bisect/server.rb,
rspec-core/lib/rspec/core/bisect/shell_command.rb,
rspec-core/lib/rspec/core/bisect/shell_runner.rb,
rspec-core/lib/rspec/core/bisect/utilities.rb,
rspec-core/lib/rspec/core/formatters/base_bisect_formatter.rb,
rspec-core/lib/rspec/core/formatters/base_formatter.rb,
rspec-core/lib/rspec/core/formatters/base_text_formatter.rb,
rspec-core/lib/rspec/core/formatters/bisect_drb_formatter.rb,
rspec-core/lib/rspec/core/formatters/bisect_progress_formatter.rb,
rspec-core/lib/rspec/core/formatters/console_codes.rb,
rspec-core/lib/rspec/core/formatters/deprecation_formatter.rb,
rspec-core/lib/rspec/core/formatters/documentation_formatter.rb,
rspec-core/lib/rspec/core/formatters/exception_presenter.rb,
rspec-core/lib/rspec/core/formatters/failure_list_formatter.rb,
rspec-core/lib/rspec/core/formatters/fallback_message_formatter.rb,
rspec-core/lib/rspec/core/formatters/helpers.rb,
rspec-core/lib/rspec/core/formatters/html_formatter.rb,
rspec-core/lib/rspec/core/formatters/html_printer.rb,
rspec-core/lib/rspec/core/formatters/html_snippet_extractor.rb,
rspec-core/lib/rspec/core/formatters/json_formatter.rb,
rspec-core/lib/rspec/core/formatters/profile_formatter.rb,
rspec-core/lib/rspec/core/formatters/progress_formatter.rb,
rspec-core/lib/rspec/core/formatters/protocol.rb,
rspec-core/lib/rspec/core/formatters/snippet_extractor.rb,
rspec-core/lib/rspec/core/formatters/syntax_highlighter.rb,
rspec-core/lib/rspec/core/mocking_adapters/flexmock.rb,
rspec-core/lib/rspec/core/mocking_adapters/mocha.rb,
rspec-core/lib/rspec/core/mocking_adapters/null.rb,
rspec-core/lib/rspec/core/mocking_adapters/rr.rb,
rspec-core/lib/rspec/core/mocking_adapters/rspec.rb,
rspec-expectations/lib/rspec/expectations.rb,
rspec-expectations/lib/rspec/matchers.rb,
rspec-expectations/lib/rspec/expectations/block_snippet_extractor.rb,
rspec-expectations/lib/rspec/expectations/configuration.rb,
rspec-expectations/lib/rspec/expectations/expectation_target.rb,
rspec-expectations/lib/rspec/expectations/fail_with.rb,
rspec-expectations/lib/rspec/expectations/failure_aggregator.rb,
rspec-expectations/lib/rspec/expectations/handler.rb,
rspec-expectations/lib/rspec/expectations/minitest_integration.rb,
rspec-expectations/lib/rspec/expectations/syntax.rb,
rspec-expectations/lib/rspec/expectations/version.rb,
rspec-expectations/lib/rspec/matchers/aliased_matcher.rb,
rspec-expectations/lib/rspec/matchers/built_in.rb,
rspec-expectations/lib/rspec/matchers/composable.rb,
rspec-expectations/lib/rspec/matchers/dsl.rb,
rspec-expectations/lib/rspec/matchers/english_phrasing.rb,
rspec-expectations/lib/rspec/matchers/fail_matchers.rb,
rspec-expectations/lib/rspec/matchers/generated_descriptions.rb,
rspec-expectations/lib/rspec/matchers/matcher_delegator.rb,
rspec-expectations/lib/rspec/matchers/matcher_protocol.rb,
rspec-expectations/lib/rspec/matchers/multi_matcher_diff.rb,
rspec-expectations/lib/rspec/matchers/built_in/all.rb,
rspec-expectations/lib/rspec/matchers/built_in/base_matcher.rb,
rspec-expectations/lib/rspec/matchers/built_in/be.rb,
rspec-expectations/lib/rspec/matchers/built_in/be_between.rb,
rspec-expectations/lib/rspec/matchers/built_in/be_instance_of.rb,
rspec-expectations/lib/rspec/matchers/built_in/be_kind_of.rb,
rspec-expectations/lib/rspec/matchers/built_in/be_within.rb,
rspec-expectations/lib/rspec/matchers/built_in/change.rb,
rspec-expectations/lib/rspec/matchers/built_in/compound.rb,
rspec-expectations/lib/rspec/matchers/built_in/contain_exactly.rb,
rspec-expectations/lib/rspec/matchers/built_in/count_expectation.rb,
rspec-expectations/lib/rspec/matchers/built_in/cover.rb,
rspec-expectations/lib/rspec/matchers/built_in/eq.rb,
rspec-expectations/lib/rspec/matchers/built_in/eql.rb,
rspec-expectations/lib/rspec/matchers/built_in/equal.rb,
rspec-expectations/lib/rspec/matchers/built_in/exist.rb,
rspec-expectations/lib/rspec/matchers/built_in/has.rb,
rspec-expectations/lib/rspec/matchers/built_in/have_attributes.rb,
rspec-expectations/lib/rspec/matchers/built_in/include.rb,
rspec-expectations/lib/rspec/matchers/built_in/match.rb,
rspec-expectations/lib/rspec/matchers/built_in/operators.rb,
rspec-expectations/lib/rspec/matchers/built_in/output.rb,
rspec-expectations/lib/rspec/matchers/built_in/raise_error.rb,
rspec-expectations/lib/rspec/matchers/built_in/respond_to.rb,
rspec-expectations/lib/rspec/matchers/built_in/satisfy.rb,
rspec-expectations/lib/rspec/matchers/built_in/start_or_end_with.rb,
rspec-expectations/lib/rspec/matchers/built_in/throw_symbol.rb,
rspec-expectations/lib/rspec/matchers/built_in/yield.rb,
rspec-mocks/lib/rspec/mocks.rb,
rspec-mocks/lib/rspec/mocks/argument_list_matcher.rb,
rspec-mocks/lib/rspec/mocks/argument_matchers.rb,
rspec-mocks/lib/rspec/mocks/configuration.rb,
rspec-mocks/lib/rspec/mocks/error_generator.rb,
rspec-mocks/lib/rspec/mocks/example_methods.rb,
rspec-mocks/lib/rspec/mocks/instance_method_stasher.rb,
rspec-mocks/lib/rspec/mocks/marshal_extension.rb,
rspec-mocks/lib/rspec/mocks/message_chain.rb,
rspec-mocks/lib/rspec/mocks/message_expectation.rb,
rspec-mocks/lib/rspec/mocks/method_double.rb,
rspec-mocks/lib/rspec/mocks/method_reference.rb,
rspec-mocks/lib/rspec/mocks/minitest_integration.rb,
rspec-mocks/lib/rspec/mocks/minitest_integration.rb,
rspec-mocks/lib/rspec/mocks/mutate_const.rb,
rspec-mocks/lib/rspec/mocks/object_reference.rb,
rspec-mocks/lib/rspec/mocks/order_group.rb,
rspec-mocks/lib/rspec/mocks/proxy.rb,
rspec-mocks/lib/rspec/mocks/space.rb,
rspec-mocks/lib/rspec/mocks/syntax.rb,
rspec-mocks/lib/rspec/mocks/targets.rb,
rspec-mocks/lib/rspec/mocks/test_double.rb,
rspec-mocks/lib/rspec/mocks/verifying_double.rb,
rspec-mocks/lib/rspec/mocks/verifying_message_expectation.rb,
rspec-mocks/lib/rspec/mocks/verifying_proxy.rb,
rspec-mocks/lib/rspec/mocks/version.rb,
rspec-mocks/lib/rspec/mocks/any_instance/chain.rb,
rspec-mocks/lib/rspec/mocks/any_instance/error_generator.rb,
rspec-mocks/lib/rspec/mocks/any_instance/expect_chain_chain.rb,
rspec-mocks/lib/rspec/mocks/any_instance/expectation_chain.rb,
rspec-mocks/lib/rspec/mocks/any_instance/message_chains.rb,
rspec-mocks/lib/rspec/mocks/any_instance/proxy.rb,
rspec-mocks/lib/rspec/mocks/any_instance/recorder.rb,
rspec-mocks/lib/rspec/mocks/any_instance/stub_chain.rb,
rspec-mocks/lib/rspec/mocks/any_instance/stub_chain_chain.rb,
rspec-mocks/lib/rspec/mocks/matchers/expectation_customization.rb,
rspec-mocks/lib/rspec/mocks/matchers/have_received.rb,
rspec-mocks/lib/rspec/mocks/matchers/receive.rb,
rspec-mocks/lib/rspec/mocks/matchers/receive_message_chain.rb,
rspec-mocks/lib/rspec/mocks/matchers/receive_messages.rb,
rspec-rails/lib/rspec-rails.rb,
rspec-rails/lib/rspec/rails/active_record.rb,
rspec-rails/lib/rspec/rails/adapters.rb,
rspec-rails/lib/rspec/rails/configuration.rb,
rspec-rails/lib/rspec/rails/feature_check.rb,
rspec-rails/lib/rspec/rails/file_fixture_support.rb,
rspec-rails/lib/rspec/rails/fixture_file_upload_support.rb,
rspec-rails/lib/rspec/rails/fixture_support.rb,
rspec-rails/lib/rspec/rails/matchers.rb,
rspec-rails/lib/rspec/rails/version.rb,
rspec-rails/lib/rspec/rails/view_assigns.rb,
rspec-rails/lib/rspec/rails/view_path_builder.rb,
rspec-rails/lib/rspec/rails/view_rendering.rb,
rspec-rails/lib/rspec/rails/view_spec_methods.rb,
rspec-rails/lib/rspec/rails/example/channel_example_group.rb,
rspec-rails/lib/rspec/rails/example/channel_example_group.rb,
rspec-rails/lib/rspec/rails/example/controller_example_group.rb,
rspec-rails/lib/rspec/rails/example/feature_example_group.rb,
rspec-rails/lib/rspec/rails/example/helper_example_group.rb,
rspec-rails/lib/rspec/rails/example/job_example_group.rb,
rspec-rails/lib/rspec/rails/example/job_example_group.rb,
rspec-rails/lib/rspec/rails/example/mailbox_example_group.rb,
rspec-rails/lib/rspec/rails/example/mailer_example_group.rb,
rspec-rails/lib/rspec/rails/example/mailer_example_group.rb,
rspec-rails/lib/rspec/rails/example/model_example_group.rb,
rspec-rails/lib/rspec/rails/example/rails_example_group.rb,
rspec-rails/lib/rspec/rails/example/request_example_group.rb,
rspec-rails/lib/rspec/rails/example/routing_example_group.rb,
rspec-rails/lib/rspec/rails/example/system_example_group.rb,
rspec-rails/lib/rspec/rails/example/view_example_group.rb,
rspec-rails/lib/rspec/rails/matchers/action_cable.rb,
rspec-rails/lib/rspec/rails/matchers/action_mailbox.rb,
rspec-rails/lib/rspec/rails/matchers/active_job.rb,
rspec-rails/lib/rspec/rails/matchers/base_matcher.rb,
rspec-rails/lib/rspec/rails/matchers/be_a_new.rb,
rspec-rails/lib/rspec/rails/matchers/be_new_record.rb,
rspec-rails/lib/rspec/rails/matchers/be_valid.rb,
rspec-rails/lib/rspec/rails/matchers/have_enqueued_mail.rb,
rspec-rails/lib/rspec/rails/matchers/have_http_status.rb,
rspec-rails/lib/rspec/rails/matchers/have_rendered.rb,
rspec-rails/lib/rspec/rails/matchers/redirect_to.rb,
rspec-rails/lib/rspec/rails/matchers/routing_matchers.rb,
rspec-rails/lib/rspec/rails/matchers/send_email.rb,
rspec-rails/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb,
rspec-rails/lib/rspec/rails/matchers/action_cable/have_streams.rb,
rspec-support/lib/rspec/support.rb,
rspec-support/lib/rspec/support/caller_filter.rb,
rspec-support/lib/rspec/support/comparable_version.rb,
rspec-support/lib/rspec/support/differ.rb,
rspec-support/lib/rspec/support/directory_maker.rb,
rspec-support/lib/rspec/support/encoded_string.rb,
rspec-support/lib/rspec/support/fuzzy_matcher.rb,
rspec-support/lib/rspec/support/hunk_generator.rb,
rspec-support/lib/rspec/support/matcher_definition.rb,
rspec-support/lib/rspec/support/method_signature_verifier.rb,
rspec-support/lib/rspec/support/mutex.rb,
rspec-support/lib/rspec/support/object_formatter.rb,
rspec-support/lib/rspec/support/recursive_const_methods.rb,
rspec-support/lib/rspec/support/reentrant_mutex.rb,
rspec-support/lib/rspec/support/source.rb,
rspec-support/lib/rspec/support/spec.rb,
rspec-support/lib/rspec/support/version.rb,
rspec-support/lib/rspec/support/warnings.rb,
rspec-support/lib/rspec/support/with_keywords_when_needed.rb,
rspec-support/lib/rspec/support/source/location.rb,
rspec-support/lib/rspec/support/source/node.rb,
rspec-support/lib/rspec/support/source/token.rb,
rspec-support/lib/rspec/support/spec/diff_helpers.rb,
rspec-support/lib/rspec/support/spec/formatting_support.rb,
rspec-support/lib/rspec/support/spec/in_sub_process.rb,
rspec-support/lib/rspec/support/spec/library_wide_checks.rb,
rspec-support/lib/rspec/support/spec/shell_out.rb,
rspec-support/lib/rspec/support/spec/stderr_splitter.rb,
rspec-support/lib/rspec/support/spec/with_isolated_stderr.rb

Overview

The following code inspired and modified from Rails’ assert_response:

https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/testing/assertions/response.rb#L22-L38

Thank you to all the ::Rails devs who did the heavy lifting on this!

Constant Summary

Class Attribute Summary

Class Method Summary

  • .clear_examples

    Used to ensure examples get reloaded between multiple runs in the same process and ensures user configuration is persisted.

  • .configure {|Configuration| ... }

    Yields the global configuration to a block.

  • .const_missing(name) Internal use only Internal use only
  • .reset

    Used to ensure examples get reloaded and user configuration gets reset to defaults between multiple runs in the same process.

::RSpec::Support::Warnings - Extended

deprecate,
warn_deprecation

Used internally to print deprecation warnings when rspec-core isn’t loaded.

warn_with

Used internally to print longer warnings.

warning

Used internally to print warnings.

::RSpec::Core::Warnings - Extended

deprecate

Used internally to print deprecation warnings.

warn_deprecation

Used internally to print deprecation warnings.

warn_with

Class Attribute Details

.configuration (rw)

Returns the global [Configuration](RSpec/Core/Configuration) object. While you can use this method to access the configuration, the more common convention is to use [RSpec.configure](RSpec#configure-class_method).

Examples:

RSpec.configuration.drb_port = 1234

See Also:

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core.rb', line 85

def self.configuration
  @configuration ||= RSpec::Core::Configuration.new
end

.configuration=(value) (rw)

This method is for internal use only.

Setters for shared global objects

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core.rb', line 49

attr_writer :configuration, :world

.current_example (rw)

The example being executed.

The primary audience for this method is library authors who need access to the example currently being executed and also want to support all versions of RSpec 2 and 3.

Examples:

RSpec.configure do |c|
  # context.example is deprecated, but RSpec.current_example is not
  # available until RSpec 3.0.
  fetch_current_example = RSpec.respond_to?(:current_example) ?
    proc { RSpec.current_example } : proc { |context| context.example }

  c.before(:example) do
    example = fetch_current_example.call(self)

    # ...
  end
end
[ GitHub ]

  
# File 'rspec-core/lib/rspec/core.rb', line 122

def self.current_example
  RSpec::Support.thread_local_data[:current_example]
end

.current_example=(example) (rw)

This method is for internal use only.

Set the current example being executed.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core.rb', line 128

def self.current_example=(example)
  RSpec::Support.thread_local_data[:current_example] = example
end

.current_scopeSymbol (rw)

Get the current RSpec execution scope

Returns (in order of lifecycle):

* {:suite} as an initial value, this is outside of the test lifecycle.
* {:before_suite_hook} during `before(:suite)` hooks.
* {:before_context_hook} during `before(:context)` hooks.
* {:before_example_hook} during `before(:example)` hooks and `around(:example)` before {example.run}.
* {:example} within the example run.
* {:after_example_hook} during `after(:example)` hooks and `around(:example)` after {example.run}.
* {:after_context_hook} during `after(:context)` hooks.
* {:after_suite_hook} during `after(:suite)` hooks.
* {:suite} as a final value, again this is outside of the test lifecycle.

Reminder, :context hooks have :all alias and :example hooks have :each alias.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core.rb', line 154

def self.current_scope
  RSpec::Support.thread_local_data[:current_scope]
end

.current_scope=(scope) (rw)

This method is for internal use only.

Set the current scope rspec is executing in

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core.rb', line 134

def self.current_scope=(scope)
  RSpec::Support.thread_local_data[:current_scope] = scope
end

.world (rw)

This method is for internal use only.

Internal container for global non-configuration data.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core.rb', line 160

def self.world
  @world ||= RSpec::Core::World.new
end

.world=(value) (rw)

This method is for internal use only.

Setters for shared global objects

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core.rb', line 49

attr_writer :configuration, :world

Class Method Details

.clear_examples

Used to ensure examples get reloaded between multiple runs in the same process and ensures user configuration is persisted.

Users must invoke this if they want to clear all examples but preserve current configuration when they use the runner multiple times within the same process.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core.rb', line 70

def self.clear_examples
  world.reset
  configuration.reset_reporter
  configuration.start_time = ::RSpec::Core::Time.now
  configuration.reset_filters
end

.configure {|Configuration| ... }

Yields the global configuration to a block.

Examples:

RSpec.configure do |config|
  config.add_formatter 'documentation'
end

Yields:

  • (Configuration)

    global configuration

See Also:

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core.rb', line 97

def self.configure
  yield configuration if block_given?
end

.const_missing(name)

This method is for internal use only.
[ GitHub ]

  
# File 'rspec-core/lib/rspec/core.rb', line 194

def self.const_missing(name)
  # Load rspec-expectations when RSpec::Matchers is referenced. This allows
  # people to define custom matchers (using `RSpec::Matchers.define`) before
  # rspec-core has loaded rspec-expectations (since it delays the loading of
  # it to allow users to configure a different assertion/expectation
  # framework). `autoload` can't be used since it works with ruby's built-in
  # require (e.g. for files that are available relative to a load path dir),
  # but not with rubygems' extended require.
  #
  # As of rspec 2.14.1, we no longer require `rspec/mocks` and
  # `rspec/expectations` when `rspec` is required, so we want
  # to make them available as an autoload.
  require MODULES_TO_AUTOLOAD.fetch(name) { return super }
  ::RSpec.const_get(name)
end

.reset

Used to ensure examples get reloaded and user configuration gets reset to defaults between multiple runs in the same process.

Users must invoke this if they want to have the configuration reset when they use the runner multiple times within the same process. Users must deal themselves with re-configuration of RSpec before run.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core.rb', line 58

def self.reset
  RSpec::ExampleGroups.remove_all_constants
  @world = nil
  @configuration = nil
end