5

Running rspec after upgrading Rails results in an uninitialized constant error: RSpec::Rails::Railtie::SourceAnnotationExtractor.

The backtrace points to the "rails_helper.rb" file.

I already attempted a bundle update rspec-rails.

SamuelLJohnson
  • 599
  • 3
  • 16

2 Answers2

6

I'm adding this question and answer because I didn't find the exact issue or solution when searching StackOverflow.

It turns out that rspec-rails was stuck because rspec wasn't updating (stuck on v 3.6).

The fix:

bundle update rspec rspec-rails

It was critical to update both gems at once. That finally updated rspec-rails to 5.0.1 and rspec to 3.10.0.

Thanks to this thread for vital information: https://github.com/rspec/rspec-rails/issues/1298

SamuelLJohnson
  • 599
  • 3
  • 16
0

I had this exact same error and this solved it.

I changed the version of the rspec-rails gem in the gemfile according to this list that I found in the README section of the gem's github repo:

  • rspec-rails 6.x for Rails 6.1 or 7.x.
  • rspec-rails 5.x for Rails 5.2 or 6.x.
  • rspec-rails 4.x for Rails from 5.x or 6.x.
  • rspec-rails 3.x for Rails earlier than 5.0.
  • rspec-rails 1.x for Rails 2.x.

So, in my case, I upgraded to 6.1, so I used: gem 'rspec-rails', '~> 6.0.0'

Stuart
  • 35
  • 4