Module: RSpec

Defined in:
lib/rspec/core/backport_random.rb,
lib/rspec/core.rb,
lib/rspec/core/dsl.rb,
lib/rspec/core/drb.rb,
lib/rspec/core/world.rb,
lib/rspec/core/hooks.rb,
lib/rspec/core/runner.rb,
lib/rspec/core/version.rb,
lib/rspec/core/example.rb,
lib/rspec/core/pending.rb,
lib/rspec/core/warnings.rb,
lib/rspec/core/flat_map.rb,
lib/rspec/core/ordering.rb,
lib/rspec/core/metadata.rb,
lib/rspec/core/rake_task.rb,
lib/rspec/core/ruby_project.rb,
lib/rspec/core/example_group.rb,
lib/rspec/core/configuration.rb,
lib/rspec/core/shared_context.rb,
lib/rspec/core/filter_manager.rb,
lib/rspec/core/metadata_filter.rb,
lib/rspec/core/memoized_helpers.rb,
lib/rspec/core/formatters/helpers.rb,
lib/rspec/core/project_initializer.rb,
lib/rspec/core/backtrace_formatter.rb,
lib/rspec/core/mocking_adapters/rr.rb,
lib/rspec/core/shared_example_group.rb,
lib/rspec/core/configuration_options.rb,
lib/rspec/core/mocking_adapters/null.rb,
lib/rspec/core/mocking_adapters/rspec.rb,
lib/rspec/core/mocking_adapters/mocha.rb,
lib/rspec/core/formatters/html_printer.rb,
lib/rspec/core/formatters/console_codes.rb,
lib/rspec/core/stdlib_assertions_adapter.rb,
lib/rspec/core/formatters/json_formatter.rb,
lib/rspec/core/mocking_adapters/flexmock.rb,
lib/rspec/core/formatters/base_formatter.rb,
lib/rspec/core/formatters/html_formatter.rb,
lib/rspec/core/formatters/legacy_formatter.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/formatters/deprecation_formatter.rb,
lib/rspec/core/formatters/documentation_formatter.rb

Overview

This code was (mostly) ported from the backports gem found at https://github.com/marcandre/backports which is subject to this license:

Copyright (c) 2009 Marc-Andre Lafortune

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

The goal is to provide a random number generator in Ruby versions that do not have one. This was added to support localization of random spec ordering.

These were in multiple files in backports, but merged into one here.

Defined Under Namespace

Modules: Core

Constant Summary

Class Method Summary (collapse)

Class Method Details

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



60
61
62
63
64
65
66
67
# File 'lib/rspec/core.rb', line 60

def self.configuration
  @configuration ||= begin
                       config = RSpec::Core::Configuration.new
                       config.expose_dsl_globally = true
                       config
                     end

end

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



77
78
79
# File 'lib/rspec/core.rb', line 77

def self.configure
  yield configuration if block_given?
end

+ (void) 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(:example) do
    example = fetch_current_example.call(self)

    # ...
  end
end


102
103
104
# File 'lib/rspec/core.rb', line 102

def self.current_example
  [:current_example]
end

+ (void) 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.



108
109
110
# File 'lib/rspec/core.rb', line 108

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

+ (void) reset

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

Users must invoke this if they want to have the configuration reset when they use runner multiple times within the same process.



47
48
49
50
# File 'lib/rspec/core.rb', line 47

def self.reset
  @world = nil
  @configuration = nil
end