Class: RuboCop::Cop::InSpecStyle::UsersResourceMatchers
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::InSpecStyle::UsersResourceMatchers
- Defined in:
- lib/rubocop/cop/inspecstyle/users_resource_matchers.rb
Overview
Users resource deprecated matchers
Constant Summary collapse
- MSG =
'Use `%<solution>s` instead of `%<violation>s` as a matcher ' \ "for the `users` resource. \nThis matcher will be removed in InSpec 5"
- MAP =
{ has_home_directory?: "its('home')", has_login_shell?: "its('shell')", has_authorized_key?: "another matcher", maximum_days_between_password_change: :maxdays, has_uid?: "another matcher", minimum_days_between_password_change: "mindays" }
Instance Method Summary collapse
Instance Method Details
#autocorrect(node) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# 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) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 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 |