From 17c24483d28e1b5b4b651f680add86da38dd14d0 Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Fri, 31 Aug 2018 16:04:57 +0100 Subject: [PATCH 1/2] Replace poltergeist with govuk_test Poltergeist is no longer maintained so replace with Selenium headless chrome driver via govuk_test. --- Gemfile | 2 +- Gemfile.lock | 25 +++++++++++++++++++------ test/integration_test_helper.rb | 12 +----------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Gemfile b/Gemfile index 0050dd89f..52448547d 100644 --- a/Gemfile +++ b/Gemfile @@ -20,9 +20,9 @@ group :development do end group :test do - gem 'poltergeist', require: false gem 'capybara', '~> 2.18.0' gem 'govuk-content-schema-test-helpers', '~> 1.6' + gem 'govuk_test' gem 'mocha', '~> 1.7.0', require: false gem 'shoulda' gem 'webmock' diff --git a/Gemfile.lock b/Gemfile.lock index efa0a2e7b..22804e3e3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,6 +46,8 @@ GEM tzinfo (~> 1.1) addressable (2.5.2) public_suffix (>= 2.0.2, < 4.0) + archive-zip (0.11.0) + io-like (~> 0.3.0) arel (9.0.0) asset_bom_removal-rails (1.0.2) rails (>= 4.2) @@ -65,7 +67,11 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (>= 2.0, < 4.0) - cliver (0.3.2) + childprocess (0.9.0) + ffi (~> 1.0, >= 1.0.11) + chromedriver-helper (1.2.0) + archive-zip (~> 0.10) + nokogiri (~> 1.8) coderay (1.1.2) commander (4.4.6) highline (~> 1.7.2) @@ -127,6 +133,11 @@ GEM slimmer (>= 11.1.0) govuk_template (0.24.1) rails (>= 3.1) + govuk_test (0.1.0) + capybara + chromedriver-helper + puma + selenium-webdriver hashdiff (0.3.7) highline (1.7.10) htmlentities (4.3.4) @@ -142,6 +153,7 @@ GEM progress (~> 3.0, >= 3.0.1) image_size (2.0.0) in_threads (1.5.0) + io-like (0.3.0) jasmine-core (2.99.2) jasmine-rails (0.14.8) jasmine-core (>= 1.3, < 3.0) @@ -196,10 +208,6 @@ GEM ast (~> 2.4.0) phantomjs (2.1.1.0) plek (2.1.1) - poltergeist (1.18.1) - capybara (>= 2.1, < 4) - cliver (~> 0.3.1) - websocket-driver (>= 0.2.0) power_assert (1.1.1) powerpack (0.1.1) progress (3.4.0) @@ -207,6 +215,7 @@ GEM coderay (~> 1.1.0) method_source (~> 0.9.0) public_suffix (3.0.3) + puma (3.12.0) rack (2.0.5) rack-cache (1.8.0) rack (>= 0.4) @@ -261,6 +270,7 @@ GEM rubocop-rspec (1.19.0) rubocop (>= 0.51.0) ruby-progressbar (1.9.0) + rubyzip (1.2.1) safe_yaml (1.0.4) sanitize (4.6.6) crass (~> 1.0.2) @@ -280,6 +290,9 @@ GEM scss_lint (0.57.0) rake (>= 0.9, < 13) sass (~> 3.5.5) + selenium-webdriver (3.14.0) + childprocess (~> 0.5) + rubyzip (~> 1.2) sentry-raven (2.7.4) faraday (>= 0.7.6, < 1.0) shoulda (3.6.0) @@ -346,6 +359,7 @@ DEPENDENCIES govuk_frontend_toolkit (~> 7.6.0) govuk_publishing_components (~> 9.16.0) govuk_template (= 0.24.1) + govuk_test image_optim (= 0.26.2) jasmine-rails (~> 0.14.8) minitest @@ -353,7 +367,6 @@ DEPENDENCIES mocha (~> 1.7.0) nokogiri (~> 1.8) plek (= 2.1.1) - poltergeist pry rack_strip_client_ip (= 0.0.2) rails (~> 5.2) diff --git a/test/integration_test_helper.rb b/test/integration_test_helper.rb index 6941829a7..ccc9f7854 100644 --- a/test/integration_test_helper.rb +++ b/test/integration_test_helper.rb @@ -1,18 +1,8 @@ require_relative 'test_helper' require 'rack/test' require 'capybara/rails' -require 'capybara/poltergeist' -require 'phantomjs' -# TODO: Remove when PhantomJS updated on Puppet -# Use modern PhantomJS version via gem -# Based on: https://github.com/colszowka/phantomjs-gem/blob/master/lib/phantomjs/poltergeist.rb -Phantomjs.path -Capybara.register_driver :poltergeist do |app| - Capybara::Poltergeist::Driver.new(app, phantomjs: Phantomjs.path, timeout: 2.minutes) -end - -Capybara.javascript_driver = :poltergeist +GovukTest.configure class ActionDispatch::IntegrationTest < ActiveSupport::TestCase include Rack::Test::Methods From 31933c2f03babb86d28d5a13d3446f65b44a680f Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Fri, 31 Aug 2018 16:06:24 +0100 Subject: [PATCH 2/2] Stub out Redis dependency Emergency banner tests rely upon Redis being present, this shouldn't be a test dependency so stub out the response from Redis. --- test/integration/notifications_test.rb | 41 +++++++++++++------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/test/integration/notifications_test.rb b/test/integration/notifications_test.rb index aeff95b7e..4da63c431 100644 --- a/test/integration/notifications_test.rb +++ b/test/integration/notifications_test.rb @@ -1,6 +1,10 @@ require 'integration_test_helper' class NotificationsTest < ActionDispatch::IntegrationTest + def stub_redis_response(hash) + Redis.any_instance.stubs(:hgetall).with("emergency_banner").returns(hash) + end + context "emergency banner file" do should "have an emergency banner file" do assert File.exist? "#{Rails.root}/app/views/notifications/_emergency_banner.html.erb" @@ -9,20 +13,19 @@ class NotificationsTest < ActionDispatch::IntegrationTest context "emergency banner notifications" do should "not render a banner if one does not exist" do - EmergencyBanner::Display.any_instance.stubs(:enabled?).returns(false) visit "/templates/wrapper.html.erb" refute page.has_selector? ".govuk-emergency-banner" end should "render a banner if one does exist" do - EmergencyBanner::Display.any_instance.stubs(:enabled?).returns(true) + stub_redis_response(campaign_class: "foo", heading: "bar") + visit "/templates/wrapper.html.erb" assert page.has_selector? ".govuk-emergency-banner" end should "render a banner with a heading and campaign colour" do - EmergencyBanner::Display.any_instance.stubs(:heading).returns("Alas poor Yorick") - EmergencyBanner::Display.any_instance.stubs(:campaign_class).returns("notable-death") + stub_redis_response(campaign_class: "notable-death", heading: "Alas poor Yorick") visit "/templates/wrapper.html.erb" @@ -31,9 +34,9 @@ class NotificationsTest < ActionDispatch::IntegrationTest end should "render the more information link" do - EmergencyBanner::Display.any_instance.stubs(:heading).returns("Alas poor Yorick") - EmergencyBanner::Display.any_instance.stubs(:campaign_class).returns("notable-death") - EmergencyBanner::Display.any_instance.stubs(:link).returns("https://yoricks.gov") + stub_redis_response(campaign_class: "notable-death", + heading: "Alas poor Yorick", + link: "https://yoricks.gov") visit "/templates/wrapper.html.erb" @@ -42,10 +45,10 @@ class NotificationsTest < ActionDispatch::IntegrationTest end should "render the more information link with specified text" do - EmergencyBanner::Display.any_instance.stubs(:heading).returns("Alas poor Yorick") - EmergencyBanner::Display.any_instance.stubs(:campaign_class).returns("notable-death") - EmergencyBanner::Display.any_instance.stubs(:link).returns("https://yoricks.gov") - EmergencyBanner::Display.any_instance.stubs(:link_text).returns("Some specified text for more information") + stub_redis_response(campaign_class: "notable-death", + heading: "Alas poor Yorick", + link: "https://yoricks.gov", + link_text: "Some specified text for more information") visit "/templates/wrapper.html.erb" @@ -53,9 +56,8 @@ class NotificationsTest < ActionDispatch::IntegrationTest end should "not render the more information link if it does not exist" do - EmergencyBanner::Display.any_instance.stubs(:heading).returns("Alas poor Yorick") - EmergencyBanner::Display.any_instance.stubs(:campaign_class).returns("notable-death") - EmergencyBanner::Display.any_instance.stubs(:link).returns(nil) + stub_redis_response(campaign_class: "notable-death", + heading: "Alas poor Yorick") visit "/templates/wrapper.html.erb" @@ -64,9 +66,9 @@ class NotificationsTest < ActionDispatch::IntegrationTest end should "render the extra information" do - EmergencyBanner::Display.any_instance.stubs(:heading).returns("Alas poor Yorick") - EmergencyBanner::Display.any_instance.stubs(:campaign_class).returns("notable-death") - EmergencyBanner::Display.any_instance.stubs(:short_description).returns("I knew him well") + stub_redis_response(campaign_class: "notable-death", + heading: "Alas poor Yorick", + short_description: "I knew him well") visit "/templates/wrapper.html.erb" @@ -74,9 +76,8 @@ class NotificationsTest < ActionDispatch::IntegrationTest end should "does not render the extra information if it does not exist" do - EmergencyBanner::Display.any_instance.stubs(:heading).returns("Alas poor Yorick") - EmergencyBanner::Display.any_instance.stubs(:campaign_class).returns("notable-death") - EmergencyBanner::Display.any_instance.stubs(:short_description).returns(nil) + stub_redis_response(campaign_class: "notable-death", + heading: "Alas poor Yorick") visit "/templates/wrapper.html.erb"