Skip to content

Commit f278250

Browse files
Test Cleanup: Improve test setup
Use `touch` test helper instead of directly working with the `File` class during the setup phase. Also create [file_fixtures][] to simplify test setup. Because the newly added file fixtures are processed with standard, I needed to adjust the testing generator to account for a minor violation. [file_fixtures]: https://api.rubyonrails.org/classes/ActiveSupport/Testing/FileFixtures.html#method-i-file_fixture
1 parent f6c6f45 commit f278250

31 files changed

+244
-276
lines changed

lib/generators/suspenders/testing_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def modify_spec_helper
4343
allow_localhost: true,
4444
allow: [
4545
/(chromedriver|storage).googleapis.com/,
46-
"googlechromelabs.github.io",
46+
"googlechromelabs.github.io"
4747
]
4848
)
4949
RUBY

test/fixtures/files/Rakefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require_relative "config/application"
2+
require "bundler/audit/task"
3+
Bundler::Audit::Task.new
4+
5+
Rails.application.load_tasks

test/fixtures/files/_flashes.html.erb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<% if flash.any? %>
2+
<div class="flashes">
3+
<% flash.each do |type, message| -%>
4+
<div class="flash-<%= type %>"><%= message %></div>
5+
<% end -%>
6+
</div>
7+
<% end %>

test/fixtures/files/action_mailer.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RSpec.configure do |config|
2+
config.before(:each) do
3+
ActionMailer::Base.deliveries.clear
4+
end
5+
end

test/fixtures/files/active_job.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require "active_job/logging"
2+
require "active_job/log_subscriber"
3+
4+
ActiveSupport::Notifications.unsubscribe("enqueue.active_job")
5+
6+
module ActiveJob
7+
module Logging
8+
class EnqueueLogSubscriber < LogSubscriber
9+
define_method :enqueue, instance_method(:enqueue)
10+
end
11+
end
12+
end
13+
14+
ActiveJob::Logging::EnqueueLogSubscriber.attach_to(:active_job)

test/fixtures/files/better_html.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Rails.configuration.to_prepare do
2+
if Rails.env.test?
3+
require "better_html"
4+
5+
BetterHtml.config = BetterHtml::Config.new(Rails.configuration.x.better_html)
6+
7+
BetterHtml.config.template_exclusion_filter = proc { |filename| !filename.start_with?(Rails.root.to_s) }
8+
end
9+
end

test/fixtures/files/driver.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RSpec.configure do |config|
2+
config.before(:each, type: :system) do
3+
driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1400]
4+
end
5+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class EmailInterceptor
2+
include ActiveSupport::Configurable
3+
4+
config_accessor :interceptor_addresses, default: []
5+
6+
def self.delivering_email(message)
7+
to = interceptor_addresses
8+
9+
message.to = to if to.any?
10+
end
11+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Rails.application.configure do
2+
if ENV["INTERCEPTOR_ADDRESSES"].present?
3+
config.action_mailer.interceptors = %w[EmailInterceptor]
4+
end
5+
end

test/fixtures/files/erb-lint.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
glob: "app/views/**/*.{html,turbo_stream}{+*,}.erb"
3+
4+
linters:
5+
AllowedScriptType:
6+
enabled: true
7+
allowed_types:
8+
- "module"
9+
- "text/javascript"
10+
ErbSafety:
11+
enabled: true
12+
better_html_config: "config/better_html.yml"
13+
GitHub::Accessibility::AvoidBothDisabledAndAriaDisabledCounter:
14+
enabled: true
15+
GitHub::Accessibility::AvoidGenericLinkTextCounter:
16+
enabled: true
17+
GitHub::Accessibility::DisabledAttributeCounter:
18+
enabled: true
19+
GitHub::Accessibility::IframeHasTitleCounter:
20+
enabled: true
21+
GitHub::Accessibility::ImageHasAltCounter:
22+
enabled: true
23+
GitHub::Accessibility::LandmarkHasLabelCounter:
24+
enabled: true
25+
GitHub::Accessibility::LinkHasHrefCounter:
26+
enabled: true
27+
GitHub::Accessibility::NestedInteractiveElementsCounter:
28+
enabled: true
29+
GitHub::Accessibility::NoAriaLabelMisuseCounter:
30+
enabled: true
31+
GitHub::Accessibility::NoPositiveTabIndexCounter:
32+
enabled: true
33+
GitHub::Accessibility::NoRedundantImageAltCounter:
34+
enabled: true
35+
GitHub::Accessibility::NoTitleAttributeCounter:
36+
enabled: true
37+
GitHub::Accessibility::SvgHasAccessibleTextCounter:
38+
enabled: true
39+
Rubocop:
40+
enabled: true
41+
rubocop_config:
42+
inherit_from:
43+
- .rubocop.yml
44+
45+
Lint/EmptyBlock:
46+
Enabled: false
47+
Layout/InitialIndentation:
48+
Enabled: false
49+
Layout/TrailingEmptyLines:
50+
Enabled: false
51+
Layout/TrailingWhitespace:
52+
Enabled: false
53+
Layout/LeadingEmptyLines:
54+
Enabled: false
55+
Style/FrozenStringLiteralComment:
56+
Enabled: false
57+
Style/MultilineTernaryOperator:
58+
Enabled: false
59+
Lint/UselessAssignment:
60+
Exclude:
61+
- "app/views/**/*"
62+
63+
EnableDefaultLinters: true

0 commit comments

Comments
 (0)