Module: RSpec

Extended by:
Core::Deprecation
Defined in:
lib/rspec/core.rb,
lib/rspec/core/dsl.rb,
lib/rspec/core/hooks.rb,
lib/rspec/core/world.rb,
lib/rspec/core/runner.rb,
lib/rspec/core/pending.rb,
lib/rspec/core/example.rb,
lib/rspec/core/version.rb,
lib/rspec/core/metadata.rb,
lib/rspec/core/rake_task.rb,
lib/rspec/core/deprecation.rb,
lib/rspec/core/command_line.rb,
lib/rspec/core/ruby_project.rb,
lib/rspec/core/configuration.rb,
lib/rspec/core/example_group.rb,
lib/rspec/core/caller_filter.rb,
lib/rspec/core/shared_context.rb,
lib/rspec/core/filter_manager.rb,
lib/rspec/core/mocking/with_rr.rb,
lib/rspec/core/drb_command_line.rb,
lib/rspec/core/memoized_helpers.rb,
lib/rspec/core/backtrace_cleaner.rb,
lib/rspec/core/mocking/with_rspec.rb,
lib/rspec/core/extensions/ordered.rb,
lib/rspec/core/formatters/helpers.rb,
lib/rspec/core/mocking/with_mocha.rb,
lib/rspec/core/project_initializer.rb,
lib/rspec/core/shared_example_group.rb,
lib/rspec/core/configuration_options.rb,
lib/rspec/core/metadata_hash_builder.rb,
lib/rspec/core/mocking/with_flexmock.rb,
lib/rspec/core/backward_compatibility.rb,
lib/rspec/core/formatters/html_printer.rb,
lib/rspec/core/formatters/console_codes.rb,
lib/rspec/core/formatters/base_formatter.rb,
lib/rspec/core/formatters/html_formatter.rb,
lib/rspec/core/formatters/json_formatter.rb,
lib/rspec/core/minitest_assertions_adapter.rb,
lib/rspec/core/test_unit_assertions_adapter.rb,
lib/rspec/core/formatters/snippet_extractor.rb,
lib/rspec/core/formatters/progress_formatter.rb,
lib/rspec/core/formatters/base_text_formatter.rb,
lib/rspec/core/deprecated_mutable_array_proxy.rb,
lib/rspec/core/formatters/text_mate_formatter.rb,
lib/rspec/core/shared_example_group/collection.rb,
lib/rspec/core/mocking/with_absolutely_nothing.rb,
lib/rspec/core/extensions/module_eval_with_args.rb,
lib/rspec/core/formatters/deprecation_formatter.rb,
lib/rspec/core/formatters/documentation_formatter.rb,
lib/rspec/core/extensions/instance_eval_with_args.rb

Defined Under Namespace

Modules: Core, Runner Classes: CallerFilter

Constant Summary

MODULES_TO_AUTOLOAD =
{
  :Matchers     => "rspec/expectations",
  :Expectations => "rspec/expectations",
  :Mocks        => "rspec/mocks"
}
SharedContext =
Core::SharedContext

Class Method Summary (collapse)

Class Method Details

+ (Object) configuration

Returns the global Configuration object. While you can use this method to access the configuration, the more common convention is to use RSpec.configure.

Examples:

RSpec.configuration.drb_port = 1234

See Also:

121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/rspec/core.rb', line 121
def self.configuration
  if block_given?
    RSpec.warn_deprecation <<-WARNING

*****************************************************************
DEPRECATION WARNING
* RSpec.configuration with a block is deprecated and has no effect.
* please use RSpec.configure with a block instead.
Called from #{CallerFilter.first_non_rspec_line}
*****************************************************************
WARNING
  end
  @configuration ||= RSpec::Core::Configuration.new
end

+ (Object) 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:

153
154
155
# File 'lib/rspec/core.rb', line 153
def self.configure
  yield configuration if block_given?
end

+ (Object) const_missing(name)

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/rspec/core.rb', line 223
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. For more info, see:
  require MODULES_TO_AUTOLOAD.fetch(name) { return super }
  ::RSpec.const_get(name)
end

+ (Object) current_example

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(:each) do
    example = fetch_current_example.call(self)
    # ...
  end
end
184
185
186
# File 'lib/rspec/core.rb', line 184
def self.current_example
  Thread.current[:_rspec_current_example]
end

+ (Object) current_example=(example)

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.

Set the current example being executed.

190
191
192
# File 'lib/rspec/core.rb', line 190
def self.current_example=(example)
  Thread.current[:_rspec_current_example] = example
end

+ (Object) reset

Used internally to ensure examples get reloaded between multiple runs in the same process.

100
101
102
103
# File 'lib/rspec/core.rb', line 100
def self.reset
  RSpec.resets_required -= 1
  internal_reset
end