Module: RSpec::Support

### Home Classes Methods

### In Files

- lib/rspec/support.rb
- lib/rspec/support/differ.rb
- lib/rspec/support/directory_maker.rb
- lib/rspec/support/encoded_string.rb
- lib/rspec/support/fuzzy_matcher.rb
- lib/rspec/support/hunk_generator.rb
- lib/rspec/support/matcher_definition.rb
- lib/rspec/support/method_signature_verifier.rb
- lib/rspec/support/object_formatter.rb
- lib/rspec/support/recursive_const_methods.rb
- lib/rspec/support/ruby_features.rb
- lib/rspec/support/spec.rb
- lib/rspec/support/spec/formatting_support.rb
- lib/rspec/support/spec/in_sub_process.rb
- lib/rspec/support/spec/shell_out.rb
- lib/rspec/support/spec/stderr_splitter.rb
- lib/rspec/support/spec/with_isolated_stderr.rb
- lib/rspec/support/version.rb
- lib/rspec/support/version_checker.rb
- lib/rspec/support/warnings.rb

### Namespace

- MODULE RSpec::Support::FormattingSupport
- MODULE RSpec::Support::FuzzyMatcher
- MODULE RSpec::Support::InSubProcess
- MODULE RSpec::Support::OS
- MODULE RSpec::Support::ObjectFormatter
- MODULE RSpec::Support::RecursiveConstMethods
- MODULE RSpec::Support::Ruby
- MODULE RSpec::Support::RubyFeatures
- MODULE RSpec::Support::ShellOut
- MODULE RSpec::Support::Spec
- MODULE RSpec::Support::Version
- MODULE RSpec::Support::Warnings
- MODULE RSpec::Support::WithIsolatedStdErr
- CLASS RSpec::Support::BlockSignature
- CLASS RSpec::Support::Differ
- CLASS RSpec::Support::DirectoryMaker
- CLASS RSpec::Support::EncodedString
- CLASS RSpec::Support::HunkGenerator
- CLASS RSpec::Support::LooseSignatureVerifier
- CLASS RSpec::Support::MethodSignature
- CLASS RSpec::Support::MethodSignatureVerifier
- CLASS RSpec::Support::StdErrSplitter
- CLASS RSpec::Support::StrictSignatureVerifier
- CLASS RSpec::Support::VersionChecker

### Methods

- ::define_optimized_require_for_rspec
- ::deregister_matcher_definition
- ::failure_notifier
- ::failure_notifier=
- ::is_a_matcher?
- ::matcher_definitions
- ::method_handle_for
- ::notify_failure
- ::register_matcher_definition
- ::rspec_description_for_object
- ::thread_local_data
- ::with_failure_notifier

### Class/Module Index

Quicksearch

- RSpec
- RSpec::CallerFilter
- RSpec::Support
- RSpec::Support::BlockSignature
- RSpec::Support::Differ
- RSpec::Support::DirectoryMaker
- RSpec::Support::EncodedString
- RSpec::Support::FormattingSupport
- RSpec::Support::FuzzyMatcher
- RSpec::Support::HunkGenerator
- RSpec::Support::InSubProcess
- RSpec::Support::LooseSignatureVerifier
- RSpec::Support::LooseSignatureVerifier::SignatureWithKeywordArgumentsMatcher
- RSpec::Support::MethodSignature
- RSpec::Support::MethodSignatureVerifier
- RSpec::Support::OS
- RSpec::Support::ObjectFormatter
- RSpec::Support::RecursiveConstMethods
- RSpec::Support::Ruby
- RSpec::Support::RubyFeatures
- RSpec::Support::ShellOut
- RSpec::Support::Spec
- RSpec::Support::StdErrSplitter
- RSpec::Support::StrictSignatureVerifier
- RSpec::Support::Version
- RSpec::Support::VersionChecker
- RSpec::Support::Warnings
- RSpec::Support::WithIsolatedStdErr
- Object
- RSpecHelpers

No matching classes.

# RSpec::Support

### Constants

DEFAULT_FAILURE_NOTIFIER

  @private

KERNEL_METHOD_METHOD

  @api private

