Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backtrace filtering #31

Open
djanowski opened this issue Oct 20, 2015 · 6 comments
Open

Fix backtrace filtering #31

djanowski opened this issue Oct 20, 2015 · 6 comments

Comments

@djanowski
Copy link
Owner

And make it work with e.g. gemsets.

This works: https://gist.github.com/djanowski/afed5a759687921f0569

@britishtea
Copy link
Contributor

Won't $LOAD_PATH often include the files that your code under test is stored in? If that's the case, you'll often end up with an empty stack trace.

@djanowski
Copy link
Owner Author

Not if you require this file before anything else, which is the most common use case, right?

@britishtea
Copy link
Contributor

That's true (though I know of at least one project where I'd end up with empty backtraces 😊).

Perhaps this is a good use case for Ruby's awk inheritance: BEGIN { $ORIGINAL_LOAD_PATH = $LOAD_PATH.dup }.

@djanowski
Copy link
Owner Author

The constant is created when the module is required, and the array is the result of adding Gem.path to $LOAD_PATH. So further modifications to $LOAD_PATH won't be a problem. Is that what you mean?

@britishtea
Copy link
Contributor

Yes.

Consider the / my typical Rakefile:

$LOAD_PATH.unshift File.expand_path("./lib")

require "cutest" # or require "test_helper"
require "my_library"

task(:foo) { MyLibrary.do_something! }
task(:bar) { MyLibrary.do_something_else! }
task(:test) { Cutest.run(FileList["test/*_test.rb"]) }

In such cases you'd end up with an empty backtrace and it will not be obvious why. Capturing the $LOAD_PATH in a BEGIN block avoids this at least partially: it will execute before anything else does.

Another situation where you'd end up with an empty backtrace is running a single test file using ruby -I lib test/my_library_test.rb. A BEGIN block won't avoid this, unfortunately.

@djanowski
Copy link
Owner Author

Yes, it's true, this is opinionated based on the fact that I never include my application's directories in $LOAD_PATH. I always use require for libraries, require_relative for code inside my app.

Maybe just using Gem.path is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants