Skip to content

A more readable error message for the RSpec split by examples JSON report (remove ANSI codes that are not human-readable)#275

Merged
ArturT merged 3 commits intomasterfrom
no-color-formatting-in-rspec-test-examples-report
Oct 22, 2024
Merged

A more readable error message for the RSpec split by examples JSON report (remove ANSI codes that are not human-readable)#275
ArturT merged 3 commits intomasterfrom
no-color-formatting-in-rspec-test-examples-report

Conversation

@ArturT
Copy link
Copy Markdown
Member

@ArturT ArturT commented Oct 21, 2024

Related

RSpec split by examples feature: https://docs.knapsackpro.com/ruby/split-by-test-examples/

Issue:

Description

When an error occurs while loading slow test files, the RSpec JSON report contains errors mixed with ANSI codes. By default, RSpec produces colored output.

We use the --no-color option to remove the ANSI codes and make the error message more readable.

Checklist reminder

  • You added the changes to the UNRELEASED section of the CHANGELOG.md, including the needed bump (ie, patch, minor, major)
  • You follow the architecture outlined below for RSpec in Queue Mode, which is a work in progress (feel free to propose changes):
    • Pure: lib/knapsack_pro/pure/queue/rspec_pure.rb contains pure functions that are unit tested.
    • Extension: lib/knapsack_pro/extensions/rspec_extension.rb encapsulates calls to RSpec internals and is integration and e2e tested.
    • Runner: lib/knapsack_pro/runners/queue/rspec_runner.rb invokes the pure code and the extension to produce side effects, which are integration and e2e tested.

@ArturT ArturT requested a review from shadre October 21, 2024 19:59
@ArturT ArturT merged commit addabce into master Oct 22, 2024
@ArturT ArturT deleted the no-color-formatting-in-rspec-test-examples-report branch October 22, 2024 11:29
@fabianoarruda
Copy link
Copy Markdown

Hey @ArturT just to let you know, this change introduced a problem for me. I use Knapsack Pro with Gitlab, and to make it output colors in jobs, I always need to attach --force-color. Here is how I use the command:

bin/rails "knapsack_pro:queue:rspec[--force-color --format documentation --format RspecJunitFormatter --out tmp/rspec-$CI_NODE_INDEX.xml]"

This has been working fine with knapsack 7.9, but after upgrading to v8.0, The job fails with this error:

Please only use one of --force-color and --no-color`

So I had to remove --force-color to make it work again, but now I don't get color output anymore for rspec.

Is there any workaround for this? Maybe you can make --no-color optional in knapsack pro?

@ArturT
Copy link
Copy Markdown
Member Author

ArturT commented Mar 12, 2025

@fabianoarruda Thanks for reporting this. It's related to recent changes in:

As a workaround, please could you add --force-color to the .rspec file instead of passing it to the Knapsack Pro command? It should help.

I'll get back to you if we have a fix.

@fabianoarruda
Copy link
Copy Markdown

That's it! Adding it to .rspec did the trick for me. Thanks @ArturT

@3v0k4
Copy link
Copy Markdown
Contributor

3v0k4 commented Apr 17, 2025

Hi @fabianoarruda.

The latest version (8.1.2) should fix the issue and make the workaround not required anymore.

Could you please give it a try?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants