From ef24a3e78614e8873d0a0b1b18fa05b08bdfa6e0 Mon Sep 17 00:00:00 2001 From: James Mead Date: Fri, 25 Aug 2017 09:26:28 +0100 Subject: [PATCH 1/4] Convert single line conditionals into multiple lines --- lib/mocha/deprecation.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/mocha/deprecation.rb b/lib/mocha/deprecation.rb index 57ffa6e7d..efaec91ba 100644 --- a/lib/mocha/deprecation.rb +++ b/lib/mocha/deprecation.rb @@ -10,8 +10,12 @@ class << self def warning(message) @messages << message - $stderr.puts "\n*** Mocha deprecation warning: #{message}\n\n" unless mode == :disabled - $stderr.puts caller.join("\n ") if mode == :debug + unless mode == :disabled + $stderr.puts "\n*** Mocha deprecation warning: #{message}\n\n" + end + if mode == :debug + $stderr.puts caller.join("\n ") + end end end From 302b2c321e5b537bb33b7ccbccb4d12e1950e6d5 Mon Sep 17 00:00:00 2001 From: James Mead Date: Fri, 25 Aug 2017 09:33:39 +0100 Subject: [PATCH 2/4] Make deprecation warnings less needy The newlines before and after each deprecation warning and the multiple leading asterisks make the warnings are a bit over the top, especially when lots of them occur within a test suite. --- lib/mocha/deprecation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mocha/deprecation.rb b/lib/mocha/deprecation.rb index efaec91ba..4f55eb7ed 100644 --- a/lib/mocha/deprecation.rb +++ b/lib/mocha/deprecation.rb @@ -11,7 +11,7 @@ class << self def warning(message) @messages << message unless mode == :disabled - $stderr.puts "\n*** Mocha deprecation warning: #{message}\n\n" + $stderr.puts "Mocha deprecation warning: #{message}" end if mode == :debug $stderr.puts caller.join("\n ") From b91f26fd31a73f275e90841239f9006e400538ea Mon Sep 17 00:00:00 2001 From: James Mead Date: Fri, 25 Aug 2017 09:37:19 +0100 Subject: [PATCH 3/4] Include file & line number in deprecation warnings by default Fixes #312. I've also removed the code which displayed the backtrace for deprecation warnings in debug mode, because this is now redundant. --- lib/mocha/deprecation.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/mocha/deprecation.rb b/lib/mocha/deprecation.rb index 4f55eb7ed..c508d7fb5 100644 --- a/lib/mocha/deprecation.rb +++ b/lib/mocha/deprecation.rb @@ -1,4 +1,5 @@ require 'mocha/debug' +require 'mocha/backtrace_filter' module Mocha @@ -11,10 +12,9 @@ class << self def warning(message) @messages << message unless mode == :disabled - $stderr.puts "Mocha deprecation warning: #{message}" - end - if mode == :debug - $stderr.puts caller.join("\n ") + filter = BacktraceFilter.new + location = filter.filtered(caller)[0] + $stderr.puts "Mocha deprecation warning at #{location}: #{message}" end end From 6e404877c1607e95a4a1c666ae88cdee8a19f4d6 Mon Sep 17 00:00:00 2001 From: James Mead Date: Fri, 25 Aug 2017 09:46:01 +0100 Subject: [PATCH 4/4] Remove debug mode for Mocha::Deprecation This is now redundant. --- lib/mocha/deprecation.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/mocha/deprecation.rb b/lib/mocha/deprecation.rb index c508d7fb5..4d7960a49 100644 --- a/lib/mocha/deprecation.rb +++ b/lib/mocha/deprecation.rb @@ -1,4 +1,3 @@ -require 'mocha/debug' require 'mocha/backtrace_filter' module Mocha @@ -20,7 +19,7 @@ def warning(message) end - self.mode = Debug::OPTIONS['debug'] ? :debug : :enabled + self.mode = :enabled self.messages = [] end