power_assert icon indicating copy to clipboard operation
power_assert copied to clipboard

Truncate too long lines

Open uiur opened this issue 8 years ago • 1 comments

large_object.inspect returns a very long message. It makes an assertion message hard to read.

In Rails, ActionDispatch::TestResponse is large and its inspect is over 10000 characters (in my environment)

    assert { @response.status == status_code(:forbidden) }
             |                |  |
             |                |  403
             |                false
             #<ActionDispatch::TestResponse:0x00007fc8bd704eb8 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x00007fc8bd704e18>, @header={"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff", "Content-Type"=>"application/json; charset=utf-8", "ETag"=>"W/\"c3ab8ff13720e8ad9047dd39466b3c89\"", "Cache-Control"=>"max-age=0, private, must-revalidate", "X-Request-Id"=>"3c9a5c24-962d-4e2e-9d55-3d4f3fa5c0c0", "X-Runtime"=>"0.078733", "Content-Length"=>"6"}, @stream=#<ActionDispatch::Response::Buffer:0x00007fc8bd704da0 @response=#<ActionDispatch::TestResponse:0x00007fc8bd704eb8 ...>, @buf=["foobar"], @closed=false, @str_body=nil>, @status=200, @cv=#<MonitorMixin::ConditionVariable:0x00007fc8bd704d78 @monitor=#<ActionDispatch::TestResponse:0x00007fc8bd704eb8 ...>, @cond=#<Thread::ConditionVariable:0x00007fc8bd704d50>>, @committed=false, @sending=false, @sent=false, @cache_control={:max_age=>"0", :private=>true, :must_revalidate=>true}...

This change truncates each line and make messages more readable.

How do you think?

uiur avatar Dec 03 '17 03:12 uiur

Thanks for your PR.

I am neutral on your proposal. However, I have the following concerns.

  • Should this feature be enabled by default? It may remove useful information from output message.
  • Should the maximum width be statically decided?

Let me think about it for a while.

BTW, power_assert provides _use_pp option. It is still an experimental feature (so the option name has _ prefix), but I will promote it as an official one. It may help you.

require 'power_assert'

PowerAssert.configure do |c|
  c._use_pp = true
end

k-tsj avatar Dec 10 '17 03:12 k-tsj