From 9e929de53091ab5db24be602546e525a72548dbd Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 29 Oct 2017 20:58:23 +0000 Subject: [PATCH] Add framework for system tests --- .travis.yml | 1 + Gemfile | 3 ++- Gemfile.lock | 3 +++ lib/tasks/testing.rake | 2 +- test/application_system_test_case.rb | 14 ++++++++++++++ test/system/site_test.rb | 9 +++++++++ 6 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/application_system_test_case.rb create mode 100644 test/system/site_test.rb diff --git a/.travis.yml b/.travis.yml index 48ddb4a1d..8c09cc439 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,3 +28,4 @@ script: - bundle exec rubocop -f fuubar - bundle exec rake jshint - bundle exec rake test:db + - bundle exec rake test:system diff --git a/Gemfile b/Gemfile index fee5fa4d1..79d95f9d5 100644 --- a/Gemfile +++ b/Gemfile @@ -119,9 +119,10 @@ end # Needed in development as well so rake can see konacha tasks group :development, :test do + gem "capybara", "~> 2.13" gem "coveralls", :require => false gem "factory_bot_rails" gem "jshint" - # gem "konacha" gem "poltergeist" + gem "puma", "~> 3.7" end diff --git a/Gemfile.lock b/Gemfile.lock index 08e6c60b4..b65ec4ed9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -229,6 +229,7 @@ GEM progress (3.4.0) psych (2.2.4) public_suffix (3.0.0) + puma (3.10.0) r2 (0.2.7) rack (2.0.3) rack-cors (1.0.2) @@ -359,6 +360,7 @@ DEPENDENCIES autoprefixer-rails bigdecimal (~> 1.1.0) canonical-rails + capybara (~> 2.13) coffee-rails (~> 4.2) composite_primary_keys (~> 10.0.0) coveralls @@ -393,6 +395,7 @@ DEPENDENCIES pg poltergeist psych + puma (~> 3.7) r2 (~> 0.2.7) rack-cors rack-uri_sanitizer diff --git a/lib/tasks/testing.rake b/lib/tasks/testing.rake index 3d933a3aa..6335adf87 100644 --- a/lib/tasks/testing.rake +++ b/lib/tasks/testing.rake @@ -1,6 +1,6 @@ namespace :test do task "lib" => "test:prepare" do $LOAD_PATH << "test" - Minitest.rake_run(["test/lib"]) + Rails::TestUnit::Runner.rake_run(["test/lib"]) end end diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 000000000..18d5ec2f7 --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,14 @@ +require "test_helper" +require "capybara/poltergeist" + +WebMock.disable_net_connect!(:allow_localhost => true) + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :poltergeist, :screen_size => [1400, 1400] + + def initialize(*args) + stub_request(:get, "http://api.hostip.info/country.php?ip=127.0.0.1") + .to_return(:status => 404) + super(*args) + end +end diff --git a/test/system/site_test.rb b/test/system/site_test.rb new file mode 100644 index 000000000..2ecc7f5a9 --- /dev/null +++ b/test/system/site_test.rb @@ -0,0 +1,9 @@ +require "application_system_test_case" + +class SiteTest < ApplicationSystemTestCase + test "visiting the index" do + visit "/" + + assert_selector "h1", :text => "OpenStreetMap" + end +end -- 2.39.5