Skip to content

Commit

Permalink
Extract cell_selector method in scaffold index view spec generator (#…
Browse files Browse the repository at this point in the history
…2777)

Move conditional `cell_selector` out of generated view spec
  • Loading branch information
mjankowski authored and JonRowe committed Aug 15, 2024
1 parent 49b34bd commit d6792b4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Bug Fixes:

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

### 6.1.3 / 2024-06-19
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v6.1.2...v6.1.3)
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/scaffold/templates/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand Down
6 changes: 6 additions & 0 deletions spec/generators/rspec/scaffold/scaffold_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d6792b4

Please sign in to comment.