Skip to content

Instantly share code, notes, and snippets.

@xaviershay
Created August 10, 2013 16:02
Show Gist options
  • Save xaviershay/6200981 to your computer and use it in GitHub Desktop.
Save xaviershay/6200981 to your computer and use it in GitHub Desktop.
Diff of `rspec-mocks` to remove circular dependency. Could be a problem if another rspec library calls into mocks then the line returned would be in the that library. This would be consistent with the behaviour that was here before `CleanCaller` was introduced though, and presumably if other libraries want to remove themselves from a trace that'…
diff --git a/lib/rspec/mocks/clean_caller.rb b/lib/rspec/mocks/clean_caller.rb
index dc52c87..ed2a72d 100644
--- a/lib/rspec/mocks/clean_caller.rb
+++ b/lib/rspec/mocks/clean_caller.rb
@@ -6,21 +6,10 @@ module RSpec
# the code using the library, which is far more useful than the particular
# internal method that raised an error.
class CleanCaller
-
- # This list is an unfortunate dependency on other RSpec core libraries.
- # It would be nice if this was not needed.
- RSPEC_LIBS = %w[
- core
- mocks
- expectations
- matchers
- rails
- ]
+ LIB_DIR = File.dirname(File.expand_path('..', __FILE__))
def self.first_non_rspec_line_in_caller
- caller.find { |line|
- line !~ %r{/lib/rspec/(#{RSPEC_LIBS.join('|')})(\.rb|/)}
- }
+ caller.find { |line| !line.start_with?(LIB_DIR) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment