Skip to content

Truncate too long lines #24

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/power_assert/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
module PowerAssert
class Context
Value = Struct.new(:name, :value, :lineno, :column)
MAX_LINE_LENGTH = 500

def initialize(base_caller_length)
@fired = false
Expand Down Expand Up @@ -92,12 +93,17 @@ def build_assertion_message(parser, return_values)
map_to = vals.each_with_object({}) do |j, h|
h[j.column.to_s.to_sym] = [l, '|', ' '][i.column <=> j.column]
end
lines << encoding_safe_rstrip(sprintf(fmt, map_to))
line = encoding_safe_rstrip(sprintf(fmt, map_to))
lines << truncate(line, MAX_LINE_LENGTH)
end
end
lines.join("\n")
end

def truncate(line, length)
"#{line[0..length]}#{'...' if line.size > length}"
end

def detect_path(parser, return_values)
return parser.call_paths.flatten.uniq if parser.method_id_set.empty?
all_paths = parser.call_paths
Expand Down