serpapi / turbo_tests

Run RSpec tests on multiple cores. Like parallel_tests but with incremental summarized output. Originally extracted from the Discourse and Rubygems source code.
https://rubygems.org/gems/turbo_tests
MIT License
173 stars 26 forks source link

Usage with fuubar #23

Open mollerhoj opened 2 years ago

mollerhoj commented 2 years ago

I use the fuubar formatter.

I just wanted to show a hack to get the formatter to work with this gem:

In Reporter#add, add the following hack:

       ...
        @formatters << formatter_class.new(output)

        if name == "Fuubar"
          output = `bundle exec rspec --dry-run | grep 'examples, 0 failures'`
          example_count = output.split(" ").first.to_i
          delegate_to_formatters(:start, RSpec::Core::Notifications::StartNotification.new(example_count))
        end

        @formatters
        ...

This will send the required StartNotification to fuubar.

Now we can run the specs with bundle exec turbo_tests -f Fuubar -r 'fuubar' to get nicely formatted output.

ilyazub commented 1 year ago

Thanks, @mollerhoj!

Confirming it works well even when delegate_to_formatters(:start, ...) is called for all formatters (without name == "Fuubar" condition).

Not sure where to add this in documentation. Maybe some section with workarounds.

P.S. I find JSON formatter more reliable for extracting the number of total examples.

json_summary = JSON.parse(`#{ENV["BUNDLE_BIN_PATH"]} exec rspec --dry-run --format json -- #{@files.join(" ")}`, symbolize_names: true)
total_examples_count = json_summary.dig(:summary, :example_count) || 0
Mayurifag commented 1 year ago

Thanks for useful information! Yea, I think, this should be added to README file. I mean, simplecov and fuubar are kinda must have and it would be very handy to have all needed info about them in single place right after putting gem to Gemfile. 😄

ilyazub commented 1 year ago

@Mayurifag Thank you for your feedback.

@mollerhoj, @Mayurifag please open a PR with a README update. :-)