diff --git a/Changelog.md b/Changelog.md index 2da298ebb..53bd6961c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ Enhancements: * Verify ActiveJob arguments by comparing to the method signature. (Oli Peate, #2745) * Add suggestion to rails_helper.rb to skip when not in test most. (Glauco Custódio, #2751) * Add `at_priority` qualifier to `have_enqueued_job` set of matchers. (mbajur, #2759) +* Remove Rails version-specific conditional from index scaffold generation. (Matt Jankowski, #2777) Bug Fixes: diff --git a/lib/generators/rspec/scaffold/templates/index_spec.rb b/lib/generators/rspec/scaffold/templates/index_spec.rb index 4abbc0da0..627b475cf 100644 --- a/lib/generators/rspec/scaffold/templates/index_spec.rb +++ b/lib/generators/rspec/scaffold/templates/index_spec.rb @@ -18,7 +18,7 @@ it "renders a list of <%= ns_table_name %>" do render - cell_selector = Rails::VERSION::STRING >= '7' ? 'div>p' : 'tr>td' + cell_selector = <%= Rails::VERSION::STRING >= '7' ? "'div>p'" : "'tr>td'" %> <% for attribute in output_attributes -%> assert_select cell_selector, text: Regexp.new(<%= value_for(attribute) %>.to_s), count: 2 <% end -%> diff --git a/spec/generators/rspec/scaffold/scaffold_generator_spec.rb b/spec/generators/rspec/scaffold/scaffold_generator_spec.rb index edbc23934..4e02682e3 100644 --- a/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +++ b/spec/generators/rspec/scaffold/scaffold_generator_spec.rb @@ -268,6 +268,12 @@ .and(contain(/^RSpec.describe "(.*)\/index", #{type_metatag(:view)}/)) .and(contain(/assign\(:posts, /)) .and(contain(/it "renders a list of (.*)"/)) + + if ::Rails::VERSION::STRING >= '7.0.0' + expect(filename).to contain(/'div>p'/) + else + expect(filename).to contain(/'tr>td'/) + end end end