Skip to content

Commit

Permalink
Merge pull request #1095 from rubocop-hq/quotes
Browse files Browse the repository at this point in the history
Add some consistency around formatting of literal strings
  • Loading branch information
bquorning authored Nov 25, 2020
2 parents cecc4b3 + 4995bd2 commit df1fa3d
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 39 deletions.
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/around_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module RSpec
# end
class AroundBlock < Base
MSG_NO_ARG = 'Test object should be passed to around block.'
MSG_UNUSED_ARG = 'You should call `%<arg>s.call` '\
MSG_UNUSED_ARG = 'You should call `%<arg>s.call` ' \
'or `%<arg>s.run`.'

def_node_matcher :hook, <<-PATTERN
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/be.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module RSpec
# expect(foo).to be(true)
#
class Be < Base
MSG = 'Don\'t use `be` without an argument.'
MSG = "Don't use `be` without an argument."

def_node_matcher :be_without_args, <<-PATTERN
(send _ #Runners.all $(send nil? :be))
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/rspec/before_after_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ module RSpec
# after(:each) { Widget.delete_all }
# end
class BeforeAfterAll < Base
MSG = 'Beware of using `%<hook>s` as it may cause state to leak '\
'between tests. If you are using `rspec-rails`, and '\
'`use_transactional_fixtures` is enabled, then records created '\
MSG = 'Beware of using `%<hook>s` as it may cause state to leak ' \
'between tests. If you are using `rspec-rails`, and ' \
'`use_transactional_fixtures` is enabled, then records created ' \
'in `%<hook>s` are not automatically rolled back.'

def_node_matcher :before_or_after_all, <<-PATTERN
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/describe_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module RSpec
class DescribeClass < Base
include TopLevelGroup

MSG = 'The first argument to describe should be '\
MSG = 'The first argument to describe should be ' \
'the class or module being tested.'

def_node_matcher :example_group_with_ignored_metadata?, <<~PATTERN
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/describe_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module RSpec
class DescribeMethod < Base
include TopLevelGroup

MSG = 'The second argument to describe should be the method '\
MSG = 'The second argument to describe should be the method ' \
"being tested. '#instance' or '.class'."

def_node_matcher :second_argument, <<~PATTERN
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/expect_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module RSpec
# # good
# expect { my_app.print_report }.to output('Hello World').to_stdout
class ExpectOutput < Base
MSG = 'Use `expect { ... }.to output(...).to_%<name>s` '\
MSG = 'Use `expect { ... }.to output(...).to_%<name>s` ' \
'instead of mutating $%<name>s.'

def on_gvasgn(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/instance_spy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module RSpec
class InstanceSpy < Base
extend AutoCorrector

MSG = 'Use `instance_spy` when you check your double '\
MSG = 'Use `instance_spy` when you check your double ' \
'with `have_received`.'

def_node_search :null_double, <<-PATTERN
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/it_behaves_like.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ItBehavesLike < Base
extend AutoCorrector
include ConfigurableEnforcedStyle

MSG = 'Prefer `%<replacement>s` over `%<original>s` when including '\
MSG = 'Prefer `%<replacement>s` over `%<original>s` when including ' \
'examples in a nested context.'

def_node_matcher :example_inclusion_offense, '(send _ % ...)'
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/iterated_expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module RSpec
# end
class IteratedExpectation < Base
MSG = 'Prefer using the `all` matcher instead ' \
'of iterating over an array.'
'of iterating over an array.'

def_node_matcher :each?, <<-PATTERN
(block
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/rspec/message_spies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class MessageSpies < Base

MSG_RECEIVE = 'Prefer `receive` for setting message expectations.'

MSG_HAVE_RECEIVED = 'Prefer `have_received` for setting message '\
'expectations. Setup `%<source>s` as a spy using '\
MSG_HAVE_RECEIVED = 'Prefer `have_received` for setting message ' \
'expectations. Setup `%<source>s` as a spy using ' \
'`allow` or `instance_spy`.'

SUPPORTED_STYLES = %w[have_received receive].freeze
Expand Down
3 changes: 1 addition & 2 deletions lib/rubocop/cop/rspec/multiple_describes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ module RSpec
class MultipleDescribes < Base
include TopLevelGroup

MSG = 'Do not use multiple top-level example groups - '\
'try to nest them.'
MSG = 'Do not use multiple top-level example groups - try to nest them.'

def on_top_level_group(node)
top_level_example_groups =
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/scattered_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module RSpec
# end
#
class ScatteredSetup < Base
MSG = 'Do not define multiple `%<hook_name>s` hooks in the same '\
MSG = 'Do not define multiple `%<hook_name>s` hooks in the same ' \
'example group (also defined on %<lines>s).'

def on_block(node)
Expand Down
7 changes: 2 additions & 5 deletions lib/rubocop/cop/rspec/shared_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@ module RSpec
class SharedContext < Base
extend AutoCorrector

MSG_EXAMPLES = "Use `shared_examples` when you don't "\
'define context.'

MSG_CONTEXT = "Use `shared_context` when you don't "\
'define examples.'
MSG_EXAMPLES = "Use `shared_examples` when you don't define context."
MSG_CONTEXT = "Use `shared_context` when you don't define examples."

def_node_search :examples?,
send_pattern('{#Includes.examples #Examples.all}')
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/single_argument_message_chain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module RSpec
class SingleArgumentMessageChain < Base
extend AutoCorrector

MSG = 'Use `%<recommended>s` instead of calling '\
MSG = 'Use `%<recommended>s` instead of calling ' \
'`%<called>s` with a single argument.'

def_node_matcher :message_chain, <<-PATTERN
Expand Down
6 changes: 3 additions & 3 deletions spec/rubocop/cop/rspec/before_after_all_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

RSpec.describe RuboCop::Cop::RSpec::BeforeAfterAll do
def message(hook)
"Beware of using `#{hook}` as it may cause state to leak between tests. "\
'If you are using `rspec-rails`, and `use_transactional_fixtures` is '\
"enabled, then records created in `#{hook}` are not automatically rolled "\
"Beware of using `#{hook}` as it may cause state to leak between tests. " \
'If you are using `rspec-rails`, and `use_transactional_fixtures` is ' \
"enabled, then records created in `#{hook}` are not automatically rolled " \
'back.'
end

Expand Down
14 changes: 7 additions & 7 deletions spec/rubocop/cop/rspec/capybara/current_path_expectation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,37 @@

include_examples 'autocorrect',
'expect(current_path).to eq expected_path',
'expect(page).to have_current_path expected_path, '\
'expect(page).to have_current_path expected_path, ' \
'ignore_query: true'

include_examples 'autocorrect',
'expect(current_path).to eq(expected_path)',
'expect(page).to have_current_path(expected_path, '\
'expect(page).to have_current_path(expected_path, ' \
'ignore_query: true)'

include_examples 'autocorrect',
'expect(current_path).to(eq(expected_path))',
'expect(page).to(have_current_path(expected_path, '\
'expect(page).to(have_current_path(expected_path, ' \
'ignore_query: true))'

include_examples 'autocorrect',
'expect(current_path).to eq(expected_path(f: :b))',
'expect(page).to have_current_path(expected_path(f: :b), '\
'expect(page).to have_current_path(expected_path(f: :b), ' \
'ignore_query: true)'

include_examples 'autocorrect',
'expect(page.current_path).to eq(foo(bar).path)',
'expect(page).to have_current_path(foo(bar).path, '\
'expect(page).to have_current_path(foo(bar).path, ' \
'ignore_query: true)'

include_examples 'autocorrect',
'expect(current_path).not_to eq expected_path',
'expect(page).to have_no_current_path expected_path, '\
'expect(page).to have_no_current_path expected_path, ' \
'ignore_query: true'

include_examples 'autocorrect',
'expect(current_path).to_not eq expected_path',
'expect(page).to have_no_current_path expected_path, '\
'expect(page).to have_no_current_path expected_path, ' \
'ignore_query: true'

include_examples 'autocorrect',
Expand Down
12 changes: 6 additions & 6 deletions spec/rubocop/cop/rspec/example_wording_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
RUBY
end

it 'finds description with `shouldn\'t` at the beginning' do
it "finds description with `shouldn't` at the beginning" do
expect_offense(<<-RUBY)
it "shouldn't do something" do
^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
Expand All @@ -57,7 +57,7 @@
RUBY
end

it 'finds description with `SHOULDN\'T` at the beginning' do
it "finds description with `SHOULDN'T` at the beginning" do
expect_offense(<<-RUBY)
it "SHOULDN'T do something" do
^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
Expand Down Expand Up @@ -152,8 +152,8 @@

it 'flags \-separated multiline strings' do
expect_offense(<<-RUBY)
it 'should do something '\\
^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
it 'should do something ' \\
^^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
'and correctly fix' do
end
RUBY
Expand All @@ -166,8 +166,8 @@

it 'flags \-separated multiline interpolated strings' do
expect_offense(<<-'RUBY')
it "should do something "\
^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
it "should do something " \
^^^^^^^^^^^^^^^^^^^^^^^ Do not use should when describing your tests.
"with #{object}" do
end
RUBY
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/rspec/example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def example(source)
end

it 'extracts interpolated doc string' do
expect(example("it(\"does \#{x}\")").doc_string)
expect(example('it("does #{x}")').doc_string)
.to eq(s(:dstr, s(:str, 'does '), s(:begin, s(:send, nil, :x))))
end

Expand Down

0 comments on commit df1fa3d

Please sign in to comment.