diff --git a/README.md b/README.md index 4278f98..0132620 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,18 @@ This gem makes it possible to use [Thruster][] as a Capybara server. Run your br ## Getting started +### Prerequisites + +Before adding the gem to your project, ensure you have either `thruster` or `anycable-thruster` installed. You can add one of these gems to your `Gemfile`: + +```ruby +# For thruster +gem "thruster" + +# or for anycable-thruster +gem "anycable-thruster" +``` + Adding the gem to your project: ```ruby diff --git a/lib/capybara/dependency_checker.rb b/lib/capybara/dependency_checker.rb new file mode 100644 index 0000000..35d3996 --- /dev/null +++ b/lib/capybara/dependency_checker.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Capybara + module Thruster + class DependencyChecker + def self.call + new.call + end + + def call + unless thruster_installed? + warn "*********************************************************" + warn "Warning: capybara-thruster requires either 'thruster' or 'anycable-thruster' gem." + warn "Please install one of them to ensure proper functionality." + warn "*********************************************************" + end + end + + private + + def thruster_installed? + gem_installed?("thruster") || gem_installed?("anycable-thruster") + end + + def gem_installed?(name) + Gem::Specification.find_all_by_name(name).any? + end + end + end +end diff --git a/lib/capybara/thruster.rb b/lib/capybara/thruster.rb index c9da625..f96e192 100644 --- a/lib/capybara/thruster.rb +++ b/lib/capybara/thruster.rb @@ -2,6 +2,10 @@ require "childprocess" require "capybara" +require "capybara/dependency_checker" +require "rack/handler" + +Capybara::Thruster::DependencyChecker.call # Replaces the default Puma server on CAPYBARA_SERVER_PORT port with Thruster server. # Requests are proxied to the Puma server running on the internal port (CAPYBARA_SERVER_PORT + 1).