aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2016-08-27 16:48:24 -0400
committereileencodes <eileencodes@gmail.com>2017-02-20 15:07:32 -0500
commit9730b1dba6d1bb9684a54915ac3735d9c0eade26 (patch)
treec2e74e65c3b333254a512338b04d8ef5fdcfe6bc
parent4533bb7dcbdd6e0451395bc869d6c3603c6ff1df (diff)
downloadrails-9730b1dba6d1bb9684a54915ac3735d9c0eade26.tar.gz
rails-9730b1dba6d1bb9684a54915ac3735d9c0eade26.tar.bz2
rails-9730b1dba6d1bb9684a54915ac3735d9c0eade26.zip
Add tests for system testing
* Adds test case test * Adds driver adapter test * Adds tests for capybara seleium driver (testing the settings not actually opening the browser to test capybara w/ selenium because that would so so so slow) * Adds tests for rack test driver * Adds tests for generators
-rw-r--r--Gemfile.lock10
-rw-r--r--actionpack/actionpack.gemspec1
-rw-r--r--actionpack/test/abstract_unit.rb1
-rw-r--r--actionpack/test/system_testing/capybara_rack_test_driver_test.rb26
-rw-r--r--actionpack/test/system_testing/capybara_selenium_driver_test.rb58
-rw-r--r--actionpack/test/system_testing/driver_adapter_test.rb19
-rw-r--r--railties/test/generators/app_generator_test.rb21
-rw-r--r--railties/test/generators/scaffold_generator_test.rb5
-rw-r--r--railties/test/generators/system_test_generator_test.rb12
9 files changed, 152 insertions, 1 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index c40730a33d..c3db5c67f8 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -45,6 +45,7 @@ PATH
actionpack (5.1.0.alpha)
actionview (= 5.1.0.alpha)
activesupport (= 5.1.0.alpha)
+ capybara (~> 2.7.0)
rack (~> 2.0)
rack-test (~> 0.6.3)
rails-dom-testing (~> 2.0)
@@ -125,6 +126,13 @@ GEM
bunny (2.6.2)
amq-protocol (>= 2.0.1)
byebug (9.0.6)
+ capybara (2.7.0)
+ addressable
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ xpath (~> 2.0)
childprocess (0.5.9)
ffi (~> 1.0, >= 1.0.11)
coffee-rails (4.2.1)
@@ -356,6 +364,8 @@ GEM
websocket-driver (0.6.4)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
+ xpath (2.0.0)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
diff --git a/actionpack/actionpack.gemspec b/actionpack/actionpack.gemspec
index 2c24a54305..bb9079dc1c 100644
--- a/actionpack/actionpack.gemspec
+++ b/actionpack/actionpack.gemspec
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
s.add_dependency "rails-html-sanitizer", "~> 1.0", ">= 1.0.2"
s.add_dependency "rails-dom-testing", "~> 2.0"
s.add_dependency "actionview", version
+ s.add_dependency "capybara", "~> 2.7.0"
s.add_development_dependency "activemodel", version
end
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 459b0d6c54..3b35af6d3a 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -33,6 +33,7 @@ require "action_view/testing/resolvers"
require "action_dispatch"
require "active_support/dependencies"
require "active_model"
+require "system_test_case"
require "pp" # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
diff --git a/actionpack/test/system_testing/capybara_rack_test_driver_test.rb b/actionpack/test/system_testing/capybara_rack_test_driver_test.rb
new file mode 100644
index 0000000000..0f037760d3
--- /dev/null
+++ b/actionpack/test/system_testing/capybara_rack_test_driver_test.rb
@@ -0,0 +1,26 @@
+require 'abstract_unit'
+
+class CapybaraRackTestDriverTest < ActiveSupport::TestCase
+ def test_default_driver_adapter
+ assert_kind_of SystemTesting::DriverAdapters::CapybaraRackTestDriver, Rails::SystemTestCase.driver
+ end
+
+ def test_default_settings
+ assert_equal 'Capybara', Rails::SystemTestCase.driver.useragent
+ end
+
+ def test_setting_useragent
+ Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraRackTestDriver.new(
+ useragent: 'x'
+ )
+ assert_equal 'x', Rails::SystemTestCase.driver.useragent
+ end
+
+ def test_does_not_accept_nonsense_kwargs
+ assert_raises ArgumentError do
+ Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraRackTestDriver.new(
+ made_up_arg: 'x'
+ )
+ end
+ end
+end
diff --git a/actionpack/test/system_testing/capybara_selenium_driver_test.rb b/actionpack/test/system_testing/capybara_selenium_driver_test.rb
new file mode 100644
index 0000000000..6357b35aa6
--- /dev/null
+++ b/actionpack/test/system_testing/capybara_selenium_driver_test.rb
@@ -0,0 +1,58 @@
+require 'abstract_unit'
+
+class CapybaraSeleniumDriverTest < ActiveSupport::TestCase
+ def setup
+ Rails::SystemTestCase.driver = :capybara_selenium_driver
+ end
+
+ def test_setting_driver_adapter_to_selenium
+ assert_kind_of SystemTesting::DriverAdapters::CapybaraSeleniumDriver, Rails::SystemTestCase.driver
+ end
+
+ def test_default_settings
+ assert_equal :chrome, Rails::SystemTestCase.driver.browser
+ assert_equal :puma, Rails::SystemTestCase.driver.server
+ assert_equal 28100, Rails::SystemTestCase.driver.port
+ assert_equal [1400,1400], Rails::SystemTestCase.driver.screen_size
+ end
+
+ def test_setting_browser
+ Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new(
+ browser: :firefox
+ )
+
+ assert_equal :firefox, Rails::SystemTestCase.driver.browser
+ end
+
+ def test_setting_server
+ Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new(
+ server: :webrick
+ )
+
+ assert_equal :webrick, Rails::SystemTestCase.driver.server
+ end
+
+ def test_setting_port
+ Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new(
+ port: 3000
+ )
+
+ assert_equal 3000, Rails::SystemTestCase.driver.port
+ end
+
+ def test_setting_screen_size
+ Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new(
+ screen_size: [ 800, 800 ]
+ )
+
+ assert_equal [ 800, 800 ], Rails::SystemTestCase.driver.screen_size
+ end
+
+ def test_does_not_accept_nonsense_kwargs
+ assert_raises ArgumentError do
+ Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraSeleniumDriver.new(
+ made_up_arg: 'x'
+ )
+ end
+ end
+end
diff --git a/actionpack/test/system_testing/driver_adapter_test.rb b/actionpack/test/system_testing/driver_adapter_test.rb
new file mode 100644
index 0000000000..bfbeaa63a2
--- /dev/null
+++ b/actionpack/test/system_testing/driver_adapter_test.rb
@@ -0,0 +1,19 @@
+require 'abstract_unit'
+
+class DriverAdapterTest < ActiveSupport::TestCase
+ test 'only registered adapters are accepted' do
+ assert_raises(NameError) do
+ Rails::SystemTestCase.driver = :whatever
+ end
+
+ assert_nothing_raised do
+ Rails::SystemTestCase.driver = :capybara_selenium_driver
+ end
+ end
+
+ test 'settings can only be used for the appropriate adapter' do
+ assert_raises(ArgumentError) do
+ Rails::SystemTestCase.driver = SystemTesting::DriverAdapters::CapybaraRackTestDriver.new(something: 'test')
+ end
+ end
+end
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index ce29d93d6e..687aed2c47 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -42,6 +42,7 @@ DEFAULT_APP_FILES = %w(
test/helpers
test/mailers
test/integration
+ test/system
vendor
tmp
tmp/cache
@@ -805,8 +806,26 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_equal 4, @sequence_step
end
- private
+ def test_system_tests_directory_generated
+ run_generator
+
+ assert_file("test/system/.keep")
+ assert_directory("test/system")
+ end
+
+ def test_system_tests_are_not_generated_on_system_test_skip
+ run_generator [destination_root, "--skip-system-test"]
+
+ assert_no_directory("test/system")
+ end
+
+ def test_system_tests_are_not_generated_on_test_skip
+ run_generator [destination_root, "--skip-test"]
+ assert_no_directory("test/system")
+ end
+
+ private
def stub_rails_application(root)
Rails.application.config.root = root
Rails.application.class.stub(:name, "Myapp") do
diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb
index e2b2acab0f..d523b93ac1 100644
--- a/railties/test/generators/scaffold_generator_test.rb
+++ b/railties/test/generators/scaffold_generator_test.rb
@@ -62,6 +62,11 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
assert_match(/patch product_line_url\(@product_line\), params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/, test)
end
+ # System tests
+ assert_file "test/system/product_lines_test.rb" do |test|
+ assert_match(/class ProductLinesTest < Rails::SystemTestCase/, test)
+ end
+
# Views
assert_no_file "app/views/layouts/product_lines.html.erb"
diff --git a/railties/test/generators/system_test_generator_test.rb b/railties/test/generators/system_test_generator_test.rb
new file mode 100644
index 0000000000..3a9733556e
--- /dev/null
+++ b/railties/test/generators/system_test_generator_test.rb
@@ -0,0 +1,12 @@
+require "generators/generators_test_helper"
+require "rails/generators/rails/system_test/system_test_generator"
+
+class SystemTestGeneratorTest < Rails::Generators::TestCase
+ include GeneratorsTestHelper
+ arguments %w(user)
+
+ def test_system_test_skeleton_is_created
+ run_generator
+ assert_file "test/system/users_test.rb", /class UsersTest < Rails::SystemTestCase/
+ end
+end