rspec/rspec-rails

be_routable not working in controller spec with Rails 7.1

contentfree opened this issue · 2 comments

Typical routing spec that works in <7.1:

expect(get: :index).to_not be_routable

Fails in Rails 7.1.1 with:

NoMethodError: undefined method `include?' for :index:Symbol

What Ruby, Rails and RSpec versions are you using?

Ruby version: 3.2.2
Rails version: 7.1.1
RSpec version: 3.12

  • rspec-core 3.12.2
  • rspec-expectations 3.12.3
  • rspec-mocks 3.12.6
  • rspec-rails 6.0.3
  • rspec-support 3.12.1

Maybe this is just a relic and is no longer expected to work this way? (It worked for a long time with Rails 5 & 6 & 7.0.) Changing to use expect(get: '/my_objects').to_not be_routable works as expected though that is a bit of a difference as it requires knowledge of any path configuration when I want to ensure that :index is never routable.

👋 We call Rails with the value you give here through ActionDispatch::Routing#RouteSet#recognize_path, and catch a specific routing error to say "this is not routable", I've never been a big user of route specs so I'm not sure if what you gave ever actually worked, certainly 7 and 6 this should not have worked because :index is not a valid route path.

I suspect this spec has always been a false positive, e.g. it was being matched as "/index" which wasn't routable so the spec passed, and all that has changed is Rails now internally expects an actual string not just a string like so you get a different error.

I'm closing this because of the above.