Skip to content

Commit d6792b4

Browse files
mjankowskiJonRowe
authored andcommitted
Extract cell_selector method in scaffold index view spec generator (#2777)
Move conditional `cell_selector` out of generated view spec
1 parent 49b34bd commit d6792b4

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
@@ -5,6 +5,7 @@ Bug Fixes:
55

66
* Prevent `have_http_status` matcher raising an error when encountering a raw `Rack::MockResponse`.
77
(Christophe Bliard, #2771)
8+
* Move Rails version conditional from index scaffold generated file to template. (Matt Jankowski, #2777)
89

910
### 6.1.3 / 2024-06-19
1011
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.1.2...v6.1.3)

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)