Skip to content

Commit 86587e2

Browse files
committed
Inline SVG id generator consistency is now enabled for all tests
1 parent 89f56d9 commit 86587e2

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module HtmlFixtures
2+
module Patches
3+
module InlineSvgIdGeneratorRandomnessOverride
4+
def call
5+
"non-random-for-fixtures"
6+
end
7+
end
8+
end
9+
end
10+
11+
# We use this module to override the randomness of the InlineSvg gem to ensure that the SVG
12+
# IDs are consistent across test runs and git commits in the generated HTML fixtures.
13+
#
14+
# Overrides this behavior: https://github.com/jamesmartin/inline_svg/blob/9ab5ccf8d4ba6a6d1e453d9bde2008a6ebab9877/lib/inline_svg/id_generator.rb#L5-L10
15+
#
16+
class InlineSvg::IdGenerator::Randomness
17+
class << self
18+
prepend HtmlFixtures::Patches::InlineSvgIdGeneratorRandomnessOverride
19+
end
20+
end

lib/html_fixtures/renderer.rb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,9 @@ def build_view_context
2222
instance.set_response! ApplicationController.make_response!(request)
2323
instance.view_context
2424
end
25-
end
26-
end
27-
28-
# We need to override the randomness of the InlineSvg gem to ensure that the SVG
29-
# IDs are consistent across test runs and git commits.
30-
module InlineSvgIdGeneratorRandomnessOverrideForFixtures
31-
def call
32-
"non-random-for-fixtures"
33-
end
34-
end
3525

36-
if Rails.env.local?
37-
class InlineSvg::IdGenerator::Randomness
38-
class << self
39-
prepend InlineSvgIdGeneratorRandomnessOverrideForFixtures
26+
def self.ensure_inline_svg_id_consistency!
27+
require_relative "patches/inline_svg_id_generator_randomness_override"
4028
end
4129
end
4230
end

lib/tasks/fixtures/html.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace :fixtures do
22
task html: :environment do
33
require_relative "../../html_fixtures/renderer"
44

5+
HtmlFixtures::Renderer.ensure_inline_svg_id_consistency!
56
HtmlFixtures::Renderer.new.render_all
67
end
78
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require "rails_helper"
2+
3+
RSpec.describe HtmlFixtures::Renderer do
4+
it "renders all fixtures" do
5+
HtmlFixtures::Renderer.new.render_all
6+
7+
expect(File.exist?(Rails.root.join("app", "javascript", "test", "fixtures", "views", "darkmode", "switch.html"))).to be true
8+
expect(File.exist?(Rails.root.join("app", "javascript", "test", "fixtures", "views", "searches", "combobox.html"))).to be true
9+
end
10+
end

spec/support/inline_svg.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
HtmlFixtures::Renderer.ensure_inline_svg_id_consistency!

0 commit comments

Comments
 (0)