class RuboCop::Cop::InSpecStyle::UsersResourceMatchers
Users resource deprecated matchers
@example EnforcedStyle: InSpecStyle
(default)
# bad describe users('/etc/my-custom-place/users') do its('has_home_directory?') { should eq 'foo' } end # good describe users('/etc/my-custom-place/users') do its('users') { should eq 'foo' } end
Constants
- MAP
- MSG
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/inspecstyle/users_resource_matchers.rb, line 72 def autocorrect(node) lambda do |corrector| # Only these two matchers are autocorrectable [ 'maximum_days_between_password_change', 'minimum_days_between_password_change' ].map do |violation| if node.inspect.include?(violation) corrector.replace(node.loc.selector, MAP[violation.to_sym]) end end end end
on_block(node)
click to toggle source
# File lib/rubocop/cop/inspecstyle/users_resource_matchers.rb, line 55 def on_block(node) return unless inside_users_spec?(node) node.descendants.each do |descendant| deprecated_users_matcher?(descendant) do |violation| add_offense( descendant, location: offense_range(descendant), message: format( MSG, violation: violation, solution: MAP[violation] ) ) end end end
Private Instance Methods
inside_users_spec?(root)
click to toggle source
# File lib/rubocop/cop/inspecstyle/users_resource_matchers.rb, line 88 def inside_users_spec?(root) spec?(root) && users_resource?(root) end
offense_range(node)
click to toggle source
# File lib/rubocop/cop/inspecstyle/users_resource_matchers.rb, line 92 def offense_range(node) node.loc.selector end