Class: RSpec::Core::FilterManager

### Home Classes Methods

### In Files

- lib/rspec/core/filter_manager.rb

### Parent

Object

### Namespace

- MODULE RSpec::Core::FilterManager::BackwardCompatibility
- MODULE RSpec::Core::FilterManager::Describable

### Methods

- ::new
- #add_location
- #empty?
- #exclude
- #exclude!
- #exclude?
- #exclude_with_low_priority
- #include
- #include!
- #include?
- #include_with_low_priority
- #prune

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Core
- RSpec::Core::BacktraceCleaner
- RSpec::Core::BacktraceFormatter
- RSpec::Core::CommandLine
- RSpec::Core::Configuration
- RSpec::Core::Configuration::MustBeConfiguredBeforeExampleGroupsError
- RSpec::Core::ConfigurationOptions
- RSpec::Core::ConstMissing
- RSpec::Core::DRbCommandLine
- RSpec::Core::DSL
- RSpec::Core::Deprecation
- RSpec::Core::DrbOptions
- RSpec::Core::Example
- RSpec::Core::Example::NotPendingExampleFixed
- RSpec::Core::Example::Procsy
- RSpec::Core::ExampleGroup
- RSpec::Core::Extensions
- RSpec::Core::Extensions::InstanceEvalWithArgs
- RSpec::Core::Extensions::ModuleEvalWithArgs
- RSpec::Core::Extensions::Ordered
- RSpec::Core::Extensions::Ordered::ExampleGroups
- RSpec::Core::Extensions::Ordered::Examples
- RSpec::Core::FilterManager
- RSpec::Core::FilterManager::BackwardCompatibility
- RSpec::Core::FilterManager::Describable
- RSpec::Core::Formatters
- RSpec::Core::Formatters::BaseFormatter
- RSpec::Core::Formatters::BaseTextFormatter
- RSpec::Core::Formatters::DeprecationFormatter
- RSpec::Core::Formatters::DocumentationFormatter
- RSpec::Core::Formatters::Helpers
- RSpec::Core::Formatters::HtmlFormatter
- RSpec::Core::Formatters::HtmlPrinter
- RSpec::Core::Formatters::JsonFormatter
- RSpec::Core::Formatters::ProgressFormatter
- RSpec::Core::Formatters::SnippetExtractor
- RSpec::Core::Formatters::SnippetExtractor::NullConverter
- RSpec::Core::Formatters::TextMateFormatter
- RSpec::Core::Hooks
- RSpec::Core::Hooks::AfterAllHook
- RSpec::Core::Hooks::AfterHook
- RSpec::Core::Hooks::AroundHook
- RSpec::Core::Hooks::AroundHookCollection
- RSpec::Core::Hooks::BeforeHook
- RSpec::Core::Hooks::GroupHookCollection
- RSpec::Core::Hooks::Hook
- RSpec::Core::Hooks::HookCollection
- RSpec::Core::Hooks::HookCollectionAliases
- RSpec::Core::Hooks::RegistersGlobals
- RSpec::Core::MemoizedHelpers
- RSpec::Core::MemoizedHelpers::BeforeAllMemoizedHash
- RSpec::Core::MemoizedHelpers::ClassMethods
- RSpec::Core::Metadata
- RSpec::Core::Metadata::ExampleMetadataHash
- RSpec::Core::Metadata::GroupMetadataHash
- RSpec::Core::Metadata::MetadataHash
- RSpec::Core::MetadataHashBuilder
- RSpec::Core::MetadataHashBuilder::Common
- RSpec::Core::MetadataHashBuilder::WithConfigWarning
- RSpec::Core::MetadataHashBuilder::WithDeprecationWarning
- RSpec::Core::MockFrameworkAdapter
- RSpec::Core::Parser
- RSpec::Core::Pending
- RSpec::Core::Pending::PendingDeclaredInExample
- RSpec::Core::Pending::PendingExampleFixedError
- RSpec::Core::ProjectInitializer
- RSpec::Core::RakeTask
- RSpec::Core::Reporter
- RSpec::Core::RubyProject
- RSpec::Core::Runner
- RSpec::Core::SharedContext
- RSpec::Core::SharedExampleGroup
- RSpec::Core::SharedExampleGroup::Collection
- RSpec::Core::SharedExampleGroup::Registry
- RSpec::Core::SharedExampleGroup::TopLevelDSL
- RSpec::Core::Time
- RSpec::Core::Version
- RSpec::Core::World
- RSpec::Rake
- RSpec::Runner
- Autotest
- Autotest::Rspec2
- Kernel

No matching classes.

# RSpec::Core::FilterManager

