module RSpec
Namespace for all core RSpec code.
This is borrowed (slightly modified) from Scott Taylor's project_path project:
http://github.com/smtlaissezfaire/project_path
Constants
- MODULES_TO_AUTOLOAD
@private
@private
Attributes
Setters for shared global objects @api private
Setters for shared global objects @api private
Public Class Methods
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.
# File lib/rspec/core.rb, line 69 def self.clear_examples world.reset configuration.reporter.reset configuration.start_time = ::RSpec::Core::Time.now configuration.reset_filters end
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).
@example
RSpec.configuration.drb_port = 1234
@see ::configure @see Core::Configuration
# File lib/rspec/core.rb, line 84 def self.configuration @configuration ||= begin config = RSpec::Core::Configuration.new config.expose_dsl_globally = true config end end
Yields the global configuration to a block. @yield [Configuration] global configuration
@example
RSpec.configure do |config| config.add_formatter 'documentation' end
@see Core::Configuration
# File lib/rspec/core.rb, line 100 def self.configure yield configuration if block_given? end
@private
# File lib/rspec/core.rb, line 174 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
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.
@example
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
# File lib/rspec/core.rb, line 125 def self.current_example thread_local_metadata[:current_example] end
Set the current example being executed. @api private
# File lib/rspec/core.rb, line 131 def self.current_example=(example) thread_local_metadata[:current_example] = example end
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.
# File lib/rspec/core.rb, line 58 def self.reset @world = nil @configuration = nil end
@private A single thread local variable so we don't excessively pollute that namespace.
# File lib/rspec/core.rb, line 138 def self.thread_local_metadata Thread.current[:_rspec] ||= { :shared_example_group_inclusions => [] } end
@private Internal container for global non-configuration data.
# File lib/rspec/core.rb, line 144 def self.world @world ||= RSpec::Core::World.new end