lib/rubocop/cop/rspec/example_wording.rb in rubocop-rspec-2.25.0 vs lib/rubocop/cop/rspec/example_wording.rb in rubocop-rspec-2.26.0
- old
+ new
@@ -20,10 +20,13 @@
# @example
# # bad
# it 'should find nothing' do
# end
#
+ # it 'will find nothing' do
+ # end
+ #
# # good
# it 'finds nothing' do
# end
#
# @example
@@ -45,37 +48,43 @@
# end
class ExampleWording < Base
extend AutoCorrector
MSG_SHOULD = 'Do not use should when describing your tests.'
+ MSG_WILL = 'Do not use the future tense when describing your tests.'
MSG_IT = "Do not repeat 'it' when describing your tests."
MSG_INSUFFICIENT_DESCRIPTION = 'Your example description is ' \
'insufficient.'
SHOULD_PREFIX = /\Ashould(?:n't)?\b/i.freeze
+ WILL_PREFIX = /\A(?:will|won't)\b/i.freeze
IT_PREFIX = /\Ait /i.freeze
# @!method it_description(node)
- def_node_matcher :it_description, <<-PATTERN
+ def_node_matcher :it_description, <<~PATTERN
(block (send _ :it ${
(str $_)
(dstr (str $_ ) ...)
} ...) ...)
PATTERN
+ # rubocop:disable Metrics/MethodLength
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
it_description(node) do |description_node, message|
if message.match?(SHOULD_PREFIX)
add_wording_offense(description_node, MSG_SHOULD)
+ elsif message.match?(WILL_PREFIX)
+ add_wording_offense(description_node, MSG_WILL)
elsif message.match?(IT_PREFIX)
add_wording_offense(description_node, MSG_IT)
elsif insufficient_docstring?(description_node)
add_offense(docstring(description_node),
message: MSG_INSUFFICIENT_DESCRIPTION)
end
end
end
+ # rubocop:enable Metrics/MethodLength
private
def add_wording_offense(node, message)
docstring = docstring(node)
@@ -98,10 +107,10 @@
end
def replacement_text(node)
text = text(node)
- if text.match?(SHOULD_PREFIX)
+ if text.match?(SHOULD_PREFIX) || text.match?(WILL_PREFIX)
RuboCop::RSpec::Wording.new(
text,
ignore: ignored_words,
replace: custom_transform
).rewrite