Permalink
Browse files

Rename server and remove optional port setting

I've renamed the server to `rails_puma` so that it doesn't override
Capybara's default puma server. I've also removed the hard port setting.
Users can simply use `Capybara.server_port` writer to set the port if
they require that.
  • Loading branch information...
eileencodes committed Feb 18, 2017
1 parent 893c3b6 commit 0a683085b1db435b7371350b2799a0f248cd717a
View
@@ -57,7 +57,7 @@ The <tt>system_test_helper.rb</tt> file provides a home for all of your Capybara
and Action System Test configuration.
The default configuration uses the Selenium driver, with the Chrome browser,
served by Puma on port 21800 with a screen size of 1400x1400.
and a screen size of 1400x1400.
Changing the configuration is as simple as changing the driver in your
<tt>system_test_helper.rb</tt>
@@ -67,17 +67,17 @@ you can change `driven_by` in the helper file.
The driver name is a required argument for `driven_by`. The optional arguments
that can be passed to `driven_by` are `:using` for the browser (this will only
be used for non-headless drivers like Selenium), `:on` for the port Puma should
use, and `:screen_size` to change the size of the screen for screenshots.
be used for non-headless drivers like Selenium), and `:screen_size` to change
the size of the screen for screenshots.
Below are some examples for changing the default configuration settings for
system tests:
Changing the browser, port for Puma, and screen size:
Changing the browser and screen size:
```ruby
class ActionSystemTestCase < ActionSystemTest::Base
driven_by :selenium, using: :firefox, on: 3000, screen_size: [ 800, 800 ]
driven_by :selenium, using: :firefox, screen_size: [ 800, 800 ]
end
```
@@ -86,7 +86,7 @@ using a headless driver simply leave out the `:using` argument.
```ruby
class ActionSystemTestCase < ActionSystemTest::Base
driven_by :poltergeist, on: 3000
driven_by :poltergeist
end
```
@@ -71,16 +71,16 @@ module ActionSystemTest # :nodoc:
# end
#
# By default, <tt>ActionSystemTest</tt> is driven by the Selenium driver, with
# the Chrome browser, on port 21800, and a browser size of 1400x1400.
# the Chrome browser, and a browser size of 1400x1400.
#
# Changing the driver configuration options are easy. Let's say you want to use
# port 3000, and the Firefox browser instead. In your +system_test_helper.rb+
# and the Firefox browser instead. In your +system_test_helper.rb+
# file add the following:
#
# require "test_helper"
#
# class ActionSystemTestCase < ActionSystemTest::Base
# driven_by :selenium, using: :firefox, on: 3000
# driven_by :selenium, using: :firefox
#
# teardown do
# take_failed_screenshot
@@ -90,8 +90,7 @@ module ActionSystemTest # :nodoc:
#
# +driven_by+ has a required argument for the driver name. The keyword
# arguments are +:using+ for the browser (not applicable for headless drivers),
# +:on+ for port (the server is always Puma), and +:screen_size+ to change
# the size of the screen when taking screenshots.
# and +:screen_size+ to change the size of the screen taking screenshots.
#
# To use a headless driver, like Poltergeist, update your Gemfile to use
# Poltergeist instead of Selenium and then declare the driver name in the
@@ -129,17 +128,19 @@ def self.start_application # :nodoc:
# Action System Test configuration options
#
# The defaults settings are Selenium, using Chrome, on port 21800, with a
# screen size of 1400x1400.
# The defaults settings are Selenium, using Chrome, with a screen size
# of 1400x1400.
#
# Examples:
#
# driven_by :poltergeist
#
# driven_by :selenium, using: :firefox, on: 3000
def self.driven_by(driver, using: :chrome, on: 21800, screen_size: [1400, 1400])
# driven_by :selenium, using: :firefox
#
# driven_by :selenium, screen_size: [800, 800]
def self.driven_by(driver, using: :chrome, screen_size: [1400, 1400])
Driver.new(driver).run
Server.new(on).run
Server.new.run
Browser.new(using, screen_size).run if selenium?(driver)
end
@@ -2,33 +2,20 @@
module ActionSystemTest
class Server # :nodoc:
def initialize(port)
@port = port
end
def run
register
setup
end
private
def register
Capybara.register_server :puma do |app, host|
Rack::Handler::Puma.run(app, Port: @port, Threads: "0:1")
Capybara.register_server :rails_puma do |app, port, host|
Rack::Handler::Puma.run(app, Port: port, Threads: "0:1")
end
end
def setup
set_server
set_port
end
def set_server
Capybara.server = :puma
end
def set_port
Capybara.server_port = @port
Capybara.server = :rails_puma
end
end
end
@@ -8,18 +8,6 @@ class ActionSystemTestTest < ActiveSupport::TestCase
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
@@ -3,7 +3,7 @@
class ServerTest < ActiveSupport::TestCase
test "initializing the server port" do
server = ActionSystemTest::Server.new(21800)
assert_equal 21800, server.instance_variable_get(:@port)
server = ActionSystemTest::Server
assert_includes Capybara.servers, :rails_puma
end
end

0 comments on commit 0a68308

Please sign in to comment.