Skip to content

Commit 910d276

Browse files
Make the index spec handle varying templates between Rails versions
1 parent cc5fef4 commit 910d276

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

example_app_generator/spec/support/default_preview_path

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ require_file_stub 'config/environment' do
2626
require "action_controller/railtie"
2727
require "action_mailer/railtie" unless ENV['NO_ACTION_MAILER']
2828
require "action_view/railtie"
29+
require "action_cable/engine" if Rails::VERSION::STRING >= '6'
2930

3031
# Require the gems listed in Gemfile, including any gems
3132
# you've limited to :test, :development, or :production.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
1919
it "renders a list of <%= ns_table_name %>" do
2020
render
21+
cell_selector = Rails::VERSION::STRING >= '7' ? 'div>p' : 'tr>td'
2122
<% for attribute in output_attributes -%>
22-
assert_select "tr>td", text: <%= value_for(attribute) %>.to_s, count: 2
23+
assert_select cell_selector, text: Regexp.new(<%= value_for(attribute) %>.to_s), count: 2
2324
<% end -%>
2425
end
2526
end

spec/generators/rspec/scaffold/scaffold_generator_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,16 @@
208208
before { run_generator %w[posts upvotes:integer downvotes:integer] }
209209
subject { file("spec/views/posts/index.html.erb_spec.rb") }
210210
it { is_expected.to exist }
211-
it { is_expected.to contain('assert_select "tr>td", text: 2.to_s, count: 2') }
212-
it { is_expected.to contain('assert_select "tr>td", text: 3.to_s, count: 2') }
211+
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(2.to_s), count: 2') }
212+
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(3.to_s), count: 2') }
213213
end
214214

215215
describe 'with multiple float attributes index' do
216216
before { run_generator %w[posts upvotes:float downvotes:float] }
217217
subject { file("spec/views/posts/index.html.erb_spec.rb") }
218218
it { is_expected.to exist }
219-
it { is_expected.to contain('assert_select "tr>td", text: 2.5.to_s, count: 2') }
220-
it { is_expected.to contain('assert_select "tr>td", text: 3.5.to_s, count: 2') }
219+
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(2.5.to_s), count: 2') }
220+
it { is_expected.to contain('assert_select cell_selector, text: Regexp.new(3.5.to_s), count: 2') }
221221
end
222222

223223
describe 'with reference attribute' do

0 commit comments

Comments
 (0)