From c7cc26436cee4a82ad2a794e84bc7da9362b75ae Mon Sep 17 00:00:00 2001 From: Michal Papis Date: Sat, 13 Sep 2014 21:23:09 +0200 Subject: [PATCH] add support for parsed line errors in ci and grep related checks --- lib/plugins/pre_commit/checks/before_all.rb | 2 +- lib/plugins/pre_commit/checks/ci.rb | 4 +- lib/plugins/pre_commit/checks/console_log.rb | 2 +- lib/plugins/pre_commit/checks/debugger.rb | 2 +- lib/plugins/pre_commit/checks/gemfile_path.rb | 2 +- .../pre_commit/checks/merge_conflict.rb | 2 +- lib/plugins/pre_commit/checks/pry.rb | 2 +- lib/plugins/pre_commit/checks/rspec_focus.rb | 2 +- .../checks/ruby_symbol_hashrockets.rb | 2 +- lib/plugins/pre_commit/checks/tabs.rb | 2 +- lib/pre-commit/checks/grep.rb | 18 ++++++- lib/pre-commit/checks/plugin.rb | 1 + lib/pre-commit/error_list.rb | 23 ++++++++ lib/pre-commit/line.rb | 22 ++++++++ lib/pre-commit/message.rb | 17 ++++++ lib/pre-commit/runner.rb | 9 +++- .../pre_commit/checks/before_all_test.rb | 16 +++--- .../unit/plugins/pre_commit/checks/ci_test.rb | 2 +- .../pre_commit/checks/console_log_test.rb | 8 +-- .../pre_commit/checks/debugger_test.rb | 8 +-- .../pre_commit/checks/gemfile_path_test.rb | 16 +++--- .../pre_commit/checks/merge_conflict_test.rb | 8 +-- .../plugins/pre_commit/checks/pry_test.rb | 8 +-- .../pre_commit/checks/rspec_focus_test.rb | 5 +- .../checks/ruby_symbol_hashrockets_test.rb | 5 +- .../plugins/pre_commit/checks/tabs_test.rb | 8 +-- test/unit/pre-commit/checks/grep_test.rb | 19 ++++--- test/unit/pre-commit/error_list_test.rb | 31 +++++++++++ test/unit/pre-commit/line_test.rb | 52 +++++++++++++++++++ test/unit/pre-commit/runner_test.rb | 1 - 30 files changed, 232 insertions(+), 67 deletions(-) create mode 100644 lib/pre-commit/error_list.rb create mode 100644 lib/pre-commit/line.rb create mode 100644 lib/pre-commit/message.rb create mode 100644 test/unit/pre-commit/error_list_test.rb create mode 100644 test/unit/pre-commit/line_test.rb diff --git a/lib/plugins/pre_commit/checks/before_all.rb b/lib/plugins/pre_commit/checks/before_all.rb index 7fa69c4..b2a3e24 100644 --- a/lib/plugins/pre_commit/checks/before_all.rb +++ b/lib/plugins/pre_commit/checks/before_all.rb @@ -13,7 +13,7 @@ def extra_grep end def message - "before(:all) found:\n" + "before(:all) found:" end def pattern diff --git a/lib/plugins/pre_commit/checks/ci.rb b/lib/plugins/pre_commit/checks/ci.rb index 22a3719..c0ad767 100644 --- a/lib/plugins/pre_commit/checks/ci.rb +++ b/lib/plugins/pre_commit/checks/ci.rb @@ -7,7 +7,9 @@ class Ci < Plugin def call(_) return if system("rake #{Ci::CI_TASK_NAME} --silent") - "your test suite has failed, for the full output run `#{CI_TASK_NAME}`" + PreCommit::ErrorList.new( + "your test suite has failed, for the full output run `#{CI_TASK_NAME}`" + ) end def self.description diff --git a/lib/plugins/pre_commit/checks/console_log.rb b/lib/plugins/pre_commit/checks/console_log.rb index e22798c..fc84653 100644 --- a/lib/plugins/pre_commit/checks/console_log.rb +++ b/lib/plugins/pre_commit/checks/console_log.rb @@ -13,7 +13,7 @@ def extra_grep end def message - "console.log found:\n" + "console.log found:" end def pattern diff --git a/lib/plugins/pre_commit/checks/debugger.rb b/lib/plugins/pre_commit/checks/debugger.rb index 7e751b0..018bcb9 100644 --- a/lib/plugins/pre_commit/checks/debugger.rb +++ b/lib/plugins/pre_commit/checks/debugger.rb @@ -9,7 +9,7 @@ def files_filter(staged_files) end def message - "debugger statement(s) found:\n" + "debugger statement(s) found:" end def pattern diff --git a/lib/plugins/pre_commit/checks/gemfile_path.rb b/lib/plugins/pre_commit/checks/gemfile_path.rb index 83d5b25..b4958a7 100644 --- a/lib/plugins/pre_commit/checks/gemfile_path.rb +++ b/lib/plugins/pre_commit/checks/gemfile_path.rb @@ -9,7 +9,7 @@ def files_filter(staged_files) end def message - "local path found in Gemfile:\n" + "local path found in Gemfile:" end def pattern diff --git a/lib/plugins/pre_commit/checks/merge_conflict.rb b/lib/plugins/pre_commit/checks/merge_conflict.rb index 66ca357..e2be528 100644 --- a/lib/plugins/pre_commit/checks/merge_conflict.rb +++ b/lib/plugins/pre_commit/checks/merge_conflict.rb @@ -5,7 +5,7 @@ module Checks class MergeConflict < Grep def message - "detected a merge conflict\n" + "detected a merge conflict" end def pattern diff --git a/lib/plugins/pre_commit/checks/pry.rb b/lib/plugins/pre_commit/checks/pry.rb index 3d0af98..67147a0 100644 --- a/lib/plugins/pre_commit/checks/pry.rb +++ b/lib/plugins/pre_commit/checks/pry.rb @@ -5,7 +5,7 @@ module Checks class Pry < Grep def message - "binding.pry found:\n" + "binding.pry found:" end def pattern diff --git a/lib/plugins/pre_commit/checks/rspec_focus.rb b/lib/plugins/pre_commit/checks/rspec_focus.rb index a37726e..07eac10 100644 --- a/lib/plugins/pre_commit/checks/rspec_focus.rb +++ b/lib/plugins/pre_commit/checks/rspec_focus.rb @@ -9,7 +9,7 @@ def files_filter(staged_files) end def message - ":focus found in specs:\n" + ":focus found in specs:" end def pattern diff --git a/lib/plugins/pre_commit/checks/ruby_symbol_hashrockets.rb b/lib/plugins/pre_commit/checks/ruby_symbol_hashrockets.rb index ae26bb8..3878c5a 100644 --- a/lib/plugins/pre_commit/checks/ruby_symbol_hashrockets.rb +++ b/lib/plugins/pre_commit/checks/ruby_symbol_hashrockets.rb @@ -9,7 +9,7 @@ def files_filter(staged_files) end def message - "detected :symbol => value hashrocket:\n" + "detected :symbol => value hashrocket:" end def pattern diff --git a/lib/plugins/pre_commit/checks/tabs.rb b/lib/plugins/pre_commit/checks/tabs.rb index d6201c1..d4999bb 100644 --- a/lib/plugins/pre_commit/checks/tabs.rb +++ b/lib/plugins/pre_commit/checks/tabs.rb @@ -5,7 +5,7 @@ module Checks class Tabs < Grep def message - "detected tab before initial space:\n" + "detected tab before initial space:" end def pattern diff --git a/lib/pre-commit/checks/grep.rb b/lib/pre-commit/checks/grep.rb index ee0b545..9bc6a89 100644 --- a/lib/pre-commit/checks/grep.rb +++ b/lib/pre-commit/checks/grep.rb @@ -1,4 +1,6 @@ require 'pre-commit/checks/plugin' +require 'pre-commit/error_list' +require 'pre-commit/line' require 'shellwords' module PreCommit @@ -35,11 +37,25 @@ def call(staged_files) return if staged_files.empty? errors = `#{grep} #{pattern} #{staged_files.join(" ")}#{extra_grep}` return unless $?.success? - "#{message}#{errors}" + parse_errors(message, errors) end private + def parse_errors(message, list) + result = PreCommit::ErrorList.new(message) + result.errors += + list.split(/\n/).map do |line| + PreCommit::Line.new(nil, *parse_error(line)) + end + result + end + + def parse_error(line) + matches = /^([^:]+):([[:digit:]]+):(.*)$/.match(line) + matches and matches.captures + end + def grep(grep_version = nil) grep_version ||= detect_grep_version if grep_version =~ /FreeBSD/ diff --git a/lib/pre-commit/checks/plugin.rb b/lib/pre-commit/checks/plugin.rb index 3819e70..c329f25 100644 --- a/lib/pre-commit/checks/plugin.rb +++ b/lib/pre-commit/checks/plugin.rb @@ -1,5 +1,6 @@ require 'plugins/pluginator/extensions/conversions' require 'pre-commit/checks/plugin/config_file' +require 'pre-commit/line' module PreCommit module Checks diff --git a/lib/pre-commit/error_list.rb b/lib/pre-commit/error_list.rb new file mode 100644 index 0000000..b37ae16 --- /dev/null +++ b/lib/pre-commit/error_list.rb @@ -0,0 +1,23 @@ +require 'pre-commit/line' + +module PreCommit + class ErrorList < Struct.new :errors + + def initialize(errors = []) + case errors + when "",nil then errors = [] + when String then errors = [PreCommit::Line.new(errors)] + end + super errors + end + + def to_a + errors.map(&:to_s) + end + + def to_s + to_a.join("\n") + end + + end +end diff --git a/lib/pre-commit/line.rb b/lib/pre-commit/line.rb new file mode 100644 index 0000000..ca9754f --- /dev/null +++ b/lib/pre-commit/line.rb @@ -0,0 +1,22 @@ +module PreCommit + class Line < Struct.new :message, :file, :line, :code + + def to_s + result = message.to_s + unless empty? file + result = "#{result}#{"\n" unless empty?(result)}#{file}" + result = "#{result}:#{line}" unless empty? line + result = "#{result}:#{code}" unless empty? code + end + result + end + + protected + + def empty?(string) + string == nil || string == "" + end + + end +end + diff --git a/lib/pre-commit/message.rb b/lib/pre-commit/message.rb new file mode 100644 index 0000000..5382a71 --- /dev/null +++ b/lib/pre-commit/message.rb @@ -0,0 +1,17 @@ +module PreCommit + class Message < Struct.new :message, :lines + + def to_s + result = message + result = "#{message}\n#{lines.map(&:to_s).join("\n")}" unless lines.nil? + result + end + + protected + + def empty?(string) + string == nil || string == "" + end + + end +end diff --git a/lib/pre-commit/runner.rb b/lib/pre-commit/runner.rb index 9df9e1f..aa665dd 100644 --- a/lib/pre-commit/runner.rb +++ b/lib/pre-commit/runner.rb @@ -4,6 +4,7 @@ require 'pre-commit/utils/staged_files' require 'pre-commit/configuration' require 'pre-commit/list_evaluator' +require 'pre-commit/error_list' module PreCommit class Runner @@ -63,18 +64,22 @@ def list_evaluator def warnings(list) <<-WARNINGS pre-commit: Some warnings were raised. These will not stop commit: -#{list.join("\n")} +#{errors_to_string(list)} WARNINGS end def checks(list) <<-ERRORS pre-commit: Stopping commit because of errors. -#{list.join("\n")} +#{errors_to_string(list)} pre-commit: You can bypass this check using `git commit -n` ERRORS end + def errors_to_string(list) + list.map(&:to_s).join("\n") + end + end end diff --git a/test/unit/plugins/pre_commit/checks/before_all_test.rb b/test/unit/plugins/pre_commit/checks/before_all_test.rb index fb3fe2b..ae54adb 100644 --- a/test/unit/plugins/pre_commit/checks/before_all_test.rb +++ b/test/unit/plugins/pre_commit/checks/before_all_test.rb @@ -21,16 +21,16 @@ end it "fails if file contains before(:all)" do - subject.call([fixture_file('before_all_spec.rb')]).must_equal(<<-EXPECTED) -before(:all) found: -test/files/before_all_spec.rb:2: before(:all) do -EXPECTED + subject.call([fixture_file('before_all_spec.rb')]).to_a.must_equal([ + "before(:all) found:", + "test/files/before_all_spec.rb:2: before(:all) do" + ]) end it "fails if file contains before :all" do - subject.call([fixture_file('before_all_spec_2.rb')]).must_equal(<<-EXPECTED) -before(:all) found: -test/files/before_all_spec_2.rb:2: before :all do -EXPECTED + subject.call([fixture_file('before_all_spec_2.rb')]).to_a.must_equal([ + "before(:all) found:", + "test/files/before_all_spec_2.rb:2: before :all do" + ]) end end diff --git a/test/unit/plugins/pre_commit/checks/ci_test.rb b/test/unit/plugins/pre_commit/checks/ci_test.rb index 8a1b02a..dcf59e0 100644 --- a/test/unit/plugins/pre_commit/checks/ci_test.rb +++ b/test/unit/plugins/pre_commit/checks/ci_test.rb @@ -12,7 +12,7 @@ it "fails if rake fails" do check.stub :system, false do - check.call([]).must_equal "your test suite has failed, for the full output run `pre_commit:ci`" + check.call([]).to_s.must_equal "your test suite has failed, for the full output run `pre_commit:ci`" end end end diff --git a/test/unit/plugins/pre_commit/checks/console_log_test.rb b/test/unit/plugins/pre_commit/checks/console_log_test.rb index f04d936..9599249 100644 --- a/test/unit/plugins/pre_commit/checks/console_log_test.rb +++ b/test/unit/plugins/pre_commit/checks/console_log_test.rb @@ -27,9 +27,9 @@ end it "fails if a js file has a console.log" do - subject.call([fixture_file('console_log.js')]).must_equal(<<-EXPECTED) -console.log found: -test/files/console_log.js:6: console.log(\"I'm in bar\"); -EXPECTED + subject.call([fixture_file('console_log.js')]).to_a.must_equal([ + "console.log found:", + "test/files/console_log.js:6: console.log(\"I'm in bar\");" + ]) end end diff --git a/test/unit/plugins/pre_commit/checks/debugger_test.rb b/test/unit/plugins/pre_commit/checks/debugger_test.rb index bf8c05d..c945a7c 100644 --- a/test/unit/plugins/pre_commit/checks/debugger_test.rb +++ b/test/unit/plugins/pre_commit/checks/debugger_test.rb @@ -21,10 +21,10 @@ end it "fails if file contains debugger" do - subject.call([fixture_file('debugger_file.rb')]).must_equal(<<-EXPECTED) -debugger statement(s) found: -test/files/debugger_file.rb:3: debugger -EXPECTED + subject.call([fixture_file('debugger_file.rb')]).to_a.must_equal([ + "debugger statement(s) found:", + "test/files/debugger_file.rb:3: \tdebugger" + ]) end it "Skips checking the Gemfile" do diff --git a/test/unit/plugins/pre_commit/checks/gemfile_path_test.rb b/test/unit/plugins/pre_commit/checks/gemfile_path_test.rb index 2851c76..fcf99cf 100644 --- a/test/unit/plugins/pre_commit/checks/gemfile_path_test.rb +++ b/test/unit/plugins/pre_commit/checks/gemfile_path_test.rb @@ -39,20 +39,20 @@ write "Gemfile", <<-RUBY gem "foo", :path => "xxxx" RUBY - check.call(["Gemfile"]).must_equal(<<-EXPECTED) -local path found in Gemfile: -Gemfile:1: gem "foo", :path => "xxxx" -EXPECTED + check.call(["Gemfile"]).to_a.must_equal([ + "local path found in Gemfile:", + 'Gemfile:1: gem "foo", :path => "xxxx"' + ]) end it "fails if Gemfile contains path:" do write "Gemfile", <<-RUBY gem "foo", path: "xxxx" RUBY - check.call(["Gemfile"]).must_equal(<<-EXPECTED) -local path found in Gemfile: -Gemfile:1: gem "foo", path: "xxxx" -EXPECTED + check.call(["Gemfile"]).to_a.must_equal([ + "local path found in Gemfile:", + 'Gemfile:1: gem "foo", path: "xxxx"' + ]) end it "allows a Gemfile path that is commented out" do diff --git a/test/unit/plugins/pre_commit/checks/merge_conflict_test.rb b/test/unit/plugins/pre_commit/checks/merge_conflict_test.rb index e241aab..8f9d569 100644 --- a/test/unit/plugins/pre_commit/checks/merge_conflict_test.rb +++ b/test/unit/plugins/pre_commit/checks/merge_conflict_test.rb @@ -13,9 +13,9 @@ end it "fails if file contains merge conflict" do - check.call([fixture_file('merge_conflict.rb')]).must_equal(<<-EXPECTED) -detected a merge conflict -test/files/merge_conflict.rb:3:<<<<<<< HEAD -EXPECTED + check.call([fixture_file('merge_conflict.rb')]).to_a.must_equal([ + "detected a merge conflict", + "test/files/merge_conflict.rb:3:<<<<<<< HEAD" + ]) end end diff --git a/test/unit/plugins/pre_commit/checks/pry_test.rb b/test/unit/plugins/pre_commit/checks/pry_test.rb index b0af254..27c316f 100644 --- a/test/unit/plugins/pre_commit/checks/pry_test.rb +++ b/test/unit/plugins/pre_commit/checks/pry_test.rb @@ -13,9 +13,9 @@ end it "fails if file contains pry" do - check.call([fixture_file('pry_file.rb')]).must_equal(<<-EXPECTED) -binding.pry found: -test/files/pry_file.rb:3: binding.pry -EXPECTED + check.call([fixture_file('pry_file.rb')]).to_a.must_equal([ + "binding.pry found:", + "test/files/pry_file.rb:3: binding.pry" + ]) end end diff --git a/test/unit/plugins/pre_commit/checks/rspec_focus_test.rb b/test/unit/plugins/pre_commit/checks/rspec_focus_test.rb index 9a1f342..eb3e94d 100644 --- a/test/unit/plugins/pre_commit/checks/rspec_focus_test.rb +++ b/test/unit/plugins/pre_commit/checks/rspec_focus_test.rb @@ -17,7 +17,7 @@ end it 'fails if focus specified on describe, context or example block using any valid syntax' do - check.call([fixture_file('rspec_focus_bad_spec.rb')]).must_equal(<<-EXPECTED) + check.call([fixture_file('rspec_focus_bad_spec.rb')]).to_s.must_equal("\ :focus found in specs: test/files/rspec_focus_bad_spec.rb:2: context 'with old hash syntax', :focus => true do test/files/rspec_focus_bad_spec.rb:3: describe 'focus on describe', :focus => true do @@ -27,8 +27,7 @@ test/files/rspec_focus_bad_spec.rb:11: it 'alerts with focus on example too', focus: true do test/files/rspec_focus_bad_spec.rb:16: context 'with symbols as keys', :focus do test/files/rspec_focus_bad_spec.rb:17: describe 'focus on describe', :focus do -test/files/rspec_focus_bad_spec.rb:18: it 'alerts with focus on example too', :focus do - EXPECTED +test/files/rspec_focus_bad_spec.rb:18: it 'alerts with focus on example too', :focus do") end end diff --git a/test/unit/plugins/pre_commit/checks/ruby_symbol_hashrockets_test.rb b/test/unit/plugins/pre_commit/checks/ruby_symbol_hashrockets_test.rb index 5a3c000..1acb9cc 100644 --- a/test/unit/plugins/pre_commit/checks/ruby_symbol_hashrockets_test.rb +++ b/test/unit/plugins/pre_commit/checks/ruby_symbol_hashrockets_test.rb @@ -13,7 +13,7 @@ end it "fails with invalid" do - result = check.call([fixture_file('wrong_hashrockets.rb')]).must_equal(<<-EXPECTED) + result = check.call([fixture_file('wrong_hashrockets.rb')]).to_s.must_equal("\ detected :symbol => value hashrocket: test/files/wrong_hashrockets.rb:3:gem 'foo', :ref => 'v2.6.0' test/files/wrong_hashrockets.rb:5:{ :@test => \"foo_bar\" } @@ -22,7 +22,6 @@ test/files/wrong_hashrockets.rb:8:{ :test! => \"foo_bar\" } test/files/wrong_hashrockets.rb:9:{ :test? => \"foo_bar\" } test/files/wrong_hashrockets.rb:10:{ :test= => \"foo_bar\" } -test/files/wrong_hashrockets.rb:11:{ :@@test => \"foo_bar\" } -EXPECTED +test/files/wrong_hashrockets.rb:11:{ :@@test => \"foo_bar\" }") end end diff --git a/test/unit/plugins/pre_commit/checks/tabs_test.rb b/test/unit/plugins/pre_commit/checks/tabs_test.rb index 658da88..f686ef2 100644 --- a/test/unit/plugins/pre_commit/checks/tabs_test.rb +++ b/test/unit/plugins/pre_commit/checks/tabs_test.rb @@ -25,9 +25,9 @@ end it "shows error message when an initial tab is found" do - check.call([fixture_file('initial_tab.rb')]).must_equal(<<-EXPECTED) -detected tab before initial space: -test/files/initial_tab.rb:3:\t 'hello' -EXPECTED + check.call([fixture_file('initial_tab.rb')]).to_a.must_equal([ + "detected tab before initial space:", + "test/files/initial_tab.rb:3:\t 'hello'" + ]) end end diff --git a/test/unit/pre-commit/checks/grep_test.rb b/test/unit/pre-commit/checks/grep_test.rb index 1d04509..524cf07 100644 --- a/test/unit/pre-commit/checks/grep_test.rb +++ b/test/unit/pre-commit/checks/grep_test.rb @@ -21,25 +21,24 @@ it "fails if file has pattern" do subject.instance_variable_set(:@pattern, "test") - subject.call([fixture_file('file_with_nb_space.rb')]).must_equal(<<-EXPECTED) -test/files/file_with_nb_space.rb:1:test -EXPECTED + subject.call([fixture_file('file_with_nb_space.rb')]).to_s.must_equal( + "test/files/file_with_nb_space.rb:1:test" + ) end it "fails if file has pattern, even if filename has spaces" do subject.instance_variable_set(:@pattern, "test") - subject.call([fixture_file('filename with spaces.rb')]).must_equal(<<-EXPECTED) -test/files/filename with spaces.rb:1:test -EXPECTED + subject.call([fixture_file('filename with spaces.rb')]).to_s.must_equal( + "test/files/filename with spaces.rb:1:test" + ) end it "adds message to output" do subject.instance_variable_set(:@pattern, "test") - subject.instance_variable_set(:@message, "extra message:\n") - subject.call([fixture_file('file_with_nb_space.rb')]).must_equal(<<-EXPECTED) + subject.instance_variable_set(:@message, "extra message:") + subject.call([fixture_file('file_with_nb_space.rb')]).to_s.must_equal("\ extra message: -test/files/file_with_nb_space.rb:1:test -EXPECTED +test/files/file_with_nb_space.rb:1:test") end it "respects extra_grep" do diff --git a/test/unit/pre-commit/error_list_test.rb b/test/unit/pre-commit/error_list_test.rb new file mode 100644 index 0000000..e0d39e3 --- /dev/null +++ b/test/unit/pre-commit/error_list_test.rb @@ -0,0 +1,31 @@ +require 'minitest_helper' +require 'pre-commit/error_list' + +describe PreCommit::ErrorList do + + it :starts_empty do + result = PreCommit::ErrorList.new() + result.errors.must_equal [] + end + + it :creates_array_from_string do + result = PreCommit::ErrorList.new("message1") + result.errors.must_equal [PreCommit::Line.new("message1")] + end + + it :uses_array_for_errors do + result = PreCommit::ErrorList.new([1,2]) + result.errors.must_equal [1,2] + end + + it :converts_errors_to_strings_in_to_a do + result = PreCommit::ErrorList.new([1,2]) + result.to_a.must_equal ["1","2"] + end + + it :converts_errors_to_string_in_to_s do + result = PreCommit::ErrorList.new([1,2]) + result.to_s.must_equal "1\n2" + end + +end diff --git a/test/unit/pre-commit/line_test.rb b/test/unit/pre-commit/line_test.rb new file mode 100644 index 0000000..74db20a --- /dev/null +++ b/test/unit/pre-commit/line_test.rb @@ -0,0 +1,52 @@ +require 'minitest_helper' +require 'pre-commit/line' + +describe PreCommit::Line do + describe :to_s do + + subject do + PreCommit::Line.new("message1") + end + + it :has_message do + subject.to_s.must_equal("message1") + end + + it :has_file do + subject.file = "path/to/file" + subject.to_s.must_equal("message1\npath/to/file") + end + + it :has_file_without_message do + subject.message = nil + subject.file = "path/to/file" + subject.to_s.must_equal("path/to/file") + end + + it :has_file_and_line do + subject.file = "path/to/file" + subject.line = "4" + subject.to_s.must_equal("message1\npath/to/file:4") + end + + it :has_no_line_or_code_without_file do + subject.line = "4" + subject.code = " some code" + subject.to_s.must_equal("message1") + end + + it :has_file_and_line_and_code do + subject.file = "path/to/file" + subject.line = "4" + subject.code = " some code" + subject.to_s.must_equal("message1\npath/to/file:4: some code") + end + + it :has_file_and_code do + subject.file = "path/to/file" + subject.code = " some code" + subject.to_s.must_equal("message1\npath/to/file: some code") + end + + end +end diff --git a/test/unit/pre-commit/runner_test.rb b/test/unit/pre-commit/runner_test.rb index 3787592..c47e401 100644 --- a/test/unit/pre-commit/runner_test.rb +++ b/test/unit/pre-commit/runner_test.rb @@ -192,7 +192,6 @@ def checks_evaluated(*); []; end pre-commit: Stopping commit because of errors. detected tab before initial space: test.rb:1:\t\t Muahaha - test.rb:2: new blank line at EOF. pre-commit: You can bypass this check using `git commit -n`