From c7d591066cef0b078b951394719f37fa6f63f2de Mon Sep 17 00:00:00 2001 From: Aditya Bhargava Date: Mon, 7 Mar 2016 16:30:49 -0800 Subject: [PATCH] Issue #215: ContractError should also show the arguments that caused the error --- lib/contracts.rb | 3 ++- lib/contracts/call_with.rb | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/contracts.rb b/lib/contracts.rb index 2e6e9ea..3e1bfc4 100644 --- a/lib/contracts.rb +++ b/lib/contracts.rb @@ -111,7 +111,7 @@ def to_s ("#{args} => #{ret}").gsub("Contracts::Builtin::", "") end - # Given a hash, prints out a failure message. + # Given a hash, returns a failure message. # This function is used by the default #failure_callback method # and uses the hash passed into the failure_callback method. def self.failure_msg(data) @@ -130,6 +130,7 @@ def self.failure_msg(data) Actual: #{data[:arg].inspect} Value guarded in: #{data[:class]}::#{method_name} With Contract: #{data[:contracts]} + All arguments: #{data[:args].inspect} At: #{position} } end diff --git a/lib/contracts/call_with.rb b/lib/contracts/call_with.rb index 29a609f..ae28857 100644 --- a/lib/contracts/call_with.rb +++ b/lib/contracts/call_with.rb @@ -23,6 +23,7 @@ def call_with(this, *args, &blk) :contracts => self, :arg_pos => i+1, :total_args => args.size, + :args => args, :return_value => false) end @@ -56,6 +57,7 @@ def call_with(this, *args, &blk) :contracts => self, :arg_pos => i-1, :total_args => args.size, + :args => args, :return_value => false) end @@ -82,6 +84,7 @@ def call_with(this, *args, &blk) :class => klass, :method => method, :contracts => self, + :args => args, :return_value => true) end