contracts.ruby icon indicating copy to clipboard operation
contracts.ruby copied to clipboard

ContractError should also show the arguments that caused the error

Open egonSchiele opened this issue 9 years ago • 2 comments

Output:

contracts.ruby (adit/215) $ cat test.rb
require "contracts"
include Contracts

Contract Num => Num
def incr x
  "Sdf"
end

incr(23)
contracts.ruby (adit/215) $ ruby test.rb
/Users/abhargava/contracts.ruby/lib/contracts.rb:45:in `block in <class:Contract>': Contract violation for return value: (ReturnContractError)
        Expected: Num,
        Actual: "Sdf"
        Value guarded in: Object::incr
        With Contract: Num => Num
        All arguments: [23]
        At: test.rb:5
    from /Users/abhargava/contracts.ruby/lib/contracts.rb:155:in `call'
    from /Users/abhargava/contracts.ruby/lib/contracts.rb:155:in `failure_callback'
    from /Users/abhargava/contracts.ruby/lib/contracts/call_with.rb:82:in `call_with'
    from /Users/abhargava/contracts.ruby/lib/contracts/method_handler.rb:138:in `block in redefine_method'
    from test.rb:9:in `<main>'

cc @waterlink @beezee (for issue #215)

egonSchiele avatar Mar 08 '16 00:03 egonSchiele

Oh man, I forgot I need to update the output in the Cucumber tests :/

egonSchiele avatar Mar 08 '16 01:03 egonSchiele

This is a very useful feature

waterlink avatar Mar 08 '16 01:03 waterlink