Module: RSpec::Core::DSL

### Home Classes Methods

### In Files

- lib/rspec/core/dsl.rb

### Namespace

- MODULE RSpec::Core::DSL::RSpec

### Methods

- ::change_global_dsl
- ::example_group_aliases
- ::expose_example_group_alias
- ::expose_example_group_alias_globally
- ::expose_globally!
- ::exposed_globally?
- ::remove_globally!

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Core
- RSpec::Core::AnonymousExampleGroup
- RSpec::Core::Backports
- RSpec::Core::Backports::Random
- RSpec::Core::Backports::Random::Implementation
- RSpec::Core::Backports::Random::MT19937
- RSpec::Core::BacktraceFormatter
- RSpec::Core::Configuration
- RSpec::Core::Configuration::DeprecationReporterBuffer
- RSpec::Core::Configuration::ExposeCurrentExample
- RSpec::Core::Configuration::MustBeConfiguredBeforeExampleGroupsError
- RSpec::Core::ConfigurationOptions
- RSpec::Core::DRbOptions
- RSpec::Core::DRbRunner
- RSpec::Core::DSL
- RSpec::Core::DSL::RSpec
- RSpec::Core::Example
- RSpec::Core::Example::ExecutionResult
- RSpec::Core::Example::Procsy
- RSpec::Core::ExampleGroup
- RSpec::Core::ExclusionRules
- RSpec::Core::FilterManager
- RSpec::Core::FilterRules
- RSpec::Core::FilterableItemRepository
- RSpec::Core::FilterableItemRepository::QueryOptimized
- RSpec::Core::FilterableItemRepository::UpdateOptimized
- RSpec::Core::FlatMap
- RSpec::Core::Formatters
- RSpec::Core::Formatters::BaseFormatter
- RSpec::Core::Formatters::BaseTextFormatter
- RSpec::Core::Formatters::ConsoleCodes
- RSpec::Core::Formatters::DeprecationFormatter
- RSpec::Core::Formatters::DeprecationFormatter::DelayedPrinter
- RSpec::Core::Formatters::DeprecationFormatter::FileStream
- RSpec::Core::Formatters::DeprecationFormatter::ImmediatePrinter
- RSpec::Core::Formatters::DeprecationFormatter::RaiseErrorStream
- RSpec::Core::Formatters::DocumentationFormatter
- RSpec::Core::Formatters::Helpers
- RSpec::Core::Formatters::HtmlFormatter
- RSpec::Core::Formatters::HtmlPrinter
- RSpec::Core::Formatters::JsonFormatter
- RSpec::Core::Formatters::Loader
- RSpec::Core::Formatters::ProfileFormatter
- RSpec::Core::Formatters::ProgressFormatter
- RSpec::Core::Formatters::Protocol
- RSpec::Core::Formatters::SnippetExtractor
- RSpec::Core::Formatters::SnippetExtractor::CoderayConverter
- RSpec::Core::Formatters::SnippetExtractor::NullConverter
- RSpec::Core::HashImitatable
- RSpec::Core::HashImitatable::ClassMethods
- RSpec::Core::Hooks
- RSpec::Core::Hooks::AfterContextHook
- RSpec::Core::Hooks::AfterHook
- RSpec::Core::Hooks::AroundHook
- RSpec::Core::Hooks::BeforeHook
- RSpec::Core::Hooks::Hook
- RSpec::Core::Hooks::HookCollections
- RSpec::Core::InclusionRules
- RSpec::Core::LegacyExampleGroupHash
- RSpec::Core::MemoizedHelpers
- RSpec::Core::MemoizedHelpers::ClassMethods
- RSpec::Core::MemoizedHelpers::ContextHookMemoizedHash
- RSpec::Core::MemoizedHelpers::ContextHookMemoizedHash::After
- RSpec::Core::MemoizedHelpers::ContextHookMemoizedHash::Before
- RSpec::Core::Metadata
- RSpec::Core::Metadata::ExampleGroupHash
- RSpec::Core::Metadata::ExampleHash
- RSpec::Core::Metadata::HashPopulator
- RSpec::Core::MetadataFilter
- RSpec::Core::MinitestAssertionsAdapter
- RSpec::Core::MockingAdapters
- RSpec::Core::MockingAdapters::Flexmock
- RSpec::Core::MockingAdapters::Mocha
- RSpec::Core::MockingAdapters::Null
- RSpec::Core::MockingAdapters::RR
- RSpec::Core::MockingAdapters::RSpec
- RSpec::Core::Notifications
- RSpec::Core::Notifications::DeprecationNotification
- RSpec::Core::Notifications::ExampleNotification
- RSpec::Core::Notifications::ExamplesNotification
- RSpec::Core::Notifications::FailedExampleNotification
- RSpec::Core::Notifications::NullColorizer
- RSpec::Core::Notifications::NullNotification
- RSpec::Core::Notifications::PendingExampleFailedAsExpectedNotification
- RSpec::Core::Notifications::PendingExampleFixedNotification
- RSpec::Core::Notifications::PendingExampleNotificationMethods
- RSpec::Core::Notifications::ProfileNotification
- RSpec::Core::Notifications::SeedNotification
- RSpec::Core::Notifications::SkippedExampleNotification
- RSpec::Core::Notifications::SummaryNotification
- RSpec::Core::NullReporter
- RSpec::Core::Ordering
- RSpec::Core::Ordering::ConfigurationManager
- RSpec::Core::Ordering::Custom
- RSpec::Core::Ordering::Identity
- RSpec::Core::Ordering::Random
- RSpec::Core::Ordering::Registry
- RSpec::Core::Parser
- RSpec::Core::Pending
- RSpec::Core::Pending::PendingExampleFixedError
- RSpec::Core::Pending::SkipDeclaredInExample
- RSpec::Core::ProjectInitializer
- RSpec::Core::RakeTask
- RSpec::Core::RandomNumberGenerator
- RSpec::Core::Reporter
- RSpec::Core::RubyProject
- RSpec::Core::Runner
- RSpec::Core::Sandbox
- RSpec::Core::SharedContext
- RSpec::Core::SharedExampleGroup
- RSpec::Core::SharedExampleGroup::Registry
- RSpec::Core::SharedExampleGroup::TopLevelDSL
- RSpec::Core::SharedExampleGroupInclusionStackFrame
- RSpec::Core::SharedExampleGroupModule
- RSpec::Core::SuiteHookContext
- RSpec::Core::TestUnitAssertionsAdapter
- RSpec::Core::Time
- RSpec::Core::Version
- RSpec::Core::Warnings
- RSpec::Core::World
- RSpec::ExampleGroups
- Object

