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

Breaks with awesome print #35

Closed
softwaregravy opened this issue Apr 27, 2019 · 6 comments
Closed

Breaks with awesome print #35

softwaregravy opened this issue Apr 27, 2019 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@softwaregravy
Copy link

Great gem. Just gave it a try. Unfortunately seems to break the awesome print. I can deterministically recreate the issue by adding and removing them gem from my rails project.

The line of code is

ap core_transactions

backtrace

     TypeError:
       no implicit conversion of Hash into String
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/colored-1.2/lib/colored.rb:70:in `colorize'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/colorize-0.8.1/lib/colorize/class_methods.rb:98:in `block (2 levels) in color_methods'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/colorize.rb:20:in `colorize'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/formatters/array_formatter.rb:128:in `generic_prefix'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/formatters/array_formatter.rb:57:in `array_prefix'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/formatters/array_formatter.rb:50:in `block in generate_printable_array'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/formatters/array_formatter.rb:49:in `map'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/formatters/array_formatter.rb:49:in `with_index'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/formatters/array_formatter.rb:49:in `generate_printable_array'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/formatters/array_formatter.rb:40:in `multiline_array'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/formatters/array_formatter.rb:32:in `simple_array'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/formatters/array_formatter.rb:20:in `format'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/formatter.rb:71:in `awesome_array'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/formatter.rb:26:in `format'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/inspector.rb:115:in `unnested'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/inspector.rb:74:in `awesome'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/core_ext/kernel.rb:10:in `ai'
     # /Users/xxxxx/.rvm/gems/ruby-2.6.2@crimson/gems/awesome_print-1.8.0/lib/awesome_print/core_ext/kernel.rb:20:in `ap'
     # ./spec/workers/remove_transactions_worker_spec.rb:12:in `block (2 levels) in <main>'
@softwaregravy
Copy link
Author

I also tried to add colorize and cri separately, both worked fine, so the issue does appear to be in the rspec_n gem somewhere

@roberts1000 roberts1000 self-assigned this Apr 28, 2019
@roberts1000 roberts1000 added the bug Something isn't working label Apr 28, 2019
@roberts1000 roberts1000 modified the milestones: Next Release, 1.2.1 Apr 28, 2019
@roberts1000
Copy link
Owner

Thanks for the bug report. I've been able to reproduce the problem and I'll work on a fix.

@roberts1000
Copy link
Owner

roberts1000 commented Apr 29, 2019

@softwaregravy I see the problem. The cri gem uses another coloring gem called colored. So...

  1. Bundler loads rspec_n in your Rails project.
  2. rspec_n loads cri.
  3. cri loads colored.
  4. awesome_print knows about the colorize gem (based on this comment in the awesome_print code) , but it doesn't appear to have compatibility with colored (since we're getting an error). If you add colored directly to the Gemfile in your Rails project (after the awesome_print gem) you'll get the same error.
  5. colored defines colorize, green, red, etc... methods on String which cause problems for awesome_print.

You have a couple options:

  1. [Not recommended] List rspec_n before awesome_print in your Gemfile. This will let awesome_print override methods from colored when your Rails environment starts. You probably don't want this kind of dependency in your Gemfile though ....

  2. [Recommended] There's no runtime benefit, to your Rails app, in having rspec_n in your Gemfile. You're just adding files to your project's $LOAD_PATH and taking a performance hit. I would take rspec_n out of the Gemfile, however, if you want to keep it in, make sure your use the require: false option so Bundler won't actually require the rspec_n files into your Rails app:

    gem 'rspec_n', require: false

    I'll update the README to point this out (via issue Add instructions for usage in a Gemfile #36). I also opened an issue on the cri board colored breaks awesome_print denisdefreyne/cri#89

@roberts1000
Copy link
Owner

roberts1000 commented Apr 29, 2019

I'm going to close this issue. Feel free to reopen if you think there's more to the story. Thanks again for submitting.

@roberts1000 roberts1000 removed this from the Next Release milestone Apr 29, 2019
@roberts1000
Copy link
Owner

roberts1000 commented Apr 29, 2019

The author of the cri gem released a new version that removes the dependency on colored so now there's a third option: bundle update rspec_n.

@softwaregravy
Copy link
Author

softwaregravy commented May 2, 2019

Thank you so much for digging into this, and so fast. Really appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants