Skip to content

Commit c3f8184

Browse files
committed
Run markdown render in spec/rails_helper
Run the markdown render for feature tests in spec/rails_helper. This is because feature tests require the app/views/generated views to exist
1 parent 0ffbdd5 commit c3f8184

4 files changed

Lines changed: 21 additions & 27 deletions

File tree

lib/tasks/markdown_to_static_html.rake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ def format_date(date)
44
return nil if date.blank?
55

66
Date.iso8601(date).strftime("%-d/%-m/%Y")
7-
rescue ArgumentError, TypeError
8-
nil
97
end
108

119
def process_visualisation_data(chart_json)
@@ -99,7 +97,9 @@ namespace :markdown do
9997

10098
FileUtils.mkdir_p(output_path.dirname)
10199

102-
puts("Rendering #{path.basename} to => #{output_path}")
100+
unless Rails.env.test?
101+
puts("Rendering #{path.basename} to => #{output_path}")
102+
end
103103

104104
html = ApplicationController.renderer.render(
105105
partial: "v2/collection/content",

spec/features/v2/charts_spec.rb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
require "rails_helper"
22

33
RSpec.describe "Charts", type: :system, js: true do
4-
before(:all) do
5-
Rake.application.rake_require("tasks/markdown_to_static_html")
6-
Rake::Task.define_task(:environment)
7-
Rails.configuration.x.markdown_collections_output_location = "app/views/generated/collections"
8-
Rails.configuration.x.markdown_collections_location_glob = "app/content/collections/**/*.md"
9-
Rails.configuration.x.visualisations_data_location = "app/content/data"
10-
Rake::Task["markdown:render"].invoke
11-
end
12-
13-
after(:all) do
14-
FileUtils.rm_rf("app/views/generated")
15-
end
4+
# Setup and teardown for generated views is handled globally in rails_helper.rb
165

176
scenario "I can see a single series line chart on a collection page" do
187
given_i_visit_a_collection_page_with_a_single_series_line_chart

spec/features/v2/collections_spec.rb

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
require "rails_helper"
22

33
RSpec.feature "collections", type: :feature do
4-
before(:all) do
5-
Rake.application.rake_require("tasks/markdown_to_static_html")
6-
Rake::Task.define_task(:environment)
7-
Rails.configuration.x.markdown_collections_output_location = "app/views/generated/collections"
8-
Rails.configuration.x.markdown_collections_location_glob = "app/content/collections/**/*.md"
9-
Rails.configuration.x.visualisations_data_location = "app/content/data"
10-
Rake::Task["markdown:render"].invoke
11-
end
12-
13-
after(:all) do
14-
FileUtils.rm_rf("app/views/generated")
15-
end
4+
# Setup and teardown for generated views is handled globally in rails_helper.rb
165

176
scenario "I visit a collection page" do
187
given_i_am_on_a_collection_page

spec/rails_helper.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@
6868
config.include FactoryBot::Syntax::Methods
6969
end
7070

71+
RSpec.configure do |config|
72+
config.before(:suite) do
73+
Rake.application.rake_require("tasks/markdown_to_static_html")
74+
Rake::Task.define_task(:environment)
75+
Rails.configuration.x.markdown_collections_output_location = "app/views/generated/collections"
76+
Rails.configuration.x.markdown_collections_location_glob = "app/content/collections/**/*.md"
77+
Rails.configuration.x.visualisations_data_location = "app/content/data"
78+
Rake::Task["markdown:render"].reenable
79+
Rake::Task["markdown:render"].invoke
80+
end
81+
82+
config.after(:suite) do
83+
FileUtils.rm_rf("app/views/generated")
84+
end
85+
end
86+
7187
# Setup chrome headless driver
7288
GovukTest.configure
7389

0 commit comments

Comments
 (0)