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

Need to step trough Contracts code when debugging #277

Open
md-work opened this issue Nov 30, 2017 · 3 comments
Open

Need to step trough Contracts code when debugging #277

md-work opened this issue Nov 30, 2017 · 3 comments

Comments

@md-work
Copy link

md-work commented Nov 30, 2017

When debugging code, I need to go trough all the Contracts code when stepping into a method guarded by a Contract.

Example:

# ruby -rdebug /home/user/mycode/app.rb
[...]
/home/user/mycode/app.rb:2:method_a()
(rdb:1) step
/usr/lib64/ruby/gems/2.1.0/gems/contracts-0.16.0/lib/contracts/method_handler.rb:111:        engine = current_engine.nearest_decorated_ancestor

Is there any way to hide the Contracts code when stepping into a method?

Maybe something about breakpoints!?

Or maybe there could be a global (not environment) variable to disable contracts, which can be manually set before stepping into a method. E.g.:

(rdb:1) $no_contracts = true
true
(rdb:1) step
/home/user/mycode/app.rb:23:  puts 'Entering method_a'
(rdb:1) $no_contracts = false
false

Simply doing ENV['NO_CONTRACTS'] = '1' doesn't work. Looks like that variable is only evaluated at start, when Ruby goes through Contract ... def method_a ....


Same problem for the byebug debugger. (https://github.com/deivid-rodriguez/byebug)

I know I could set a breakpoint, but it's not always clear where a method call goes (think of polymorphism) And I know I can use the NO_CONTRACTS environment variable. But sadly that's not always a practical solution.

Maybe related: #276

@egonSchiele
Copy link
Owner

Hi,
I am not actively working on this project, but if you send a PR I am happy to discuss it! More info

@nacengineer
Copy link

nacengineer commented Mar 19, 2018

I think this issue should be closed.

I think the bulk of your difficulty is arising more as a result of your testing methods. I believe you could add rspec to this project and leverage it to alleviate a lot of the pain you may be experiencing while using rdebug.

For example, with rspec, you could isolate the method of code you're testing in some unit tests and stub the NO_CONTRACTS constant when you need it to be off.

@md-work
Copy link
Author

md-work commented Mar 20, 2018

@nacengineer
My problem isn't testing, but debugging (actually my tests are working great with Contracts). So please leave this ticket open.

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

3 participants