<commit_before>require 'kookaburra/exceptions'
require 'kookaburra/dependency_accessor'

class Kookaburra
  class UIDriver
    class UIComponent
      extend DependencyAccessor

      dependency_accessor :browser

      def initialize(options = {})
        @browser = options[:browser]
        @server_error_detection = options[:server_error_detection]
      end

      def method_missing(name, *args, &block)
        if element.respond_to?(name)
          element.send(name, *args, &block)
        else
          super
        end
      end

      def respond_to?(name)
        super || element.respond_to?(name)
      end

      def show(*args)
        return if visible?
        browser.visit component_path(*args)
        assert_visible
      end

      def visible?
        element.visible?
      rescue ComponentNotFound
        false
      end

      private

      def assert(test, message = "You might want to provide a better message, eh?")
        test or raise AssertionFailed, message
      end

      def assert_visible
        assert visible?, "The #{self.class.name} component is not visible!"
      end

      def component_path
        raise ConfigurationError, "You must define #{self.class.name}#component_path."
      end

      def component_locator
        raise ConfigurationError, "You must define #{self.class.name}#component_locator."
      end

      def detect_server_error!
        if @server_error_detection.try(:call, browser)
          raise UnexpectedResponse, "Your server error detection function detected a server error. Looks like your applications is busted. :-("
        end
      end

      def element
        detect_server_error!
        begin
          browser.find(component_locator)
        rescue StandardError => e
          raise ComponentNotFound, e.message
        end
      end
    end
  end
end
<commit_msg>whitespace<commit_after>require 'kookaburra/exceptions'
require 'kookaburra/dependency_accessor'

class Kookaburra
  class UIDriver
    class UIComponent
      def initialize(options = {})
        @browser = options[:browser]
        @server_error_detection = options[:server_error_detection]
      end

      def method_missing(name, *args, &block)
        if element.respond_to?(name)
          element.send(name, *args, &block)
        else
          super
        end
      end

      def respond_to?(name)
        super || element.respond_to?(name)
      end

      def show(*args)
        return if visible?
        browser.visit component_path(*args)
        assert_visible
      end

      def visible?
        element.visible?
      rescue ComponentNotFound
        false
      end

      private

      extend DependencyAccessor
      dependency_accessor :browser

      def assert(test, message = "You might want to provide a better message, eh?")
        test or raise AssertionFailed, message
      end

      def assert_visible
        assert visible?, "The #{self.class.name} component is not visible!"
      end

      def component_path
        raise ConfigurationError, "You must define #{self.class.name}#component_path."
      end

      def component_locator
        raise ConfigurationError, "You must define #{self.class.name}#component_locator."
      end

      def detect_server_error!
        if @server_error_detection.try(:call, browser)
          raise UnexpectedResponse, "Your server error detection function detected a server error. Looks like your applications is busted. :-("
        end
      end

      def element
        detect_server_error!
        begin
          browser.find(component_locator)
        rescue StandardError => e
          raise ComponentNotFound, e.message
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.06673842841765339, 'fraction_numerical': 0.0, 'mean_word_length': 2.249125874125874, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1070217', 'n_tokens_mistral': 1000, 'n_tokens_neox': 976, 'n_words': 286}