Sha256: 620e4eec637e407db649b471d1becc1a40a83d6f06599641c7d3bedec70c3705
Contents?: true
Size: 1.77 KB
Versions: 3
Compression:
Stored size: 1.77 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module RSpec # Do not use should when describing your tests. # see: http://betterspecs.org/#should # # The autocorrect is experimental - use with care! It can be configured # with CustomTransform (e.g. have => has) and IgnoredWords (e.g. only). # # @example # # bad # it 'should find nothing' do # end # # # good # it 'finds nothing' do # end class ExampleWording < Cop MSG = 'Do not use should when describing your tests.'.freeze def on_block(node) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/LineLength method, = *node _, method_name, *args = *method return unless method_name.equal?(:it) arguments = args.first.to_a message = arguments.first.to_s return unless message.downcase.start_with?('should') arg1 = args.first.loc.expression message = Parser::Source::Range.new(arg1.source_buffer, arg1.begin_pos + 1, arg1.end_pos - 1) add_offense(message, message) end def autocorrect(range) lambda do |corrector| corrector.replace( range, RuboCop::RSpec::Wording.new( range.source, ignore: ignored_words, replace: custom_transform ).rewrite ) end end private def custom_transform cop_config.fetch('CustomTransform', {}) end def ignored_words cop_config.fetch('IgnoredWords', []) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rubocop-rspec-1.6.0 | lib/rubocop/cop/rspec/example_wording.rb |
rubocop-rspec-1.5.3 | lib/rubocop/cop/rspec/example_wording.rb |
rubocop-rspec-1.5.2 | lib/rubocop/cop/rspec/example_wording.rb |