Manages the filtering of examples and groups by matching tags declared on the command line or options files, or filters declared via `RSpec.configure`, with hash key/values submitted within example group and/or example declarations. For example, given this declaration:

    describe Thing, :awesome => true do
      it "does something" do
        # ...
      end
    end

That group (or any other with `:awesome => true`) would be filtered in with any of the following commands:

    rspec --tag awesome:true
    rspec --tag awesome
    rspec -t awesome:true
    rspec -t awesome

Prefixing the tag names with `~` negates the tags, thus excluding this group with any of:

    rspec --tag ~awesome:true
    rspec --tag ~awesome
    rspec -t ~awesome:true
    rspec -t ~awesome

## Options files and command line overrides

Tag declarations can be stored in `.rspec`, `~/.rspec`, or a custom options file. This is useful for storing defaults. For example, let's say you've got some slow specs that you want to suppress most of the time. You can tag them like this:

    describe Something, :slow => true do

And then store this in `.rspec`:

    --tag ~slow:true

Now when you run `rspec`, that group will be excluded.

## Overriding

Of course, you probably want to run them sometimes, so you can override this tag on the command line like this:

    rspec --tag slow:true

## RSpec.configure

You can also store default tags with `RSpec.configure`. We use `tag` on the command line (and in options files like `.rspec`), but for historical reasons we use the term `filter` in `RSpec.configure:

    RSpec.configure do |c|
      c.filter_run_including :foo => :bar
      c.filter_run_excluding :foo => :bar
    end

These declarations can also be overridden from the command line.

@see RSpec.configure @see Configuration#filter_run_including @see Configuration#filter_run_excluding

### Constants

DEFAULT_EXCLUSIONS
STANDALONE_FILTERS

### Attributes

exclusions[R]
inclusions[R]

### Public Class Methods

new() click to toggle source

    # File lib/rspec/core/filter_manager.rb, line 117
    def initialize
      @exclusions = DEFAULT_EXCLUSIONS.dup.extend(Describable)
      @inclusions = {}.extend(Describable)
      extend(BackwardCompatibility)
    end

### Public Instance Methods

add_location(file_path, line_numbers) click to toggle source

    # File lib/rspec/core/filter_manager.rb, line 123
    def add_location(file_path, line_numbers)
      # locations is a hash of expanded paths to arrays of line
      # numbers to match against. e.g.
      #   { "path/to/file.rb" => [37, 42] }
      locations = @inclusions.delete(:locations) || Hash.new {|h,k| h[k] = []}
      locations[File.expand_path(file_path)].push(*line_numbers)
      @inclusions.replace(:locations => locations)
      @exclusions.clear
    end

empty?() click to toggle source

    # File lib/rspec/core/filter_manager.rb, line 133
    def empty?
      inclusions.empty? && exclusions.empty_without_conditional_filters?
    end

exclude(*args) click to toggle source

    # File lib/rspec/core/filter_manager.rb, line 141
    def exclude(*args)
      merge(@exclusions, @inclusions, *args)
    end

exclude!(*args) click to toggle source

    # File lib/rspec/core/filter_manager.rb, line 145
    def exclude!(*args)
      replace(@exclusions, @inclusions, *args)
    end

exclude?(example) click to toggle source

    # File lib/rspec/core/filter_manager.rb, line 153
    def exclude?(example)
      @exclusions.empty? ? false : example.any_apply?(@exclusions)
    end

exclude_with_low_priority(*args) click to toggle source

    # File lib/rspec/core/filter_manager.rb, line 149
    def exclude_with_low_priority(*args)
      reverse_merge(@exclusions, @inclusions, *args)
    end

include(*args) click to toggle source

    # File lib/rspec/core/filter_manager.rb, line 157
    def include(*args)
      unless_standalone(*args) { merge(@inclusions, @exclusions, *args) }
    end

include!(*args) click to toggle source

    # File lib/rspec/core/filter_manager.rb, line 161
    def include!(*args)
      unless_standalone(*args) { replace(@inclusions, @exclusions, *args) }
    end

include?(example) click to toggle source

    # File lib/rspec/core/filter_manager.rb, line 169
    def include?(example)
      @inclusions.empty? ? true : example.any_apply?(@inclusions)
    end

include_with_low_priority(*args) click to toggle source

    # File lib/rspec/core/filter_manager.rb, line 165
    def include_with_low_priority(*args)
      unless_standalone(*args) { reverse_merge(@inclusions, @exclusions, *args) }
    end

prune(examples) click to toggle source

    # File lib/rspec/core/filter_manager.rb, line 137
    def prune(examples)
      examples.select {|e| !exclude?(e) && include?(e)}
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.