Skip to content

Commit

Permalink
Support spelling "offence" also for the meantime
Browse files Browse the repository at this point in the history
  • Loading branch information
yujinakayama committed Feb 11, 2014
1 parent 9d4381f commit 446fbe7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Development

* Support both spelling “offense” (RuboCop 0.19 or later) and “offence” (prior to RuboCop 0.19) ([rubocop#700](https://github.com/bbatsov/rubocop/issues/700))

## v1.0.1

* Fix inappripriate multiple run on a save with Vim ([#6](https://github.com/yujinakayama/guard-rubocop/pull/6))
Expand Down
6 changes: 4 additions & 2 deletions lib/guard/rubocop/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ def summary_text
text = pluralize(summary[:inspected_file_count], 'file')
text << ' inspected, '

text << pluralize(summary[:offense_count], 'offense', no_for_zero: true)
offense_count = summary[:offense_count] || summary[:offence_count]
text << pluralize(offense_count, 'offense', no_for_zero: true)
text << ' detected'
end

def failed_paths
failed_files = result[:files].reject do |file|
file[:offenses].empty?
offenses = file[:offenses] || file[:offences]
offenses.empty?
end
failed_files.map do |file|
file[:path]
Expand Down
57 changes: 57 additions & 0 deletions spec/guard/rubocop/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,68 @@
expect(summary_text).to include '2 offenses'
end
end

context 'with spelling "offence" in old RuboCop' do
before do
allow(runner).to receive(:result).and_return(
{
summary: {
offence_count: 2,
target_file_count: 1,
inspected_file_count: 1
}
}
)
end

it 'handles the spelling' do
expect(summary_text).to include '2 offenses'
end
end
end

describe '#failed_paths', :json_file do
it 'returns file paths which have offenses' do
expect(runner.failed_paths).to eq(['lib/bar.rb'])
end

context 'with spelling "offence" in old RuboCop' do
before do
json = <<-END
{
"files": [{
"path": "lib/foo.rb",
"offences": []
}, {
"path": "lib/bar.rb",
"offences": [{
"severity": "convention",
"message": "Line is too long. [81/79]",
"cop_name": "LineLength",
"location": {
"line": 546,
"column": 80
}
}, {
"severity": "warning",
"message": "Unreachable code detected.",
"cop_name": "UnreachableCode",
"location": {
"line": 15,
"column": 9
}
}
]
}
]
}
END
File.write(runner.json_file_path, json)
end

it 'handles the spelling' do
expect(runner.failed_paths).to eq(['lib/bar.rb'])
end
end
end
end

0 comments on commit 446fbe7

Please # to comment.