Skip to content

Commit 5ce7e31

Browse files
committed
Extract cell_selector method in scaffold index view spec generator
1 parent 8c17b4e commit 5ce7e31

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
1919
it "renders a list of <%= ns_table_name %>" do
2020
render
21-
cell_selector = Rails::VERSION::STRING >= '7' ? 'div>p' : 'tr>td'
2221
<% for attribute in output_attributes -%>
2322
assert_select cell_selector, text: Regexp.new(<%= value_for(attribute) %>.to_s), count: 2
2423
<% end -%>
2524
end
25+
26+
def cell_selector
27+
<%= Rails::VERSION::STRING >= '7' ? "'div>p'" : "'tr>td'" %>
28+
end
2629
end

spec/generators/rspec/scaffold/scaffold_generator_spec.rb

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

0 commit comments

Comments
 (0)