Skip to content

Commit c7d5910

Browse files
committed
Issue #215: ContractError should also show the arguments that caused the error
1 parent f689c58 commit c7d5910

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/contracts.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def to_s
111111
("#{args} => #{ret}").gsub("Contracts::Builtin::", "")
112112
end
113113

114-
# Given a hash, prints out a failure message.
114+
# Given a hash, returns a failure message.
115115
# This function is used by the default #failure_callback method
116116
# and uses the hash passed into the failure_callback method.
117117
def self.failure_msg(data)
@@ -130,6 +130,7 @@ def self.failure_msg(data)
130130
Actual: #{data[:arg].inspect}
131131
Value guarded in: #{data[:class]}::#{method_name}
132132
With Contract: #{data[:contracts]}
133+
All arguments: #{data[:args].inspect}
133134
At: #{position} }
134135
end
135136

lib/contracts/call_with.rb

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def call_with(this, *args, &blk)
2323
:contracts => self,
2424
:arg_pos => i+1,
2525
:total_args => args.size,
26+
:args => args,
2627
:return_value => false)
2728
end
2829

@@ -56,6 +57,7 @@ def call_with(this, *args, &blk)
5657
:contracts => self,
5758
:arg_pos => i-1,
5859
:total_args => args.size,
60+
:args => args,
5961
:return_value => false)
6062
end
6163

@@ -82,6 +84,7 @@ def call_with(this, *args, &blk)
8284
:class => klass,
8385
:method => method,
8486
:contracts => self,
87+
:args => args,
8588
:return_value => true)
8689
end
8790

0 commit comments

Comments
 (0)