Class: RuboCop::Cop::InSpecStyle::FileSize

Inherits:
RuboCop::Cop show all
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/inspecstyle/file_size.rb

Overview

Examples:

EnforcedStyle: InSpecStyle (default)

`size` property for `file` resource is deprecated for `size_kb` and will be removed in InSpec5

# bad
describe file('my_file.txt') do
  its('size') { should eq 12345 }
end

# good
describe file('my_file.txt') do
  its('size_kb') { should eq 12345 }
end

Constant Summary collapse

MSG =
'`size` property for `file` resource is deprecated for `size_kb` and will be removed in InSpec5'

Instance Method Summary collapse

Instance Method Details

#autocorrect(node) ⇒ Object



54
55
56
57
58
# File 'lib/rubocop/cop/inspecstyle/file_size.rb', line 54

def autocorrect(node)
  lambda do |corrector|
    corrector.replace(offense_range(node), preferred_replacement)
  end
end

#on_block(node) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/rubocop/cop/inspecstyle/file_size.rb', line 46

def on_block(node)
  return unless inside_file_spec?(node)
  node.descendants.each do |descendant|
    next unless file_resource_size_property?(descendant)
    add_offense(descendant, location: offense_range(descendant))
  end
end