Sha256: c0e96d4b4b929264860c5b45f47e11dd85ff47807b82d33343bbac9b82b42bfc
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module RSpec # `context` should not be used for specifying methods. # # @example # # bad # context '#foo_bar' do # # ... # end # # context '.foo_bar' do # # ... # end # # # good # describe '#foo_bar' do # # ... # end # # describe '.foo_bar' do # # ... # end class ContextMethod < Cop extend AutoCorrector MSG = 'Use `describe` for testing methods.' def_node_matcher :context_method, <<-PATTERN (block (send #{RSPEC} :context $(str #method_name?) ...) ...) PATTERN def on_block(node) context_method(node) do |context| add_offense(context) do |corrector| corrector.replace(node.send_node.loc.selector, 'describe') end end end private def method_name?(description) description.start_with?('.', '#') end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rubocop-rspec-1.42.0 | lib/rubocop/cop/rspec/context_method.rb |