rspec / rspec-rails

RSpec for Rails 6+
https://rspec.info
MIT License
5.16k stars 1.03k forks source link

Support chages to `show_helper` in Rails 7 #2741

Open rickselby opened 7 months ago

rickselby commented 7 months ago

2492 overrode show_helper, which in Rails 6 looks like:

def show_helper
  "#{singular_route_name}_url(@#{singular_table_name})"
end

But Rails 7 changed it to

def show_helper(arg = "@#{singular_table_name}", type: :url) # :doc:
  "#{singular_route_name}_#{type}(#{arg})"
end

This change supports the arguments in Rails 7 while maintaining support for Rails 6.

pirj commented 7 months ago

Do you think it’s possible to add a failing example?

rickselby commented 7 months ago

Not unless there's an easy way of providing a different template to a spec test.

Ideally I'd add a test template that called show_helper(type: :path) and could test the output of the generator with that template. But I can't see a way of doing that.

Also, if anyone has any preferences on how to address the rubocop failure, I'll make a change.

rickselby commented 7 months ago

I've updated the change to remove the override for Rails 6 (and have reverted show_helper to what it was before).

I'm still struggling to see a good way of setting up a spec test; but as I'm now not changing the function, just removing it from Rails 7, then the existing Rails 7 tests should show that it still works? The default templates do call show_helper.