Skip to content

Commit

Permalink
Remove warnings
Browse files Browse the repository at this point in the history
When running tests locally, multiple warnings were being emitted. A lot
of these warnings have to do with the fact that we are overriding core
methods in RSpec, and whenever you override a method, Ruby feels the
need to inform you. To get around this, we need to use the same trick
that we already use for AugmentedMatcher: we create a module on the fly
and `prepend` it to the class or module in question. Sometimes we might
even need to `prepend` to the singleton class. Also, this commit adds
WarningsLogger so that we can track when this happens again.
  • Loading branch information
mcmire committed Feb 14, 2021
1 parent f2f2903 commit b2e82a1
Show file tree
Hide file tree
Showing 25 changed files with 405 additions and 305 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
gem "rubocop"
gem "warnings_logger"

gemspec
8 changes: 7 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ require_relative "support/current_bundle"

begin
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
RSpec::Core::RakeTask.new(spec: :before_spec) do |config|
config.verbose = true
end
rescue LoadError
task :spec do
appraisal = SuperDiff::CurrentBundle.instance.latest_appraisal
Expand All @@ -22,3 +24,7 @@ task :default do
exec "appraisal #{appraisal.name} rake --trace"
end
end

task :before_spec do
FileUtils.rm_rf(File.expand_path("./spec/tmp", __dir__))
end
1 change: 1 addition & 0 deletions gemfiles/no_rails_rspec_gte_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
gem "rubocop"
gem "warnings_logger"
gem "rspec", ">= 3.10", "< 4"

gemspec path: "../"
2 changes: 2 additions & 0 deletions gemfiles/no_rails_rspec_gte_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ GEM
thor (1.0.1)
trollop (1.16.2)
unicode-display_width (1.7.0)
warnings_logger (0.1.1)

PLATFORMS
ruby
Expand All @@ -76,6 +77,7 @@ DEPENDENCIES
rspec (>= 3.10, < 4)
rubocop
super_diff!
warnings_logger

BUNDLED WITH
2.1.4
1 change: 1 addition & 0 deletions gemfiles/no_rails_rspec_lt_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
gem "rubocop"
gem "warnings_logger"
gem "rspec", "< 3.10"

gemspec path: "../"
2 changes: 2 additions & 0 deletions gemfiles/no_rails_rspec_lt_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ GEM
thor (1.0.1)
trollop (1.16.2)
unicode-display_width (1.7.0)
warnings_logger (0.1.1)

PLATFORMS
ruby
Expand All @@ -76,6 +77,7 @@ DEPENDENCIES
rspec (< 3.10)
rubocop
super_diff!
warnings_logger

BUNDLED WITH
2.1.4
1 change: 1 addition & 0 deletions gemfiles/rails_5_0_rspec_gte_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
gem "rubocop"
gem "warnings_logger"
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "activerecord", "~> 5.0.0"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails_5_0_rspec_gte_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ GEM
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.7.0)
warnings_logger (0.1.1)

PLATFORMS
ruby
Expand All @@ -146,6 +147,7 @@ DEPENDENCIES
rubocop
sqlite3 (~> 1.3.6)
super_diff!
warnings_logger

BUNDLED WITH
2.1.4
1 change: 1 addition & 0 deletions gemfiles/rails_5_0_rspec_lt_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
gem "rubocop"
gem "warnings_logger"
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "activerecord", "~> 5.0.0"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails_5_0_rspec_lt_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ GEM
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.7.0)
warnings_logger (0.1.1)

PLATFORMS
ruby
Expand All @@ -146,6 +147,7 @@ DEPENDENCIES
rubocop
sqlite3 (~> 1.3.6)
super_diff!
warnings_logger

BUNDLED WITH
2.1.4
1 change: 1 addition & 0 deletions gemfiles/rails_5_1_rspec_gte_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
gem "rubocop"
gem "warnings_logger"
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "activerecord", "~> 5.1.0"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails_5_1_rspec_gte_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ GEM
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.7.0)
warnings_logger (0.1.1)

PLATFORMS
ruby
Expand All @@ -146,6 +147,7 @@ DEPENDENCIES
rubocop
sqlite3 (~> 1.3.6)
super_diff!
warnings_logger

BUNDLED WITH
2.1.4
1 change: 1 addition & 0 deletions gemfiles/rails_5_1_rspec_lt_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
gem "rubocop"
gem "warnings_logger"
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "activerecord", "~> 5.1.0"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails_5_1_rspec_lt_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ GEM
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.7.0)
warnings_logger (0.1.1)

PLATFORMS
ruby
Expand All @@ -146,6 +147,7 @@ DEPENDENCIES
rubocop
sqlite3 (~> 1.3.6)
super_diff!
warnings_logger

BUNDLED WITH
2.1.4
1 change: 1 addition & 0 deletions gemfiles/rails_5_2_rspec_gte_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
gem "rubocop"
gem "warnings_logger"
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "activerecord", "~> 5.2.0"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails_5_2_rspec_gte_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ GEM
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.7.0)
warnings_logger (0.1.1)

PLATFORMS
ruby
Expand All @@ -146,6 +147,7 @@ DEPENDENCIES
rubocop
sqlite3 (~> 1.3.6)
super_diff!
warnings_logger

BUNDLED WITH
2.1.4
1 change: 1 addition & 0 deletions gemfiles/rails_5_2_rspec_lt_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
gem "rubocop"
gem "warnings_logger"
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "activerecord", "~> 5.2.0"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails_5_2_rspec_lt_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ GEM
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.7.0)
warnings_logger (0.1.1)

PLATFORMS
ruby
Expand All @@ -146,6 +147,7 @@ DEPENDENCIES
rubocop
sqlite3 (~> 1.3.6)
super_diff!
warnings_logger

BUNDLED WITH
2.1.4
1 change: 1 addition & 0 deletions gemfiles/rails_6_0_rspec_gte_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
gem "rubocop"
gem "warnings_logger"
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "activerecord", "~> 6.0"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails_6_0_rspec_gte_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ GEM
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.7.0)
warnings_logger (0.1.1)
zeitwerk (2.4.1)

PLATFORMS
Expand All @@ -146,6 +147,7 @@ DEPENDENCIES
rubocop
sqlite3 (~> 1.4.0)
super_diff!
warnings_logger

BUNDLED WITH
2.1.4
1 change: 1 addition & 0 deletions gemfiles/rails_6_0_rspec_lt_3_10.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
gem "rake"
gem "rubocop"
gem "warnings_logger"
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "activerecord", "~> 6.0"
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/rails_6_0_rspec_lt_3_10.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ GEM
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.7.0)
warnings_logger (0.1.1)
zeitwerk (2.4.1)

PLATFORMS
Expand All @@ -148,6 +149,7 @@ DEPENDENCIES
rubocop
sqlite3 (~> 1.4.0)
super_diff!
warnings_logger

BUNDLED WITH
2.1.4
16 changes: 16 additions & 0 deletions lib/super_diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,20 @@ def self.time_like?(value)
(value.respond_to?(:acts_like_time?) && value.acts_like_time?) ||
value.is_a?(Time)
end

def self.insert_overrides(target_module, mod = nil, &block)
if mod
target_module.prepend(mod)
else
target_module.prepend(Module.new(&block))
end
end

def self.insert_singleton_overrides(target_module, mod = nil, &block)
if mod
target_module.singleton_class.prepend(mod)
else
target_module.singleton_class.prepend(Module.new(&block))
end
end
end
Loading

0 comments on commit b2e82a1

Please sign in to comment.