Skip to content

Commit 4aad064

Browse files
authored
Extract cell_selector method in scaffold index view spec generator (#2777)
Move conditional `cell_selector` out of generated view spec
1 parent dc0abdb commit 4aad064

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Enhancements:
88
* Verify ActiveJob arguments by comparing to the method signature. (Oli Peate, #2745)
99
* Add suggestion to rails_helper.rb to skip when not in test most. (Glauco Custódio, #2751)
1010
* Add `at_priority` qualifier to `have_enqueued_job` set of matchers. (mbajur, #2759)
11+
* Remove Rails version-specific conditional from index scaffold generation. (Matt Jankowski, #2777)
1112

1213
Bug Fixes:
1314

lib/generators/rspec/scaffold/templates/index_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
it "renders a list of <%= ns_table_name %>" do
2020
render
21-
cell_selector = Rails::VERSION::STRING >= '7' ? 'div>p' : 'tr>td'
21+
cell_selector = <%= Rails::VERSION::STRING >= '7' ? "'div>p'" : "'tr>td'" %>
2222
<% for attribute in output_attributes -%>
2323
assert_select cell_selector, text: Regexp.new(<%= value_for(attribute) %>.to_s), count: 2
2424
<% end -%>

spec/generators/rspec/scaffold/scaffold_generator_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,12 @@
268268
.and(contain(/^RSpec.describe "(.*)\/index", #{type_metatag(:view)}/))
269269
.and(contain(/assign\(:posts, /))
270270
.and(contain(/it "renders a list of (.*)"/))
271+
272+
if ::Rails::VERSION::STRING >= '7.0.0'
273+
expect(filename).to contain(/'div>p'/)
274+
else
275+
expect(filename).to contain(/'tr>td'/)
276+
end
271277
end
272278
end
273279

0 commit comments

Comments
 (0)