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

custom error formatter for KeywordArgs #246

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
adjust error formatting just for cucumber specs
  • Loading branch information
mindreframer committed Dec 21, 2016
commit c65e92f224ac79fff1d8d3fd2f899ae47793421d
33 changes: 15 additions & 18 deletions lib/contracts/error_formatter.rb
Original file line number Diff line number Diff line change
@@ -21,15 +21,12 @@ def initialize(data)
end

def message
s = []
s << header
s << "Expected: #{expected}"
s << "Actual: #{data[:arg].inspect}"
s << "Value guarded in: #{data[:class]}::#{method_name}"
s << "With Contract: #{data[:contracts]}"
s << "At: #{position}"

s.join("\n")
%{#{header}
Expected: #{expected},
Actual: #{data[:arg].inspect}
Value guarded in: #{data[:class]}::#{method_name}
With Contract: #{data[:contracts]}
At: #{position} }
end

private
@@ -57,15 +54,15 @@ def method_name
class KeywordArgsErrorFormatter < DefaultErrorFormatter
def message
s = []
s << header
s << "Expected: #{expected}"
s << "Actual: #{data[:arg].inspect}"
s << "Missing Contract: #{missing_contract_info}" if !missing_contract_info.empty?
s << "Invalid Args: #{invalid_args_info}" if !invalid_args_info.empty?
s << "Missing Args: #{missing_args_info}" if !missing_args_info.empty?
s << "Value guarded in: #{data[:class]}::#{method_name}"
s << "With Contract: #{data[:contracts]}"
s << "At: #{position}"
s << "#{header}"
s << " Expected: #{expected}"
s << " Actual: #{data[:arg].inspect}"
s << " Missing Contract: #{missing_contract_info}" if !missing_contract_info.empty?
s << " Invalid Args: #{invalid_args_info}" if !invalid_args_info.empty?
s << " Missing Args: #{missing_args_info}" if !missing_args_info.empty?
s << " Value guarded in: #{data[:class]}::#{method_name}"
s << " With Contract: #{data[:contracts]}"
s << " At: #{position} "

s.join("\n")
end