rspec/rspec-core

Test failure with Ruby 3.1

kzkn opened this issue · 2 comments

kzkn commented

Subject of the issue

spec/integration/spec_file_load_errors_spec.rb fails when run on Ruby 3.1.

Your environment

  • Ruby version: 3.1.3
  • rspec-core version: HEAD of main branch ec0fe5d

Steps to reproduce

  • checkout
  • rspec spec/

Expected behavior

  • Pass test

Actual behavior

  • Fail test with the output below
Failures:

  1) Spec file load errors nicely handles load-time errors in user spec files
     Failure/Error:
           expect(output).to eq unindent(<<-EOS)

             An error occurred while loading ./1_spec.rb.
             Failure/Error: boom

             NameError:
               undefined local variable or method `boom' for main:Object
             # ./1_spec.rb:1#{spec_line_suffix}

             An error occurred while loading ./3_spec.rb.

       expected: "\nAn error occurred while loading ./1_spec.rb.\nFailure/Error: boom\n\nNameError:\n  undefined local variable or method `boom' for main:Object\n# ./1_spec.rb:1:in `<top (required)>'\n\nAn error occurred while loading ./3_spec.rb.\nFailure/Error: boom\n\nNameError:\n  undefined local variable or method `boom' for main:Object\n# ./3_spec.rb:1:in `<top (required)>'\n\n\nFinished in n.nnnn seconds (files took n.nnnn seconds to load)\n0 examples, 0 failures, 2 errors occurred outside of examples\n\n"
            got: "\nAn error occurred while loading ./1_spec.rb.\nFailure/Error: boom\n\nNameError:\n  undefined local variable or method `boom' for main:Object\n\n  boom\n  ^^^^\n# ./1_spec.rb:1:in `<top (required)>'\n\nAn error occurred while loading ./3_spec.rb.\nFailure/Error: boom\n\nNameError:\n  undefined local variable or method `boom' for main:Object\n\n  boom\n  ^^^^\n# ./3_spec.rb:1:in `<top (required)>'\n\n\nFinished in n.nnnn seconds (files took n.nnnn seconds to load)\n0 examples, 0 failures, 2 errors occurred outside of examples\n\n"

       (compared using ==)

       Diff:
       @@ -4,6 +4,9 @@

        NameError:
          undefined local variable or method `boom' for main:Object
       +
       +  boom
       +  ^^^^
        # ./1_spec.rb:1:in `<top (required)>'

        An error occurred while loading ./3_spec.rb.
       @@ -11,6 +14,9 @@

        NameError:
          undefined local variable or method `boom' for main:Object
       +
       +  boom
       +  ^^^^
        # ./3_spec.rb:1:in `<top (required)>'



     # ./spec/integration/spec_file_load_errors_spec.rb:150:in `block (2 levels) in <top (required)>'
     # ./spec/support/sandboxing.rb:16:in `block (3 levels) in <top (required)>'
     # ./spec/support/sandboxing.rb:7:in `block (2 levels) in <top (required)>'

Finished in 15.42 seconds (files took 0.86247 seconds to load)
2217 examples, 1 failure, 3 pending

Failed examples:

rspec ./spec/integration/spec_file_load_errors_spec.rb:118 # Spec file load errors nicely handles load-time errors in user spec files

Notes

I think that the behavior may have changed depending on whether or not error_highlight gem is installed.
But as I know the gem is a built-in gem in Ruby 3.1...? 🤔

pirj commented

I wonder why it doesn't fail on ci?

This failed on my machine and I sorta ignored it because I've always had a few random spec failures due to asdf, so thank you for fixing this.

Presumedly it doesn't fails on CI because it doesn't have the gem installed