Parent

Class Index [+]

Quicksearch

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
117:       def initialize
118:         @exclusions = DEFAULT_EXCLUSIONS.dup.extend(Describable)
119:         @inclusions = {}.extend(Describable)
120:         extend(BackwardCompatibility)
121:       end

Public Instance Methods

add_location(file_path, line_numbers) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 123
123:       def add_location(file_path, line_numbers)
124:         # locations is a hash of expanded paths to arrays of line
125:         # numbers to match against. e.g.
126:         #   { "path/to/file.rb" => [37, 42] }
127:         locations = @inclusions.delete(:locations) || Hash.new {|h,k| h[k] = []}
128:         locations[File.expand_path(file_path)].push(*line_numbers)
129:         @inclusions.replace(:locations => locations)
130:         @exclusions.clear
131:       end
empty?() click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 133
133:       def empty?
134:         inclusions.empty? && exclusions.empty_without_conditional_filters?
135:       end
exclude(*args) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 141
141:       def exclude(*args)
142:         merge(@exclusions, @inclusions, *args)
143:       end
exclude!(*args) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 145
145:       def exclude!(*args)
146:         replace(@exclusions, @inclusions, *args)
147:       end
exclude?(example) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 153
153:       def exclude?(example)
154:         @exclusions.empty? ? false : example.any_apply?(@exclusions)
155:       end
exclude_with_low_priority(*args) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 149
149:       def exclude_with_low_priority(*args)
150:         reverse_merge(@exclusions, @inclusions, *args)
151:       end
include(*args) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 157
157:       def include(*args)
158:         unless_standalone(*args) { merge(@inclusions, @exclusions, *args) }
159:       end
include!(*args) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 161
161:       def include!(*args)
162:         unless_standalone(*args) { replace(@inclusions, @exclusions, *args) }
163:       end
include?(example) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 169
169:       def include?(example)
170:         @inclusions.empty? ? true : example.any_apply?(@inclusions)
171:       end
include_with_low_priority(*args) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 165
165:       def include_with_low_priority(*args)
166:         unless_standalone(*args) { reverse_merge(@inclusions, @exclusions, *args) }
167:       end
prune(examples) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 137
137:       def prune(examples)
138:         examples.select {|e| !exclude?(e) && include?(e)}
139:       end

Private Instance Methods

already_set_standalone_filter?() click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 194
194:       def already_set_standalone_filter?
195:         is_standalone_filter?(inclusions)
196:       end
is_standalone_filter?(filter) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 198
198:       def is_standalone_filter?(filter)
199:         STANDALONE_FILTERS.any? {|key| filter.has_key?(key)}
200:       end
merge(orig, opposite, *updates) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 179
179:       def merge(orig, opposite, *updates)
180:         orig.merge!(updates.last).each_key {|k| opposite.delete(k)}
181:       end
replace(orig, opposite, *updates) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 183
183:       def replace(orig, opposite, *updates)
184:         updates.last.each_key {|k| opposite.delete(k)}
185:         orig.replace(updates.last)
186:       end
reverse_merge(orig, opposite, *updates) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 188
188:       def reverse_merge(orig, opposite, *updates)
189:         updated = updates.last.merge(orig)
190:         opposite.each_pair {|k,v| updated.delete(k) if updated[k] == v}
191:         orig.replace(updated)
192:       end
unless_standalone(*args) click to toggle source
     # File lib/rspec/core/filter_manager.rb, line 175
175:       def unless_standalone(*args)
176:         is_standalone_filter?(args.last) ? @inclusions.replace(args.last) : yield unless already_set_standalone_filter?
177:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.