Class: RuboCop::Cop::RSpec::Extra::RestrictBlockTag

Inherits:
Base
  • Object
show all
Includes:
Metadata
Defined in:
lib/rubocop/cop/rspec/extra/restrict_block_tag.rb

Overview

Restrict to only allowed block tags.

Examples:

AllowTags: ['foo', 'bar']

# bad
RSpec.describe 'Something', :baz do
end

# bad
RSpec.describe 'Something' do
  context 'when something', baz: :foo do
  end
end

# good
RSpec.describe 'Something', :foo do
end

# good
RSpec.describe 'Something' do
  context 'when something', bar: :foo do
  end
end

Instance Method Summary collapse

Instance Method Details

#on_metadata(symbols, hash) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rubocop/cop/rspec/extra/restrict_block_tag.rb', line 33

def (symbols, hash)
  symbols += hash.pairs.map(&:key) unless hash.nil?
  offenses = symbols.filter do |symbol|
    !allow_tags.include?(symbol.value.to_s)
  end

  return unless offenses.any?

  offenses.each do |offense|
    add_offense(offense, message: offense_message)
  end
end