Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions lib/overcommit/hook/commit_msg/spell_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ class SpellCheck < Base
MISSPELLING_REGEX = /^[&#]\s(?<word>\w+)(?:.+?:\s(?<suggestions>.*))?/.freeze

def run
result = execute(command + [uncommented_commit_msg_file])
result = ::Tempfile.create('commit-msg') do |file|
file.write(commit_message)
file.close
execute(command + [file.path])
end
return [:fail, "Error running spellcheck: #{result.stderr.chomp}"] unless result.success?

misspellings = parse_misspellings(result.stdout)
Expand All @@ -29,13 +33,6 @@ def run

private

def uncommented_commit_msg_file
::Tempfile.open('commit-msg') do |file|
file.write(commit_message)
file.path
end
end

def parse_misspellings(output)
output.scan(MISSPELLING_REGEX).map do |word, suggestions|
Misspelling.new(word, suggestions)
Expand Down
2 changes: 1 addition & 1 deletion lib/overcommit/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

# Defines the gem version.
module Overcommit
VERSION = '0.75.0'
VERSION = '0.76.0'
end
20 changes: 19 additions & 1 deletion spec/overcommit/hook/additional_hook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,29 @@
it 'passes uncommented commit messages to the spelling checker' do
hook = Overcommit::Hook::CommitMsg::SpellCheck.new(config,
double('context', commit_message: 'Subject'))
message_file = nil
expect(hook).to receive(:execute) do |command|
expect(File).to exist(command.last)
message_file = command.last
GC.start
expect(File).to exist(message_file)
expect(File.read(message_file)).to eq('Subject')
double('result', success?: true, stdout: '')
end
expect(hook.run).to eq(:pass)
expect(File).not_to exist(message_file)
end

it 'removes the spelling checker message file when execution raises' do
hook = Overcommit::Hook::CommitMsg::SpellCheck.new(config,
double('context', commit_message: 'Subject'))
message_file = nil
expect(hook).to receive(:execute) do |command|
message_file = command.last
expect(File).to exist(message_file)
raise 'spell checker failed'
end
expect { hook.run }.to raise_error('spell checker failed')
expect(File).not_to exist(message_file)
end

it 'checks real submodule statuses with the configured recursive option' do
Expand Down
3 changes: 1 addition & 2 deletions spec/overcommit/hook/commit_msg/spell_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

describe Overcommit::Hook::CommitMsg::SpellCheck do
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
let(:context) { double('context') }
let(:context) { double('context', commit_message: 'Subject') }
subject { described_class.new(config, context) }

before do
subject.stub(:uncommented_commit_msg_file)
subject.stub(:execute).and_return(result)
end

Expand Down