egonSchiele / contracts.ruby

Contracts for Ruby.
http://egonschiele.github.com/contracts.ruby
BSD 2-Clause "Simplified" License
1.44k stars 82 forks source link

Need to step trough Contracts code when debugging #277

Open md-work opened 6 years ago

md-work commented 6 years ago

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 commented 6 years ago

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

nacengineer commented 6 years ago

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 commented 6 years ago

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