<commit_before>module Gamera
  module Visitable
    # Methods to include on pages that are visitable, i.e. have a URL to visit and are then displayed.

    include Capybara::DSL

    # Open the page url in the browser specified in your Capybara configuration
    #
    # @param fail_on_redirect [Boolean] Whether to fail if the site redirects to a page that does not match the url_matcher regex
    # @raise [WrongPageVisited] if the site redirects to URL that doesn't match the url_matcher regex and fail_on_redirect is true
    def visit(fail_on_redirect = true)
      super(url)
      if fail_on_redirect
        fail Gamera::WrongPageVisited, "Expected URL '#{url}', got '#{page.current_url}'" unless displayed?
      end
    end

    # Check to see if we eventually land on the right page
    #
    # @param wait_time_seconds [Integer] How long to wait for the correct page to load
    # @return [Boolean] true if the url loaded in the browser matches the url_matcher pattern
    # @raise [NoUrlMatcherForPage] if there's no url_matcher for this page
    def displayed?(wait_time_seconds = Capybara.default_wait_time)
      fail Gamera::NoUrlMatcherForPage if url_matcher.nil?
      start_time = Time.now
      loop do
        return true if page.current_url.chomp('/') =~ url_matcher
        break unless Time.now - start_time <= wait_time_seconds
        sleep(0.05)
      end
      false
    end

    # A method to wait for slow loading data on a page. Useful, for example,<commit_msg>Use Capybara.default_max_wait_time instead of Capybara.default_wait_time per deprecation warning on Capybara 2.5<commit_after>module Gamera
  module Visitable
    # Methods to include on pages that are visitable, i.e. have a URL to visit and are then displayed.

    include Capybara::DSL

    # Open the page url in the browser specified in your Capybara configuration
    #
    # @param fail_on_redirect [Boolean] Whether to fail if the site redirects to a page that does not match the url_matcher regex
    # @raise [WrongPageVisited] if the site redirects to URL that doesn't match the url_matcher regex and fail_on_redirect is true
    def visit(fail_on_redirect = true)
      super(url)
      if fail_on_redirect
        fail Gamera::WrongPageVisited, "Expected URL '#{url}', got '#{page.current_url}'" unless displayed?
      end
    end

    # Check to see if we eventually land on the right page
    #
    # @param wait_time_seconds [Integer] How long to wait for the correct page to load
    # @return [Boolean] true if the url loaded in the browser matches the url_matcher pattern
    # @raise [NoUrlMatcherForPage] if there's no url_matcher for this page
    def displayed?(wait_time_seconds = Capybara.default_max_wait_time)
      fail Gamera::NoUrlMatcherForPage if url_matcher.nil?
      start_time = Time.now
      loop do
        return true if page.current_url.chomp('/') =~ url_matcher
        break unless Time.now - start_time <= wait_time_seconds
        sleep(0.05)
      end
      false
    end

    # A method to wait for slow loading data on a page. Useful, for example,
{'fraction_non_alphanumeric': 0.05924247329232762, 'fraction_numerical': 0.002589834898025251, 'mean_word_length': 3.2445054945054945, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4902017', 'n_tokens_mistral': 900, 'n_tokens_neox': 885, 'n_words': 363}