Class: Bidi2pdfRails::TestHelpers::Server
- Inherits:
-
Object
- Object
- Bidi2pdfRails::TestHelpers::Server
- Defined in:
- lib/bidi2pdf_rails/test_helpers/server.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#server_boot_timeout ⇒ Object
readonly
Returns the value of attribute server_boot_timeout.
Instance Method Summary collapse
- #boot ⇒ Object
-
#initialize(app: Rails.application, port: TestHelpers.configuration.server_port, host: TestHelpers.configuration.server_host, server_boot_timeout: TestHelpers.configuration.server_boot_timeout) ⇒ Server
constructor
A new instance of Server.
- #port ⇒ Object
- #running? ⇒ Boolean
- #shutdown ⇒ Object
Constructor Details
#initialize(app: Rails.application, port: TestHelpers.configuration.server_port, host: TestHelpers.configuration.server_host, server_boot_timeout: TestHelpers.configuration.server_boot_timeout) ⇒ Server
Returns a new instance of Server.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bidi2pdf_rails/test_helpers/server.rb', line 12 def initialize( app: Rails.application, port: TestHelpers.configuration.server_port, host: TestHelpers.configuration.server_host, server_boot_timeout: TestHelpers.configuration.server_boot_timeout ) @app = app @port = port @host = host @server_boot_timeout = server_boot_timeout end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
10 11 12 |
# File 'lib/bidi2pdf_rails/test_helpers/server.rb', line 10 def app @app end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
10 11 12 |
# File 'lib/bidi2pdf_rails/test_helpers/server.rb', line 10 def host @host end |
#server_boot_timeout ⇒ Object (readonly)
Returns the value of attribute server_boot_timeout.
10 11 12 |
# File 'lib/bidi2pdf_rails/test_helpers/server.rb', line 10 def server_boot_timeout @server_boot_timeout end |
Instance Method Details
#boot ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bidi2pdf_rails/test_helpers/server.rb', line 32 def boot return if @booted @booted = true that = self @server_thread = Thread.new do Rack::Handler::Puma.run that.app, Port: that.port, Silent: false rescue Errno::EADDRINUSE => e puts "Port #{that.port} is already/still in use." raise e end wait_until_server_is_ready end |
#port ⇒ Object
24 25 26 |
# File 'lib/bidi2pdf_rails/test_helpers/server.rb', line 24 def port @port ||= find_available_port end |
#running? ⇒ Boolean
28 29 30 |
# File 'lib/bidi2pdf_rails/test_helpers/server.rb', line 28 def running? @booted && @server_thread&.alive? end |
#shutdown ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/bidi2pdf_rails/test_helpers/server.rb', line 50 def shutdown return unless @booted @booted = false if @server_thread&.alive? @server_thread.exit @server_thread.join end end |