aboutsummaryrefslogtreecommitdiffstats
path: root/actionsystemtest/test
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2017-01-22 14:05:51 -0500
committereileencodes <eileencodes@gmail.com>2017-02-20 15:07:34 -0500
commit3dfbe7e4e5057d56c636b8231e8d00a06a15796b (patch)
tree2f410e1d28277cf291d6d46bad4b239ce09204f9 /actionsystemtest/test
parent62c7d983848726bb9a512d687d2765c1dd78fe8d (diff)
downloadrails-3dfbe7e4e5057d56c636b8231e8d00a06a15796b.tar.gz
rails-3dfbe7e4e5057d56c636b8231e8d00a06a15796b.tar.bz2
rails-3dfbe7e4e5057d56c636b8231e8d00a06a15796b.zip
Rewrite API for ActionSystemTest
This is a major rewrite of what existed previously. After discussing this feature with DHH I realized that I was looking at the setup all wrong. I had originally mentally broken it into "what Rails wants" and "what Capybara already has". What happened after looking at it from DHH's angle was that I saw there was no reason to group settings by Driver but instead the following groups: - There will always be a `Driver` - This can selenium, poltergeist, or capybara webkit. Capybara already provides all of these and there's no reason to break them into a category of Rails' usese Selenium like this and Capybara uses it like that. - Only Selenium drivers care about `Browser` - Because of this it was weird to set it only in the Rails end. - Therefore only `Browser`, and not `Driver` cares about `screen_size`. - Puma is the default `Server` in Rails - Therefore there's no reason to explictly support Webkit Once I looked at it from this angle I was able to abstract all the settings away from grouping the drivers with their options. Now all the driver, server, and browser settings are abstracted away and not part of the public facing API. This means there's no requirement to initialize new classes to change the default settings and the public options API is much smaller. All of Rails preferred defaults are still there (selenium with port 21800 using the chrome browser with a screen size of 1400x1400) but changing these no longer requires initializing a new class or understanding which driver you're using underneath (rails defaults or capybaras defaults respectively). Rails opinions are now simple defaults instead of doing a them versus us setup with Drivers and explicit options. Changing the defaults is simple. Call `driven_by` with different settings to change the defaults which will on their own initialize new classes and change the default settings. Use poltergeist with port 3000 for Puma ``` driven_by :poltergeist, on: 3000 ``` Use selenium with the Chrome browser and a screen size of 800x800 ``` driven_by :selenium, using: :firefox, screen_size: [ 800, 800 ] ``` The entire setup of how browser and drivers interact with each other are abstracted away and the only required argument is the driver name.
Diffstat (limited to 'actionsystemtest/test')
-rw-r--r--actionsystemtest/test/abstract_unit.rb69
-rw-r--r--actionsystemtest/test/cases/action_system_test_test.rb34
-rw-r--r--actionsystemtest/test/cases/browser_test.rb10
-rw-r--r--actionsystemtest/test/cases/capybara_driver_test.rb39
-rw-r--r--actionsystemtest/test/cases/driver_adapter_test.rb13
-rw-r--r--actionsystemtest/test/cases/driver_test.rb9
-rw-r--r--actionsystemtest/test/cases/rails_selenium_driver_test.rb11
-rw-r--r--actionsystemtest/test/cases/screenshot_helper_test.rb20
-rw-r--r--actionsystemtest/test/cases/server_test.rb9
9 files changed, 67 insertions, 147 deletions
diff --git a/actionsystemtest/test/abstract_unit.rb b/actionsystemtest/test/abstract_unit.rb
deleted file mode 100644
index 81630ca66d..0000000000
--- a/actionsystemtest/test/abstract_unit.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-require "active_support/testing/autorun"
-require "action_controller"
-require "action_dispatch"
-require "action_system_test"
-
-# Set the Rails tests to use the +:rack_test+ driver because
-# we're not testing Capybara or it's drivers, but rather that
-# the methods accept the proper arguments.
-class RoutedRackApp
- attr_reader :routes
-
- def initialize(routes, &blk)
- @routes = routes
- @stack = ActionDispatch::MiddlewareStack.new(&blk).build(@routes)
- end
-
- def call(env)
- @stack.call(env)
- end
-end
-
-class ActionSystemTestCase < ActionSystemTest::Base
- ActionSystemTest.driver = :rack_test
-
- def self.build_app(routes = nil)
- RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new)
- end
-end
-
-class PostsController < ActionController::Base
- def index
- render inline: <<HTML
-<html>
-<body>
- <h1>This</h1>
- <p title="the title" class="test">Paragraph 1</p>
- <p title="the others" class="test">Paragraph 2</p>
-</body>
-</html>
-HTML
- end
-end
-
-CapybaraRoutes = ActionDispatch::Routing::RouteSet.new
-CapybaraRoutes.draw do
- resources :posts
-end
-
-# Initialize an application
-APP = ActionSystemTestCase.build_app(CapybaraRoutes)
-
-# Initialize an application for Capybara
-RailsApp = ActionSystemTestCase.new(APP)
-
-# Assign Capybara.app to original Rack Application
-Capybara.app = APP
-
-Capybara.add_selector :title_test do
- xpath { |name| XPath.css(".test")[XPath.attr(:title).is(name.to_s)] }
-end
-
-# Skips the current run on Rubinius using Minitest::Assertions#skip
-def rubinius_skip(message = "")
- skip message if RUBY_ENGINE == "rbx"
-end
-# Skips the current run on JRuby using Minitest::Assertions#skip
-def jruby_skip(message = "")
- skip message if defined?(JRUBY_VERSION)
-end
diff --git a/actionsystemtest/test/cases/action_system_test_test.rb b/actionsystemtest/test/cases/action_system_test_test.rb
new file mode 100644
index 0000000000..732c06ba20
--- /dev/null
+++ b/actionsystemtest/test/cases/action_system_test_test.rb
@@ -0,0 +1,34 @@
+require "active_support/testing/autorun"
+require "action_system_test"
+
+class ActionSystemTestTest < ActiveSupport::TestCase
+ test "driven_by sets Capybara's default driver to poltergeist" do
+ ActionSystemTest::Base.driven_by :poltergeist
+
+ assert_equal :poltergeist, Capybara.default_driver
+ end
+
+ test "driven_by defaults to port 21800" do
+ ActionSystemTest::Base.driven_by :poltergeist
+
+ assert_equal 21800, Capybara.server_port
+ end
+
+ test "driven_by can change Capybara's server port" do
+ ActionSystemTest::Base.driven_by :selenium, on: 3000
+
+ assert_equal 3000, Capybara.server_port
+ end
+
+ test "driven_by sets Capybara's drivers respectively" do
+ ActionSystemTest::Base.driven_by :selenium, using: :chrome
+
+ assert_includes Capybara.drivers, :selenium
+ assert_includes Capybara.drivers, :chrome
+ assert_equal :chrome, Capybara.default_driver
+ end
+
+ test "selenium? returns false if driver is poltergeist" do
+ assert_not ActionSystemTest::Base.selenium?(:poltergeist)
+ end
+end
diff --git a/actionsystemtest/test/cases/browser_test.rb b/actionsystemtest/test/cases/browser_test.rb
new file mode 100644
index 0000000000..05e260abfa
--- /dev/null
+++ b/actionsystemtest/test/cases/browser_test.rb
@@ -0,0 +1,10 @@
+require "active_support/testing/autorun"
+require "action_system_test"
+
+class BrowserTest < ActiveSupport::TestCase
+ test "initializing the browser" do
+ browser = ActionSystemTest::Browser.new(:chrome, [ 1400, 1400 ])
+ assert_equal :chrome, browser.instance_variable_get(:@name)
+ assert_equal [ 1400, 1400 ], browser.instance_variable_get(:@screen_size)
+ end
+end
diff --git a/actionsystemtest/test/cases/capybara_driver_test.rb b/actionsystemtest/test/cases/capybara_driver_test.rb
deleted file mode 100644
index 33337ad18b..0000000000
--- a/actionsystemtest/test/cases/capybara_driver_test.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require "abstract_unit"
-
-class CapybaraDriverTest < ActiveSupport::TestCase
- def setup
- ActionSystemTest.driver = :poltergeist
- end
-
- def test_default_driver_adapter
- assert_kind_of ActionSystemTest::DriverAdapters::CapybaraDriver, ActionSystemTest.driver
- end
-
- def test_default_settings
- assert_equal :poltergeist, ActionSystemTest.driver.name
- assert_equal :puma, ActionSystemTest.driver.server
- assert_equal 28100, ActionSystemTest.driver.port
- end
-
- def test_setting_driver
- ActionSystemTest.driver = :webkit
-
- assert_equal :webkit, ActionSystemTest.driver.name
- end
-
- def test_setting_server
- ActionSystemTest.driver = ActionSystemTest::DriverAdapters::CapybaraDriver.new(
- server: :webrick
- )
-
- assert_equal :webrick, ActionSystemTest.driver.server
- end
-
- def test_setting_port
- ActionSystemTest.driver = ActionSystemTest::DriverAdapters::CapybaraDriver.new(
- port: 3000
- )
-
- assert_equal 3000, ActionSystemTest.driver.port
- end
-end
diff --git a/actionsystemtest/test/cases/driver_adapter_test.rb b/actionsystemtest/test/cases/driver_adapter_test.rb
deleted file mode 100644
index cecaa5b958..0000000000
--- a/actionsystemtest/test/cases/driver_adapter_test.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require "abstract_unit"
-
-class DriverAdapterTest < ActiveSupport::TestCase
- test "only registered adapters are accepted" do
- assert_raises(NameError) do
- ActionSystemTest.driver = :whatever
- end
-
- assert_nothing_raised do
- ActionSystemTest.driver = :rack_test
- end
- end
-end
diff --git a/actionsystemtest/test/cases/driver_test.rb b/actionsystemtest/test/cases/driver_test.rb
new file mode 100644
index 0000000000..895aab4e45
--- /dev/null
+++ b/actionsystemtest/test/cases/driver_test.rb
@@ -0,0 +1,9 @@
+require "active_support/testing/autorun"
+require "action_system_test"
+
+class DriverTest < ActiveSupport::TestCase
+ test "initializing the driver" do
+ driver = ActionSystemTest::Driver.new(:selenium)
+ assert_equal :selenium, driver.instance_variable_get(:@name)
+ end
+end
diff --git a/actionsystemtest/test/cases/rails_selenium_driver_test.rb b/actionsystemtest/test/cases/rails_selenium_driver_test.rb
deleted file mode 100644
index 1a8e875f52..0000000000
--- a/actionsystemtest/test/cases/rails_selenium_driver_test.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require "abstract_unit"
-
-class RailsSeleniumDriverTest < ActiveSupport::TestCase
- def setup
- ActionSystemTest.driver = :rails_selenium_driver
- end
-
- def test_default_driver_adapter
- assert_kind_of ActionSystemTest::DriverAdapters::RailsSeleniumDriver, ActionSystemTest.driver
- end
-end
diff --git a/actionsystemtest/test/cases/screenshot_helper_test.rb b/actionsystemtest/test/cases/screenshot_helper_test.rb
index 43b24cba21..d86bc4e62d 100644
--- a/actionsystemtest/test/cases/screenshot_helper_test.rb
+++ b/actionsystemtest/test/cases/screenshot_helper_test.rb
@@ -1,20 +1,10 @@
-require "abstract_unit"
+require "active_support/testing/autorun"
+require "action_system_test"
class ScreenshotHelperTest < ActiveSupport::TestCase
- def test_driver_support_for_screenshots
- ActionSystemTest.driver = :rails_selenium_driver
- assert ActionSystemTest.driver.supports_screenshots?
+ test "image path is saved in tmp directory" do
+ new_test = ActionSystemTest::Base.new("x")
- ActionSystemTest.driver = :rack_test
- assert_not ActionSystemTest.driver.supports_screenshots?
-
- ActionSystemTest.driver = :selenium
- assert ActionSystemTest.driver.supports_screenshots?
-
- ActionSystemTest.driver = :webkit
- assert ActionSystemTest.driver.supports_screenshots?
-
- ActionSystemTest.driver = :poltergeist
- assert ActionSystemTest.driver.supports_screenshots?
+ assert_equal "tmp/screenshots/failures_x.png", new_test.send(:image_path)
end
end
diff --git a/actionsystemtest/test/cases/server_test.rb b/actionsystemtest/test/cases/server_test.rb
new file mode 100644
index 0000000000..39a9be5026
--- /dev/null
+++ b/actionsystemtest/test/cases/server_test.rb
@@ -0,0 +1,9 @@
+require "active_support/testing/autorun"
+require "action_system_test"
+
+class ServerTest < ActiveSupport::TestCase
+ test "initializing the server port" do
+ server = ActionSystemTest::Server.new(21800)
+ assert_equal 21800, server.instance_variable_get(:@port)
+ end
+end