Skip to content

Commit

Permalink
Merge pull request #1510 from alphagov/replace-poltergeist-with-govuk…
Browse files Browse the repository at this point in the history
…-test

Replace poltergeist with govuk test
  • Loading branch information
steventux authored Aug 31, 2018
2 parents 6bbb820 + 31933c2 commit ae6f58f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
25 changes: 19 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -196,17 +208,14 @@ 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)
pry (0.11.3)
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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -346,14 +359,14 @@ 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
minitest-capybara (~> 0.8.2)
mocha (~> 1.7.0)
nokogiri (~> 1.8)
plek (= 2.1.1)
poltergeist
pry
rack_strip_client_ip (= 0.0.2)
rails (~> 5.2)
Expand Down
41 changes: 21 additions & 20 deletions test/integration/notifications_test.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"

Expand All @@ -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"

Expand All @@ -42,20 +45,19 @@ 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"

assert_match "Some specified text for more information", page.body
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"

Expand All @@ -64,19 +66,18 @@ 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"

assert_match "I knew him well", page.body
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"

Expand Down
12 changes: 1 addition & 11 deletions test/integration_test_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ae6f58f

Please sign in to comment.