-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Rails integration test for compiled template
We want to be confident that the changes we make to govuk_template don't break the compiled templates. The only way we can really do this automatically is to have code that can process each template. The spec is currently wired up to anything and is hardcoded for the filename generated by the Rails integration code. The expectations should be portable, however. This needs some scripting to trigger the sub-build within each integration testing app and then run the spec. For the languages that aren't Ruby, we'll need to alter the travis.yml.
- Loading branch information
1 parent
708a45d
commit a53e58b
Showing
10 changed files
with
212 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
.DS_Store | ||
.bundle | ||
.sass-cache | ||
Gemfile.lock | ||
app | ||
/Gemfile.lock | ||
/app | ||
pkg | ||
|
||
integration_tests/html_for_testing/*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Integration Tests | ||
|
||
When we make changes to govuk_template, we want to know that the changes don't break integration with clients. | ||
|
||
This directory contains example integrations for compilation targets of govuk_template so that we can test two things: | ||
|
||
* is the compiled template still syntactically valid? | ||
* has the API changed - has it required any changes in the app? | ||
|
||
This is achieved by getting each app to render HTML from the template, saving it into `./html_for_testing` and then running assertions against each of those HTML files. |
Empty file.
82 changes: 82 additions & 0 deletions
82
integration_tests/html_rendered_by_each_integration_testing_app_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
require 'spec_helper' | ||
require 'rspec-html-matchers' | ||
|
||
describe "HTML rendered by each integration testing app" do | ||
include RSpecHtmlMatchers | ||
|
||
let(:filename) { "#{PROJECT_ROOT}/integration_tests/html_for_testing/rails_integration_test_app.html" } | ||
|
||
subject { File.open(filename).read } | ||
|
||
it "should allow overriding the lang attribute on the html tag" do | ||
expect(subject).to have_tag("html", with: { lang: 'rb' }) | ||
end | ||
|
||
it "should allow overriding the page title" do | ||
expect(subject).to have_tag("title", text: "This is a custom page title") | ||
end | ||
|
||
it "should allows inserting content into the head" do | ||
expect(subject).to have_tag("head") do | ||
with_tag "inserted-into-head" | ||
end | ||
end | ||
|
||
it "should allow setting_body_classes" do | ||
expect(subject).to have_tag("body", with: { class: "custom_body_class" }) | ||
end | ||
|
||
it "should allow inserting content into body_start" do | ||
expect(subject).to have_tag("body") do | ||
with_tag "inserted-into-body-start" | ||
end | ||
end | ||
|
||
it "should allow overriding the cookie message" do | ||
expect(subject).to have_tag("div#global-cookie-message", text: /Custom cookie message/) | ||
end | ||
|
||
it "should allow setting_global_header_class" do | ||
expect(subject).to have_tag("header", with: { class: "custom_header_class" }) | ||
end | ||
|
||
it "should allow inserting content into the header" do | ||
expect(subject).to have_tag("header") do | ||
with_tag("inside-header") | ||
end | ||
end | ||
|
||
it "should allow inserting_a_proposition_header" do | ||
expect(subject).to have_tag("header") do | ||
with_tag("proposition-header") | ||
end | ||
end | ||
|
||
it "should allow inserting_after_header" do | ||
expect(subject).to have_tag("body") do | ||
with_tag("after-header") | ||
end | ||
end | ||
|
||
it "should content" do | ||
expect(subject).to have_tag("body", text: /The page content/) | ||
end | ||
|
||
it "should footer_top" do | ||
expect(subject).to have_tag("footer") do | ||
with_tag "footer-top" | ||
end | ||
end | ||
|
||
it "should footer_support_links" do | ||
expect(subject).to have_tag("footer") do | ||
with_tag "footer-support-links" | ||
end | ||
end | ||
|
||
it "should body_end" do | ||
expect(subject).to have_tag("body") do | ||
with_tag "body-end" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gem "actionpack", "4.2.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
actionpack (4.2.1) | ||
actionview (= 4.2.1) | ||
activesupport (= 4.2.1) | ||
rack (~> 1.6) | ||
rack-test (~> 0.6.2) | ||
rails-dom-testing (~> 1.0, >= 1.0.5) | ||
rails-html-sanitizer (~> 1.0, >= 1.0.1) | ||
actionview (4.2.1) | ||
activesupport (= 4.2.1) | ||
builder (~> 3.1) | ||
erubis (~> 2.7.0) | ||
rails-dom-testing (~> 1.0, >= 1.0.5) | ||
rails-html-sanitizer (~> 1.0, >= 1.0.1) | ||
activesupport (4.2.1) | ||
i18n (~> 0.7) | ||
json (~> 1.7, >= 1.7.7) | ||
minitest (~> 5.1) | ||
thread_safe (~> 0.3, >= 0.3.4) | ||
tzinfo (~> 1.1) | ||
builder (3.2.2) | ||
erubis (2.7.0) | ||
i18n (0.7.0) | ||
json (1.8.2) | ||
loofah (2.0.2) | ||
nokogiri (>= 1.5.9) | ||
mini_portile (0.6.2) | ||
minitest (5.6.1) | ||
nokogiri (1.6.6.2) | ||
mini_portile (~> 0.6.0) | ||
rack (1.6.1) | ||
rack-test (0.6.3) | ||
rack (>= 1.0) | ||
rails-deprecated_sanitizer (1.0.3) | ||
activesupport (>= 4.2.0.alpha) | ||
rails-dom-testing (1.0.6) | ||
activesupport (>= 4.2.0.beta, < 5.0) | ||
nokogiri (~> 1.6.0) | ||
rails-deprecated_sanitizer (>= 1.0.1) | ||
rails-html-sanitizer (1.0.2) | ||
loofah (~> 2.0) | ||
thread_safe (0.3.5) | ||
tzinfo (1.2.2) | ||
thread_safe (~> 0.1) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
actionpack (= 4.2.1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#! /bin/bash | ||
set -e | ||
|
||
bundle install | ||
|
||
bundle exec ruby simplicity.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'action_controller' | ||
|
||
class TemplateRenderer < AbstractController::Base | ||
include AbstractController::Rendering | ||
include ActionView::Layouts | ||
include AbstractController::Helpers | ||
include AbstractController::Translation | ||
include AbstractController::AssetPaths | ||
|
||
self.view_paths = [ | ||
"views", | ||
File.absolute_path(File.expand_path(File.join(__FILE__, "../../../../app/views"))) # Hack to manually add the compiled template path | ||
] | ||
|
||
layout "govuk_template" | ||
|
||
def show | ||
render template: "show" | ||
end | ||
end | ||
|
||
rendered_template = TemplateRenderer.new.show | ||
|
||
output_filepath = File.absolute_path(File.expand_path(File.join(__FILE__, "../../../html_for_testing/rails_integration_test_app.html"))) | ||
|
||
File.write(output_filepath, rendered_template) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<% content_for(:html_lang, 'rb') %> | ||
<% content_for(:page_title, "This is a custom page title") %> | ||
<% content_for(:head) do %><inserted-into-head></inserted-into-head><% end %> | ||
<% content_for(:body_classes, "custom_body_class") %> | ||
<% content_for(:body_start) do %><inserted-into-body-start></inserted-into-body-start><% end %> | ||
<% content_for(:cookie_message, "Custom cookie message") %> | ||
<% content_for(:header_class, "custom_header_class") %> | ||
<% content_for(:inside_header) do %><inside-header></inside-header><% end %> | ||
<% content_for(:proposition_header) do %><proposition-header></proposition-header><% end %> | ||
<% content_for(:after_header) do %><after-header></after-header><% end %> | ||
|
||
The page content | ||
|
||
<% content_for(:footer_top) do %><footer-top></footer-top><% end %> | ||
<% content_for(:footer_support_links) do %><footer-support-links></footer-support-links><% end %> | ||
<% content_for(:body_end) do %><body-end></body-end><% end %> |