Skip to content

Conversation

@kateinoigakukun
Copy link
Contributor

This kind of partial loading could happen when underlying gems are
unavailable on some platforms (e.g. io/console/size on WebAssembly), and
so on.

This kind of partial loading could happen when underlying gems are
unavailable on some platforms (e.g. io/console/size on WebAssembly), and
so on.
@kou
Copy link
Member

kou commented Oct 11, 2022

How about preventing partial load in power_assert instead?

e.g.:

diff --git a/lib/power_assert/inspector.rb b/lib/power_assert/inspector.rb
index 50bb646..6a4d8b6 100644
--- a/lib/power_assert/inspector.rb
+++ b/lib/power_assert/inspector.rb
@@ -1,5 +1,8 @@
 require 'power_assert/configuration'
-require 'io/console/size'
+begin
+  require 'io/console/size'
+rescue LoadError
+end
 
 module PowerAssert
   class InspectedValue
@@ -44,7 +47,8 @@ module PowerAssert
     def inspect
       if PowerAssert.configuration.colorize_message
         if PowerAssert.configuration.inspector == :pp
-          width = [IO.console_size[1] - 1 - @indent, 10].max
+          console_width = IO.respond_to?(:console_size) ? IO.console_size[1] : 80
+          width = [console_width - 1 - @indent, 10].max
           IRB::ColorPrinter.pp(@value, '', width)
         else
           IRB::Color.colorize_code(@value.to_s, ignore_error: true)

@k-tsj What do you think about this?

@kateinoigakukun
Copy link
Contributor Author

kateinoigakukun commented Oct 11, 2022

@kou Thank you for quick response :)
It looks better to me and I've confirmed it works well also.

I'm fine with either solution ruby/power_assert#39

@k-tsj
Copy link
Member

k-tsj commented Oct 12, 2022

@kou @kateinoigakukun
It looks good. I'll merge the PR.

@kateinoigakukun
Copy link
Contributor Author

Close in favor of the power_assert solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants