Class: RSpec::Core::FilterRules

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/core/filter_manager.rb

Direct Known Subclasses

InclusionRules

Constant Summary collapse

PROC_HEX_NUMBER =
/0x[0-9a-f]+@/
PROJECT_DIR =
File.expand_path('.')

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules = {}) ⇒ FilterRules

Returns a new instance of FilterRules



130
131
132
# File 'lib/rspec/core/filter_manager.rb', line 130

def initialize(rules={})
  @rules = rules
end

Instance Attribute Details

#oppositeObject

Returns the value of attribute opposite



119
120
121
# File 'lib/rspec/core/filter_manager.rb', line 119

def opposite
  @opposite
end

#rulesObject (readonly)

Returns the value of attribute rules



120
121
122
# File 'lib/rspec/core/filter_manager.rb', line 120

def rules
  @rules
end

Class Method Details

.buildObject



122
123
124
125
126
127
128
# File 'lib/rspec/core/filter_manager.rb', line 122

def self.build
  exclusions = ExclusionRules.new
  inclusions = InclusionRules.new
  exclusions.opposite = inclusions
  inclusions.opposite = exclusions
  [exclusions, inclusions]
end

Instance Method Details

#[](key) ⇒ Object



161
162
163
# File 'lib/rspec/core/filter_manager.rb', line 161

def [](key)
  @rules[key]
end

#add(updated) ⇒ Object



134
135
136
# File 'lib/rspec/core/filter_manager.rb', line 134

def add(updated)
  @rules.merge!(updated).each_key { |k| opposite.delete(k) }
end

#add_with_low_priority(updated) ⇒ Object



138
139
140
141
142
# File 'lib/rspec/core/filter_manager.rb', line 138

def add_with_low_priority(updated)
  updated = updated.merge(@rules)
  opposite.each_pair { |k, v| updated.delete(k) if updated[k] == v }
  @rules.replace(updated)
end

#clearObject



149
150
151
# File 'lib/rspec/core/filter_manager.rb', line 149

def clear
  @rules.clear
end

#delete(key) ⇒ Object



153
154
155
# File 'lib/rspec/core/filter_manager.rb', line 153

def delete(key)
  @rules.delete(key)
end

#descriptionObject



173
174
175
# File 'lib/rspec/core/filter_manager.rb', line 173

def description
  rules.inspect.gsub(PROC_HEX_NUMBER, '').gsub(PROJECT_DIR, '.').gsub(' (lambda)', '')
end

#each_pair(&block) ⇒ Object



169
170
171
# File 'lib/rspec/core/filter_manager.rb', line 169

def each_pair(&block)
  @rules.each_pair(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


165
166
167
# File 'lib/rspec/core/filter_manager.rb', line 165

def empty?
  rules.empty?
end

#fetch(*args, &block) ⇒ Object



157
158
159
# File 'lib/rspec/core/filter_manager.rb', line 157

def fetch(*args, &block)
  @rules.fetch(*args, &block)
end

#include_example?(example) ⇒ Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/rspec/core/filter_manager.rb', line 177

def include_example?(example)
  MetadataFilter.apply?(:any?, @rules, example.)
end

#use_only(updated) ⇒ Object



144
145
146
147
# File 'lib/rspec/core/filter_manager.rb', line 144

def use_only(updated)
  updated.each_key { |k| opposite.delete(k) }
  @rules.replace(updated)
end