No matching classes.

# RSpec::Core::DSL

DSL defines methods to group examples, most notably `describe`, and exposes them as class methods of {RSpec}. They can also be exposed globally (on `main` and instances of `Module`) through the {Configuration} option `expose_dsl_globally`.

By default the methods `describe`, `context` and `example_group` are exposed. These methods define a named context for one or more examples. The given block is evaluated in the context of a generated subclass of {RSpec::Core::ExampleGroup}.

## Examples:

    RSpec.describe "something" do
      context "when something is a certain way" do
        it "does something" do
          # example code goes here
        end
      end
    end

@see ExampleGroup @see ExampleGroup.example_group

### Attributes

top_level[RW]

@private

### Public Class Methods

change_global_dsl(&changes) click to toggle source

@private

    # File lib/rspec/core/dsl.rb, line 87
    def self.change_global_dsl(&changes)
      (class << top_level; self; end).class_exec(&changes)
      Module.class_exec(&changes)
    end

example_group_aliases() click to toggle source

@private

    # File lib/rspec/core/dsl.rb, line 27
    def self.example_group_aliases
      @example_group_aliases ||= []
    end

expose_example_group_alias(name) click to toggle source

@private

    # File lib/rspec/core/dsl.rb, line 37
    def self.expose_example_group_alias(name)
      return if example_group_aliases.include?(name)

      example_group_aliases << name

      (class << RSpec; self; end).__send__(:define_method, name) do |*args, &example_group_block|
        RSpec.world.register RSpec::Core::ExampleGroup.__send__(name, *args, &example_group_block)
      end

      expose_example_group_alias_globally(name) if exposed_globally?
    end

expose_example_group_alias_globally(method_name) click to toggle source

@private

    # File lib/rspec/core/dsl.rb, line 79
    def self.expose_example_group_alias_globally(method_name)
      change_global_dsl do
        remove_method(method_name) if method_defined?(method_name)
        define_method(method_name) { |*a, &b| ::RSpec.__send__(method_name, *a, &b) }
      end
    end

expose_globally!() click to toggle source

Adds the describe method to Module and the top level binding. @api private

    # File lib/rspec/core/dsl.rb, line 56
    def self.expose_globally!
      return if exposed_globally?

      example_group_aliases.each do |method_name|
        expose_example_group_alias_globally(method_name)
      end

      @exposed_globally = true
    end

exposed_globally?() click to toggle source

@private

    # File lib/rspec/core/dsl.rb, line 32
    def self.exposed_globally?
      @exposed_globally ||= false
    end

remove_globally!() click to toggle source

Removes the describe method from Module and the top level binding. @api private

    # File lib/rspec/core/dsl.rb, line 68
    def self.remove_globally!
      return unless exposed_globally?

      example_group_aliases.each do |method_name|
        change_global_dsl { undef_method method_name }
      end

      @exposed_globally = false
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.