Class: RuboCop::RSpec::Wording
- Inherits:
-
Object
- Object
- RuboCop::RSpec::Wording
- Defined in:
- lib/rubocop/rspec/wording.rb
Overview
RSpec example wording rewriter
Constant Summary collapse
- SHOULDNT_PREFIX =
/\Ashould(?:n't|n’t| not)\b/i.freeze
- SHOULDNT_BE_PREFIX =
/#{SHOULDNT_PREFIX} be\b/i.freeze
- WILL_NOT_PREFIX =
/\Awill not\b/i.freeze
- WONT_PREFIX =
/\Awo(?:n't|n’t)\b/i.freeze
- ES_SUFFIX_PATTERN =
/(?:o|s|x|ch|sh|z)\z/i.freeze
- IES_SUFFIX_PATTERN =
/[^aeou]y\z/i.freeze
Instance Method Summary collapse
-
#initialize(text, ignore:, replace:) ⇒ Wording
constructor
A new instance of Wording.
-
#rewrite ⇒ Object
rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(text, ignore:, replace:) ⇒ Wording
Returns a new instance of Wording.
14 15 16 17 18 |
# File 'lib/rubocop/rspec/wording.rb', line 14 def initialize(text, ignore:, replace:) @text = text @ignores = ignore @replacements = replace end |
Instance Method Details
#rewrite ⇒ Object
rubocop:disable Metrics/MethodLength
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rubocop/rspec/wording.rb', line 21 def rewrite case text when SHOULDNT_BE_PREFIX replace_prefix(SHOULDNT_BE_PREFIX, 'is not') when SHOULDNT_PREFIX replace_prefix(SHOULDNT_PREFIX, 'does not') when WILL_NOT_PREFIX replace_prefix(WILL_NOT_PREFIX, 'does not') when WONT_PREFIX replace_prefix(WONT_PREFIX, 'does not') else remove_should_and_pluralize end end |