-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1253 from ydah/fix-capybara-current-path-expectat…
…ion-autocorrect [Fix #1237] Fix `Capybara/CurrentPathExpectation` autocorrect incompatible with `Style/TrailingCommaInArguments` autocorrect
- Loading branch information
Showing
6 changed files
with
116 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe 'RuboCop::CLI --autocorrect', :isolated_environment do # rubocop:disable RSpec/DescribeClass | ||
subject(:cli) { RuboCop::CLI.new } | ||
|
||
include_context 'when cli spec behavior' | ||
|
||
context 'when corrects `RSpec/Capybara/CurrentPathExpectation` with ' \ | ||
'`Style/TrailingCommaInArguments`' do | ||
before do | ||
RuboCop::ConfigLoader | ||
.default_configuration | ||
.for_all_cops['SuggestExtensions'] = false | ||
|
||
create_file('.rubocop.yml', <<~YAML) | ||
Style/TrailingCommaInArguments: | ||
EnforcedStyleForMultiline: 'comma' | ||
YAML | ||
|
||
create_file('spec/example.rb', <<-RUBY) | ||
expect(page.current_path).to eq( | ||
some_path( | ||
id: id | ||
) | ||
) | ||
RUBY | ||
end | ||
|
||
it 'rubocop terminates with a succsess' do | ||
expect(cli.run(['-A', '--only', | ||
'RSpec/Capybara/CurrentPathExpectation,' \ | ||
'Style/TrailingCommaInArguments'])).to eq(0) | ||
end | ||
|
||
it 'autocorrects be compatible with each other' do | ||
cli.run(['-A', '--only', | ||
'RSpec/Capybara/CurrentPathExpectation,' \ | ||
'Style/TrailingCommaInArguments']) | ||
|
||
expect(File.read('spec/example.rb')).to eq(<<-RUBY) | ||
expect(page).to have_current_path( | ||
some_path( | ||
id: id, | ||
), ignore_query: true | ||
) | ||
RUBY | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_context 'when cli spec behavior' do | ||
include_context 'mock console output' | ||
|
||
include FileHelper | ||
|
||
before do | ||
RuboCop::ConfigLoader.debug = false | ||
|
||
# OPTIMIZE: Makes these specs faster. Work directory (the parent of | ||
# .rubocop_cache) is removed afterwards anyway. | ||
RuboCop::ResultCache.inhibit_cleanup = true | ||
end | ||
|
||
# Wrap all cli specs in `aggregate_failures` so that the expected and | ||
# actual results of every expectation per example are shown. This is | ||
# helpful because it shows information like expected and actual | ||
# $stdout messages while not using `aggregate_failures` will only | ||
# show information about expected and actual exit code | ||
around { |example| aggregate_failures(&example) } | ||
|
||
after { RuboCop::ResultCache.inhibit_cleanup = false } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'fileutils' | ||
|
||
module FileHelper | ||
def create_file(file_path, content) | ||
file_path = File.expand_path(file_path) | ||
create_dir file_path | ||
|
||
File.open(file_path, 'w') do |file| | ||
case content | ||
when String | ||
file.puts content | ||
when Array | ||
file.puts content.join("\n") | ||
end | ||
end | ||
end | ||
|
||
def create_dir(file_path) | ||
dir_path = File.dirname(file_path) | ||
FileUtils.makedirs dir_path unless File.exist?(dir_path) | ||
end | ||
end |