diff --git a/lib/capybara/wsl.rb b/lib/capybara/wsl.rb index 17b061e..a27b8e5 100644 --- a/lib/capybara/wsl.rb +++ b/lib/capybara/wsl.rb @@ -10,44 +10,46 @@ module WSL class CapybaraWSLError < StandardError; end class CannotDetectWSLPath < CapybaraWSLError; end - def self.save_and_open_page(path = nil) - Capybara.current_session.save_page(path).tap do |s_path| - open_file(s_path) + class << self + def save_and_open_page(path = nil) + Capybara.current_session.save_page(path).tap do |s_path| + open_file(s_path) + end end - end - def self.save_and_open_screenshot(path = nil, **options) - Capybara.current_session.save_screenshot(path, options).tap do |s_path| - open_file(s_path) + def save_and_open_screenshot(path = nil, **options) + Capybara.current_session.save_screenshot(path, **options).tap do |s_path| + open_file(s_path) + end end - end - private + private - def self.open_file(path) - Dotenv.overload!(File.expand_path("#{__FILE__}/../.env")) - wsl_path = modify_path(path) - Launchy.open(wsl_path) - rescue LoadError - warn "File saved to #{wsl_path}.\nPlease install the launchy gem to open the file automatically." - end + def open_file(path) + Dotenv.overload!(File.expand_path("#{__FILE__}/../.env")) + wsl_path = modify_path(path) + Launchy.open(wsl_path) + rescue LoadError + warn "File saved to #{wsl_path}.\nPlease install the launchy gem to open the file automatically." + end - def self.modify_path(path) - path[1..-1].prepend(detect_path).gsub("/", "\\") - end + def self.modify_path(path) + path[1..-1].prepend(detect_path).gsub("/", "\\") + end - def self.detect_path - path = `wslpath -m "/"`&.strip + def self.detect_path + path = `wslpath -m "/"`&.strip - if path.empty? - raise(Capybara::WSL::CannotDetectWSLPath, - "Cannot detect WSL path. Are you sure you're running WSL?") - end + if path.empty? + raise(Capybara::WSL::CannotDetectWSLPath, + "Cannot detect WSL path. Are you sure you're running WSL?") + end - "file:#{path}" + "file:#{path}" + end end end end # Add WSL-related methods to Capybara's DSL -Capybara::DSL.include Capybara::WSL::DSL +Capybara::DSL.include(Capybara::WSL::DSL) diff --git a/lib/capybara/wsl/dsl.rb b/lib/capybara/wsl/dsl.rb index 443452a..7825fc8 100644 --- a/lib/capybara/wsl/dsl.rb +++ b/lib/capybara/wsl/dsl.rb @@ -8,7 +8,7 @@ def save_and_open_page_wsl(path = nil) end def save_and_open_screenshot_wsl(path = nil, **options) - Capybara::WSL.save_and_open_screenshot(path, options) + Capybara::WSL.save_and_open_screenshot(path, **options) end end end