rspec-expectations icon indicating copy to clipboard operation
rspec-expectations copied to clipboard

Slow sequential And

Open Lukom opened this issue 2 years ago • 3 comments

Subject of the issue

It appears that if And compounds are sequential then tests are running for a long time. Eg.:

expect('qwe').
  to include('asd').
    and(include('asd')).
    and(include('asd')).
    and(include('asd')).
    and(include('asd')).
    and(include('asd')).
    and(include('asd')).
    and(include('asd')).
    and(include('asd')).
    and(include('asd')).
    and(include('asd')).
    and(include('asd')).
    and(include('asd')).
    and(include('asd'))

this is running on my computer for 15 seconds, and each additional condition doubles the previous duration.

It's not a problem with nested and:

expect('qwe').
  to include('asd').
    and include('asd').
      and include('asd').
        and include('asd').
          and include('asd').
            and include('asd').
              and include('asd').
                and include('asd').
                  and include('asd').
                    and include('asd').
                      and include('asd').
                        and include('asd').
                          and include('asd').
                            and include('asd')

This is instant. But I prefer the previous sequential approach as it doesn't increase nesting level.

Your environment

  • Ruby version: 2.6.3
  • rspec-expectations version: 3.10.1

Lukom avatar Oct 27 '21 23:10 Lukom