aboutsummaryrefslogtreecommitdiffstats
path: root/actionsystemtest/test/cases/action_system_test_test.rb
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/cases/action_system_test_test.rb
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/cases/action_system_test_test.rb')
-rw-r--r--actionsystemtest/test/cases/action_system_test_test.rb34
1 files changed, 34 insertions, 0 deletions
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