From 96c783b4b60fbf1e45c6c56cd66e3a02ee617bc6 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 17 Oct 2013 16:29:14 +1100 Subject: [PATCH] remove old caller filter files --- benchmarks/caller.rb | 81 --------------------------- lib/rspec/core/caller_filter.rb | 55 ------------------ spec/rspec/core/caller_filter_spec.rb | 43 -------------- spec/support/helper_methods.rb | 28 --------- 4 files changed, 207 deletions(-) delete mode 100644 benchmarks/caller.rb delete mode 100644 lib/rspec/core/caller_filter.rb delete mode 100644 spec/rspec/core/caller_filter_spec.rb diff --git a/benchmarks/caller.rb b/benchmarks/caller.rb deleted file mode 100644 index 6d160c8334..0000000000 --- a/benchmarks/caller.rb +++ /dev/null @@ -1,81 +0,0 @@ -$LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__)) - -require 'benchmark' -require 'rspec/support/caller_filter' - -n = 10000 - -puts "#{n} times - ruby #{RUBY_VERSION}" -puts - -puts "* Using a chunked fetch is quicker than the old method of array-access." -Benchmark.bm(20) do |bm| - bm.report("CallerFilter") do - n.times do - RSpec::CallerFilter.first_non_rspec_line - end - end - - bm.report("Direct caller access") do - n.times do - caller(1)[4] - end - end -end - -puts -puts "* Chunking fetches of caller adds a ~17% overhead." -Benchmark.bm(20) do |bm| - bm.report("Chunked") do - n.times do - caller(1, 2) - caller(3, 2) - caller(5, 2) - end - end - - bm.report("All at once") do - n.times do - caller(1, 6) - end - end -end - -puts -puts "* `caller` scales linearly with length parameter." -Benchmark.bm(20) do |bm| - (1..10).each do |x| - bm.report(x) do - n.times do - caller(1, x) - end - end - end -end - - -# > ruby benchmarks/caller.rb -# 10000 times - ruby 2.0.0 -# -# * Using a chunked fetch is quicker than the old method of array-access. -# user system total real -# CallerFilter 0.140000 0.010000 0.150000 ( 0.145381) -# Direct caller access 0.170000 0.000000 0.170000 ( 0.180610) -# -# * Chunking fetches of caller adds a ~17% overhead. -# user system total real -# Chunked 0.150000 0.000000 0.150000 ( 0.181162) -# All at once 0.130000 0.010000 0.140000 ( 0.138732) -# -# * `caller` scales linearly with length parameter. -# user system total real -# 1 0.030000 0.000000 0.030000 ( 0.035000) -# 2 0.050000 0.000000 0.050000 ( 0.059879) -# 3 0.080000 0.000000 0.080000 ( 0.098468) -# 4 0.090000 0.010000 0.100000 ( 0.097619) -# 5 0.110000 0.000000 0.110000 ( 0.126220) -# 6 0.130000 0.000000 0.130000 ( 0.136739) -# 7 0.150000 0.000000 0.150000 ( 0.159055) -# 8 0.160000 0.010000 0.170000 ( 0.172416) -# 9 0.180000 0.000000 0.180000 ( 0.203038) -# 10 0.200000 0.000000 0.200000 ( 0.210551) diff --git a/lib/rspec/core/caller_filter.rb b/lib/rspec/core/caller_filter.rb deleted file mode 100644 index a3c29dd4e1..0000000000 --- a/lib/rspec/core/caller_filter.rb +++ /dev/null @@ -1,55 +0,0 @@ -module RSpec - # Consistent implementation for "cleaning" the caller method to strip out - # non-rspec lines. This enables errors to be reported at the call site in - # the code using the library, which is far more useful than the particular - # internal method that raised an error. - class CallerFilter - - RSPEC_LIBS = %w[ - core - mocks - expectations - matchers - rails - ] - - ADDITIONAL_TOP_LEVEL_FILES = %w[ autorun ] - - LIB_REGEX = %r{/lib/rspec/(#{(RSPEC_LIBS + ADDITIONAL_TOP_LEVEL_FILES).join('|')})(\.rb|/)} - - if RUBY_VERSION >= '2.0.0' - def self.first_non_rspec_line - # `caller` is an expensive method that scales linearly with the size of - # the stack. The performance hit for fetching it in chunks is small, - # and since the target line is probably near the top of the stack, the - # overall improvement of a chunked search like this is significant. - # - # See benchmarks/caller.rb for measurements. - - # Initial value here is mostly arbitrary, but is chosen to give good - # performance on the common case of creating a double. - increment = 5 - i = 1 - line = nil - - while !line - stack = caller(i, increment) - raise "No non-lib lines in stack" unless stack - - line = stack.find { |l| l !~ LIB_REGEX } - - i += increment - increment *= 2 # The choice of two here is arbitrary. - end - - line - end - else - # Earlier rubies do not support the two argument form of `caller`. This - # fallback is logically the same, but slower. - def self.first_non_rspec_line - caller.find { |line| line !~ LIB_REGEX } - end - end - end -end diff --git a/spec/rspec/core/caller_filter_spec.rb b/spec/rspec/core/caller_filter_spec.rb deleted file mode 100644 index c5e5f536a2..0000000000 --- a/spec/rspec/core/caller_filter_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -require 'spec_helper' - -module RSpec - describe CallerFilter do - def ruby_files_in_lib(lib) - # http://rubular.com/r/HYpUMftlG2 - path = $LOAD_PATH.find { |p| p.match(/\/rspec-#{lib}(-[a-f0-9]+)?\/lib/) } - - Dir["#{path}/**/*.rb"].sort.tap do |files| - # Just a sanity check... - expect(files.count).to be > 10 - end - end - - describe "the filtering regex" do - def unmatched_from(files) - files.reject { |file| file.match(CallerFilter::LIB_REGEX) } - end - - %w[ core mocks expectations ].each do |lib| - it "matches all ruby files in rspec-#{lib}" do - files = ruby_files_in_lib(lib) - - # We don't care about this file -- it only has a single require statement - # and won't show up in any backtraces. - files.reject! { |file| file.end_with?('lib/rspec-expectations.rb') } - - expect(unmatched_from files).to eq([]) - end - end - - it "does not match other ruby files" do - files = %w[ - /path/to/lib/rspec/some-extension/foo.rb - /path/to/spec/rspec/core/some_spec.rb - ] - - expect(unmatched_from files).to eq(files) - end - end - end -end - diff --git a/spec/support/helper_methods.rb b/spec/support/helper_methods.rb index 3ba09f196a..4b6abe8705 100644 --- a/spec/support/helper_methods.rb +++ b/spec/support/helper_methods.rb @@ -23,32 +23,4 @@ def safely end end - def expect_deprecation_with_call_site(file, line) - expect(RSpec.configuration.reporter).to receive(:deprecation) do |options| - expect(options[:call_site]).to include([file, line].join(':')) - end - end - - def allow_deprecation - allow(RSpec.configuration.reporter).to receive(:deprecation) - end - - def expect_warning_without_call_site(expected = //) - expect(::Kernel).to receive(:warn) do |message| - expect(message).to match expected - expect(message).to_not match(/Called from/) - end - end - - def expect_warning_with_call_site(file, line, expected = //) - expect(::Kernel).to receive(:warn) do |message| - expect(message).to match expected - expect(message).to match(/Called from #{file}:#{line}/) - end - end - - def allow_warning - allow(::Kernel).to receive(:warn) - end - end