Just launch HTTP server for testing your Rack application.
require 'rack/test_server' # Configuration with `rackup` compatible options. server = ::.( app: Rails.application, server: :puma, Host: '127.0.0.1', Port: 3000) before(:suite) do # Just launch it on a Thread server.start_async server.wait_for_ready end
Since transactional fixtures are available by sharing a DB connection, we can see any mocked situation (ex. logged in as admin, receiving a lot of notifications, ...) from real browsers, which dramatically improved the testing experiences. Only one limitations for using this feature is that we have to launch the HTTP server within the same process as test runnner's.
If you are working with Rails application, add configuration like below in spec/support/system_testing_helper.rb:
require 'rack/test_server' # Configure Rack server # # options for Rack::Server # @see https://github.com/rack/rack/blob/2.2.3/lib/rack/server.rb#L173 # options for Rack::Handler::Puma # @see https://github.com/puma/puma/blob/v5.4.0/lib/rack/handler/puma.rb#L84 server = ::.( app: Rails.application, server: :puma, Host: '127.0.0.1', Port: 3000) RSpec.configure do # Launch Rails application. config.before(:suite) do server.start_async server.wait_for_ready end end
If you are not Rails user, just replace
Rails.application with your Rack application, and put the configuration file as you prefer. :)
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the Rack::TestServer project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.