LibraryVersionTooLowError
StrictSignatureVerifier

  Figures out wether a given method can accept various arguments. Surprisingly non-trivial.

  @private

### Public Class Methods

define_optimized_require_for_rspec(lib, &require_relative) click to toggle source

@api private

Defines a helper method that is optimized to require files from the named lib. The passed block MUST be `{ |f| require_relative f }` because for `require_relative` to work properly from within the named lib the line of code must be IN that lib.

`require_relative` is preferred when available because it is always O(1), regardless of the number of dirs in $LOAD_PATH. `require`, on the other hand, does a linear O(N) search over the dirs in the $LOAD_PATH until it can resolve the file relative to one of the dirs.

    # File lib/rspec/support.rb, line 14
    def self.define_optimized_require_for_rspec(lib, &require_relative)
      name = "require_rspec_#{lib}"

      if Kernel.respond_to?(:require_relative)
        (class << self; self; end).__send__(:define_method, name) do |f|
          require_relative.call("#{lib}/#{f}")
        end
      else
        (class << self; self; end).__send__(:define_method, name) do |f|
          require "rspec/#{lib}/#{f}"
        end
      end
    end

deregister_matcher_definition(&block) click to toggle source

Remove a previously registered matcher. Useful for cleaning up after yourself in specs.

@private

    # File lib/rspec/support/matcher_definition.rb, line 22
    def self.deregister_matcher_definition(&block)
      matcher_definitions.delete(block)
    end

failure_notifier() click to toggle source

    # File lib/rspec/support.rb, line 88
    def self.failure_notifier
      thread_local_data[:failure_notifier] || DEFAULT_FAILURE_NOTIFIER
    end

failure_notifier=(callable) click to toggle source

    # File lib/rspec/support.rb, line 81
    def self.failure_notifier=(callable)
      thread_local_data[:failure_notifier] = callable
    end

is_a_matcher?(object) click to toggle source

@private

    # File lib/rspec/support/matcher_definition.rb, line 27
    def self.is_a_matcher?(object)
      matcher_definitions.any? { |md| md.call(object) }
    end

matcher_definitions() click to toggle source

@private

    # File lib/rspec/support/matcher_definition.rb, line 4
    def self.matcher_definitions
      @matcher_definitions ||= []
    end

method_handle_for(object, method_name) click to toggle source

    # File lib/rspec/support.rb, line 47
    def self.method_handle_for(object, method_name)
      KERNEL_METHOD_METHOD.bind(object).call(method_name)
    rescue NameError => original
      begin
        handle = object.method(method_name)
        raise original unless handle.is_a? Method
        handle
      rescue Exception
        raise original
      end
    end

notify_failure(failure, options={}) click to toggle source

    # File lib/rspec/support.rb, line 92
    def self.notify_failure(failure, options={})
      failure_notifier.call(failure, options)
    end

register_matcher_definition(&block) click to toggle source

Used internally to break cyclic dependency between mocks, expectations, and support. We don't currently have a consistent implementation of our matchers, though we are considering changing that: github.com/rspec/rspec-mocks/issues/513

@private

    # File lib/rspec/support/matcher_definition.rb, line 14
    def self.register_matcher_definition(&block)
      matcher_definitions << block
    end

rspec_description_for_object(object) click to toggle source

@api private

gives a string representation of an object for use in RSpec descriptions

    # File lib/rspec/support/matcher_definition.rb, line 34
    def self.rspec_description_for_object(object)
      if RSpec::Support.is_a_matcher?(object) && object.respond_to?(:description)
        object.description
      else
        object
      end
    end

thread_local_data() click to toggle source

A single thread local variable so we don't excessively pollute that namespace.

    # File lib/rspec/support.rb, line 77
    def self.thread_local_data
      Thread.current[:__rspec] ||= {}
    end

with_failure_notifier(callable) click to toggle source

    # File lib/rspec/support.rb, line 96
    def self.with_failure_notifier(callable)
      orig_notifier = failure_notifier
      self.failure_notifier = callable
      yield
    ensure
      self.failure_notifier = orig_notifier
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.